A spatial relation extraction algorithm based on dependency relation

Source: Internet
Author: User
Tags ming
0. Introduction

Spatial relationship refers to the relationship of spatial characteristics between entities, such as azimuth relation, distance relation, topological relation, hierarchical relation, etc. Spatial relationships generally have three or two levels in natural language descriptions. The three parts are divided into projectiles, landmarks and nouns from the perspective of Cognition, wherein: the projectile is the main component of the spatial relationship. Nouns of locality are used to describe the spatial direction and positional relationship between entities, usually with their preceding nouns constituting the quarters in the sentence. The landmark provides reference for the orientation of the projectile.

For example S1: The cup is on the table. The S1 contains a spatial expression (in, on, table).
Then the cup is the shot body, the table is the landmark, and the locality.

To get a spatial relationship, you need to find the spatial expression in the sentence. First, we need to preprocess the original corpus. The spatial relationship is then extracted. 1. Corpus preprocessing 1.1. Get the dependency after sentence participle

Based on the natural language processing technology of hit, it uses its API to participle sentences and get its dependencies.
The user obtains the corresponding result by specifying the API parameters, and the API parameter set of the language cloud service is linked as follows:
http://www.ltp-cloud.com/document/
In the language cloud, all API access is done through HTTP requests. and needs to be accessed from the api.ltp-cloud.com domain. The language cloud only supports get and post HTTP requests. The user obtains the corresponding result by specifying parameters in the HTTP request.
For example, the phrase "a bird on the roof" is a dependent syntactic analysis.
The sentence view of the dependency of this sentence is as follows:

Figure 1-1 Dependency of example sentences

Returns the result in XML format. Example of GET request and return result:
GET http://api.ltp-cloud.com/analysis/?api_key=u1h0s1z1ckcutrloujvyhvnsowky9ycmavahcduw&text= A bird on the roof & Pattern=all&format=xml

Figure 1-2 XML standard results for example sentences

The XML standard results for this sentence are as follows: The node labels are XML4NLP, note, DOC, para, sent, word,arg a total of seven kinds of node tags:
1, XML4NLP is the root node, without any attribute value;
2, note for the tag node, with the attributes are: Sent, Word, POS, NE, parser, SRL, respectively, representing the clauses, participle, part-of-speech tagging, named entity recognition, dependency syntax analysis, Word sense disambiguation, semantic role labeling; the value is "n", which indicates that the value is "Y" means complete, such as pos= "Y", indicating that the part of speech has been marked;
3. doc is a textual node, which contains the text content in a paragraph, without any attribute value;
4, para is a paragraph node, need to include the id attribute, whose value starts from 0;
5, sent is the sentence node, the attribute should be id,cont;id as the sentence sequence number in the paragraph, its value starts from 0; Cont is the sentence content;
6, Word is a word segmentation node, need to contain the attribute as the ID, Cont;id is the sentence ordinal number of the word, its value starts from 0, Cont is the word segmentation content; optional attribute is POS, NE, parent, relate, semparent,semrelate;pos content is the part of speech label The content of the name is NE; the parent and relate appear in pairs, and the parent is the Father Node ID number of the dependent parsing, and relate is the corresponding relationship; Semparent and semrelate appear in pairs, semparent for semantic dependency analysis Affinity Node ID number, semrelate for the corresponding relationship;
7, ARG is a semantic role information node, any predicate will have a number of the node, its property is ID, type, Beg,end;id is ordinal, starting from 0, type is the name of the role, beg is the starting word ordinal, end is the ending ordinal;
The logical relationships of the nodes and attributes are described below:
1, each node hierarchy relationship can be clearly obtained from the diagram, where the node with the id attribute can contain multiple;
2, if sent= "n" that is incomplete clause, then should not contain sent and its lower node;
3, if sent= "y" word= "n" is complete clause, not complete participle, it should not include word and its next node;
4, other circumstances are in the case of sent= "y" word= "y":
(1) If pos= "Y" then the word node must include the POS attribute;
(2) If ne= "Y" then the word node must contain the NE attribute;
(3) If parser= "Y", the word node must contain the parent and relate attributes;
(4) If semparser= "Y" then the word node must contain the semparent and semrelate attributes;
(5) If srl= "Y" then the participle of the general predicate (predicate) will contain several ARG nodes;
In XML format analysis, the user can specify the parameters Pattern=ws | POS | NER | DP | SDP | Srl | All to nominate the analysis task and get the corresponding XML result.

1.2. Save the dependency as an XML file

Saves the dependency to an XML file as a string in XML format.
Example "A bird on the roof" The XML format of the dependency of the phrase is as shown in the figure:

Figure 1-3 Example of XML for a dependency

1.3 Parsing an XML file to get the properties of each word

Parse the XML file using DOM4J to get the values of each attribute under the node (as shown in the red box above). Create an entity class word, which corresponds to the attributes of the nodes in the XML file. Save the parsed attribute value of each word as a word instance into a list.

Figure 1-4 Node Properties

2. Spatial relations Ternary group extraction

According to the information of speech, dependence and syntactic structure of all the words in a short sentence obtained by Corpus preprocessing, we can identify the three groups of spatial relation based on the knowledge of cognition.
First, according to the number of nouns in a short sentence to determine at least how many triples, then for each locality of words, to determine its landmarks and projectiles, if there are multiple projectiles, then copy the locality and landmarks, add the number of ternary group.
"Xiaoming and Barack Obama are fishing on the bridge behind the house," he said. ”

Figure 2-1 Syntax analysis and part-of-speech tagging for example sentences

Figure 2-2 Syntax Analysis tree for example sentences

As shown above, the words identified in the example are "back" and "Shang", and the number of nouns of locality is 2, then it can be determined that there are at least two triples, according to the sub-nodes of the nouns of locality of the ATT (fixed-medium relationship), the landmarks are "room" and "bridge" respectively. Then based on the locality to find the three groups of projectiles (the specific method below), because there is a three-group of the shoot for "Xiao Ming" and "Obama", so to "Xiao Ming" The landmark and the locality to copy to "Obama", and then add the new ternary group to the results of the ternary list. 2.1 Identification of the locality of nouns

By traversing through all the words in a short sentence, the word "nd" (direction noun) is found to be used as the locality of speech.
Hit's language technology platform's word-breaker system has more than 100 kinds of fixed nouns of locality, such as "Northeast Face", "front and back", etc.

Figure 2-3 Locality recognition

2.2 Identification of landmarks

Add the identified locality of 2.1 to the corresponding ternary group, for each of the current ternary group, according to the locality to identify the landmark, after a large number of examples, in the syntactic analysis tree, the landmark is the node of the locality, the dependency of the landmark is the ATT (fixed-sino relationship), according to such rules, Identify the landmarks in the corresponding ternary group.
Example "A bird on the roof" the dependency of this sentence is shown in Figure 3-2:

Figure 2-4 Dependencies and part-of-speech tagging

"He stands in front of the house," the dependency of this sentence is shown in Figure 3-3:

Figure 2-5 Dependencies and part-of-speech tagging

When the direct dependency of a locality in a dependency att is not a landmark, such as "an ant on the back of an elephant"

Figure 2-6 Dependencies and part-of-speech tagging

In the figure above you can see the dependency att (up-and-down), (back-to-the-elephant), at this time the locality "on" the direct dependency of the object is not a landmark, but the "back" of the direct dependency is a landmark. , from its sememes learned that the "back" is a component, so it cannot be used as a landmark, to determine the elephant is a landmark.
The landmark recognition algorithm is as follows:
① determines the dependency of the locality child node ATT.
② the direct dependent object X1 of the locality of nouns in the locality dependency ATT.
③ find if X1 is part, if not turn (4), otherwise turn (5)
④ identified X1 as a landmark. End.
⑤ gets the X1 dependency att, from the dependency att to the X1 direct dependent object X2, the value of the update X1 is X2. Turn ③.

2.3 Body Recognition
2.3.1 Simple shot recognition

According to the importance of locality in the short sentence, the locality of locality can be classified as the main place of locality, which is directly related to the root node of the parsing tree.
As shown in the following illustration, "Xiaoming and Barack Obama are fishing on the bridge behind the house." "In, three triples for (Xiaoming, Bridge, Upper), (Obama, Bridge, ON), (Bridge, House, back), where" Shang "is the main locality," back "is the secondary locality. According to the classification of the locality, the corresponding projectiles are identified.

(1) Nouns of locality are the main nouns of locality.
When the locality is the primary locality, the parent node's dependency is hed (the core relationship) or the parent node (or more) is hed, as the example in Figure 3-9, the parent node of the parent node of "up" is hed.
Starting from the word locality, the node is fetched up one layer at a time until it obtains a node with a dependency of hed, and then iterates through the nodes of the node node that have the noun "n" (or "n") and the pronoun "r". In the example above can be found on the shot "Xiaoming".

Figure 2-8 Syntax Analysis tree

"There is a water cup on the table in front of the house." The main locality of the "on" of the shot is "water cup." The dependency and parsing tree of this sentence is shown in Figures 2-8 and 2-9:

2-9 dependencies

Figure 2-10 Syntax Analysis tree

(2) Nouns of locality are secondary nouns of locality.
When the locality is the second word, the dependency of the locality is the ATT (fixed-in relationship), and the object of direct dependence is the noun "n" (or the part of speech containing "n", such as "Xiao Ming" "NH") or the pronoun "r", which can be judged as the emitter of the secondary locality.
Example: Xiao Ming and Barack Obama are fishing on the bridge behind the house. "In the secondary locality" after "the dependence of the ATT, directly dependent on the object is" bridge "part of the word" n ", in line with the above requirements, so" bridge "is the" back "of the projectile.

The simple shot recognition algorithm is as follows:
① judge whether the locality is the secondary locality (whether the dependency is att), if it is, turn ②, otherwise turn ③.
② verifies that the parent node is a noun or pronoun, and if so, determines the shot, otherwise returns a null value.
③ the locality as the current word, judging whether the parent node of the current word is dependent on hed, if not, the parent node of the current word is overwritten with the current word, and then judged, until the parent node of the current word is satisfied that the dependency relationship is hed.
④ iterates through the syntax tree, extracts the same word as the parent node of the current word, verifies that its part is a noun or pronoun, and, if so, determines the shot, otherwise, returns a null value.


2.3.2 Complex shot recognition

When there are multiple parallel projectiles in a short sentence, as in the example "xiaoming and Obama are fishing on the bridge behind the house." "Through the method of 2.3.1 we can only identify two triples (Xiao Ming, Bridge, Upper), (Bridge, House, back), and" Xiao Ming "side of the shot" Obama "did not recognize it, so the simple shot recognition after the juxtaposition of the shot to do processing, copy the corresponding landmarks and locality, Add to the list of results triples.

In the above image, we can iterate through the syntax tree to extract the parent node as the identified projectile, the dependency is the COO of the node as a new ternary group of projectiles, in the copy of the parent node of the three-dimensional group of the marker and the locality, add to the results of the ternary list.
The complex shot recognition algorithm is as follows:
① Simple shot recognition.
② iterates through the syntax tree, extracting the parent node is the node that currently handles the projectiles in the ternary group, verifying that its dependencies are "COO".
③ Copy the current processing of the three-tuple of the landmark and the location of the new ternary group, the node as a new ternary group of the shot, and the new ternary group added to the results of the ternary list.
④ return result ternary group

Note:
1. The Corpus preprocessing section uses the language cloud API, which is linked to: http://www.ltp-cloud.com/document/
2. Source code Download Address: Https://github.com/CODERXIAOYE/Spatial-relation-extraction-based-on-the-dependency.git

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.