A method and device for expanding regular expressions based on knowledge graph
The automatic generation of regular expressions through the knowledge graph solves the time-consuming and incomplete problems of regular expression library expansion in the existing technology, achieves more efficient semantic analysis, and improves the user experience of intelligent learning products.
Patent Information
- Application Number
- CN201910365367.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-30
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2039-04-30
AI Technical Summary
In the existing technology, relying on the expansion of regular expression libraries requires manual intervention, is time-consuming, laborious, and incomplete, resulting in insufficient semantic parsing capabilities and affecting user experience.
Build a domain knowledge graph based on the knowledge graph, automatically generate regular expressions, generate sentence patterns and semantic slots through nodes and relationships, update the regular expression library, and achieve automatic expansion.
It eliminates the need for manual analysis of sentence structures, improves the completeness of the regular expression library and the success rate of semantic parsing, and improves the user experience of intelligent learning products.
Smart Images

Figure CN111859976B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of semantic parsing, and in particular to a method and device for expanding regular expressions based on knowledge graphs. Background Art
[0002] With the continuous development of society, more and more smart learning devices, such as tutoring machines and student tablets, are widely used in families. People use such devices to assist children in learning. For example, when they encounter exercises that they cannot solve or knowledge points that they do not understand during the learning process, they can input relevant questions or knowledge points through voice or text, and search for corresponding answers and knowledge explanations in smart learning devices.
[0003] At present, in human-computer interaction scenarios, accurately understanding the semantics of input information is the basis for making correct responses. Relying on regular expressions to parse semantics is a classic method in semantic parsing. This method improves semantic parsing capabilities by expanding the regular expression library. Generally, it is necessary to manually expand the user corpus and expand the regular expression library based on the expanded corpus, which is time-consuming, labor-intensive and inefficient; in addition, there may be some sentence corpora that have not been collected, making the constructed regular expression library incomplete, resulting in some corpora that cannot be parsed normally when used by users, which in turn causes the machine to be unable to accurately understand the user's intentions, reducing the user's experience. Summary of the invention
[0004] The purpose of the present invention is to provide a method and device for expanding regular expressions based on knowledge graphs. The method generates new regular expressions based on knowledge graphs, expands the existing regular expression library, and makes the constructed regular expression library more perfect, so as to accurately understand the user's intentions and improve the success rate of semantic parsing.
[0005] The technical solution provided by the present invention is as follows:
[0006] A method for expanding regular expressions based on a knowledge graph, comprising: constructing a domain knowledge graph; obtaining at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship between them; obtaining a semantic slot corresponding to the node; generating a regular expression based on the sentence pattern, the semantic slot, and a non-node part in the sentence pattern, and updating a regular expression library.
[0007] Further preferably, the obtaining of at least one sentence pattern according to two adjacent nodes in the domain knowledge graph and the relationship therebetween includes: when a bidirectional relationship exists between two adjacent nodes in the domain knowledge graph, different sentence patterns are obtained respectively according to the bidirectional relationship.
[0008] Further preferably, the step of obtaining at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship therebetween also includes: when the relationship between two adjacent nodes in the domain knowledge graph is a noun, obtaining a first sentence pattern based on the two nodes and the relationship, the predicate of the first sentence pattern being a judgment verb.
[0009] Further preferably, the obtaining of at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship therebetween also includes: when the relationship between two adjacent nodes in the domain knowledge graph is a noun, expressing the relationship with a verb with similar semantics to obtain a different sentence pattern with the same semantics as the first sentence pattern.
[0010] Further preferably, the step of obtaining at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship therebetween also includes: when the relationship between two adjacent nodes in the domain knowledge graph is a verb, obtaining a second sentence pattern based on the two nodes and the relationship, the predicate of the second sentence pattern being the relationship.
[0011] Further preferably, the step of obtaining at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship therebetween also includes: when the relationship between two adjacent nodes in the domain knowledge graph is a verb, expressing the relationship with nouns with similar semantics to obtain a different sentence pattern with the same semantics as the second sentence pattern.
[0012] The present invention also provides a device for expanding regular expressions based on a knowledge graph, comprising: a knowledge graph construction module, used to construct a domain knowledge graph; a sentence generation module, used to obtain at least one sentence pattern based on two adjacent nodes in the domain knowledge graph and the relationship between them; a semantic slot acquisition module, used to obtain the semantic slot corresponding to the node; a regular generation module, used to generate a regular expression based on the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and update the regular expression library.
[0013] Further preferably, the sentence generation module is further used to obtain a first sentence pattern according to the two nodes and the relationship when the relationship between two adjacent nodes in the domain knowledge graph is a noun, and the predicate of the first sentence pattern is a judgment verb.
[0014] Further preferably, the sentence generation module is further used to express the relationship with a verb with similar semantics when the relationship between two adjacent nodes in the domain knowledge graph is a noun, so as to obtain a different sentence with the same semantics as the first sentence.
[0015] Further preferably, the sentence generation module is further used to obtain a second sentence pattern according to the two nodes and the relationship when the relationship between two adjacent nodes in the domain knowledge graph is a verb, and the predicate of the second sentence pattern is the relationship.
[0016] The method and device for expanding regular expressions based on knowledge graph provided by the present invention can bring the following beneficial effects:
[0017] 1. The present invention automatically generates a regular expression based on each triple in the domain knowledge graph, without the need to manually analyze sentence structure and write regular expressions, which saves time and effort and is more efficient.
[0018] 2. The present invention automatically generates regular expressions based on the domain knowledge graph, expands the existing regular expression library, makes the constructed regular expression library more perfect, improves the success rate of semantic parsing, and thus improves the user experience of intelligent learning products. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The following will explain the preferred implementation mode in a clear and understandable manner with reference to the accompanying drawings, and further explain the above-mentioned characteristics, technical features, advantages and implementation methods of a method and device for expanding regular expressions based on a knowledge graph.
[0020] Figure 1 It is a flowchart of an embodiment of a method for expanding regular expressions based on a knowledge graph of the present invention;
[0021] Figure 2 is a flow chart of another embodiment of a method for expanding regular expressions based on a knowledge graph of the present invention;
[0022] Figure 3 is a flow chart of another embodiment of a method for expanding regular expressions based on a knowledge graph of the present invention;
[0023] Figure 4 is a flow chart of another embodiment of a method for expanding regular expressions based on a knowledge graph of the present invention;
[0024] Figure 5 It is a structural diagram of an embodiment of a device for expanding regular expressions based on a knowledge graph of the present invention.
[0025] Description of Figure Numbers:
[0026] 110. Knowledge graph construction module, 120. Sentence generation module, 130. Semantic slot acquisition module, 140. Regular generation module. DETAILED DESCRIPTION
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.
[0028] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".
[0029] The present invention improves the success rate of semantic parsing by expanding regular expressions; the regular expression expansion method provided by the present invention can be applied to intelligent learning devices (for example: tutoring machines), but technicians in this field should understand that the regular expression expansion method can also be applied to other intelligent learning devices as long as the corresponding functions can be achieved.
[0030] In one embodiment of the present invention, Figure 1 As shown, a method for expanding regular expressions based on knowledge graphs includes:
[0031] Step S100 constructs a domain knowledge graph.
[0032] Specifically, the knowledge graph describes the complex relationships between concepts and entities in the objective world in a structured form. The knowledge graph is a network composed of nodes and node relationships. Concepts and entities in the objective world can be used as nodes in the knowledge graph. For example, people, height, weight, geographical location, literary works, film works, etc. can all be used as nodes. The knowledge graph contains nodes, relationships, and triples composed of nodes and relationships. Each triple represents a piece of knowledge, that is, there is a certain relationship or attribute between two nodes, which is represented by (head node, relationship or attribute, tail node) (this article will unify triples in this way in the future). For example, (Hangzhou, located in, China) represents the knowledge that "Hangzhou is located in China", and (apple, color, red) represents "the color of apple is red".
[0033] Domain knowledge graphs include general domain knowledge graphs, professional domain knowledge graphs, and segmented domain knowledge graphs. Professional domain or segmented domain knowledge graphs are more targeted and professional, so regular expressions generated from professional domain knowledge graphs are more suitable for semantic analysis of professional domain texts, especially for the recognition and analysis of some professional terms, and the success rate of semantic analysis will be higher. For example, smart learning products for primary school students require semantic recognition of primary school students' voices. If regular expressions generated from primary school education knowledge graphs are used for semantic recognition and analysis, they will be more targeted.
[0034] To construct a domain knowledge graph, you need to first collect a large amount of knowledge in the domain, which can be obtained from existing knowledge bases or network data; then extract concepts or entities from the acquired knowledge, and organize the relationships between concepts or entities; take each concept or entity as a node, and the relationship between concepts or entities as the relationship between nodes. All nodes and node relationships constitute the knowledge graph of the domain.
[0035] Step S200 obtains at least one sentence pattern according to two adjacent nodes in the domain knowledge graph and the relationship between them.
[0036] Specifically, every two adjacent nodes and their relationship form at least one triple, and each triple corresponds to at least one sentence pattern. For example, the node "Hangzhou", the node "China" and the relationship "located in" form a triple (Hangzhou, located in, China), which means "Hangzhou is located in China", and based on this meaning, a sentence pattern "Hangzhou is located in China" can be obtained.
[0037] For example, the triplet (Wang Xiaoming, father, Wang Dawei) indicates "Wang Xiaoming's father is Wang Dawei", and based on this triplet we get the corresponding sentence "Wang Xiaoming's father is Wang Dawei"; the relationship between these two nodes is inverse, so it is easy to get another triplet (Wang Dawei, son, Wang Xiaoming), that is, "Wang Dawei's son is Wang Xiaoming", and based on this triplet we get another sentence "Wang Dawei's son is Wang Xiaoming".
[0038] Step S300 obtains the semantic slot corresponding to the node;
[0039] Step S400 generates a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and updates a regular expression library.
[0040] Specifically, a semantic slot reflects a certain specific concept and can be a certain type of word. According to the semantics of the node, words with similar semantics or words belonging to the category of this semantics are selected as the corresponding semantic slots. For example, for the node "Wang Xiaoming", which is a personal name and belongs to the category of personal names, so words representing personal names are selected as the corresponding semantic slots; for the node "Hangzhou", which is a city, so words representing cities can be selected as the corresponding semantic slots. "Hangzhou" can also be considered a geographical name, so words representing geographical names can also be selected as the corresponding semantic slots.
[0041] A regular expression refers to a string used to describe or match a series of strings that conform to a certain syntactic rule. By using semantic slots to replace the nodes in the sentence pattern, and then according to the original sentence pattern structure and the non-node parts in the sentence pattern, the corresponding regular expression of the sentence pattern can be generated, where the non-node parts in the sentence pattern reflect the relationships between the nodes.
[0042] For example, for the sentence pattern "Hangzhou is located in China", where the node "Hangzhou" is replaced with a geographical name slot (words representing geographical names) and the node "China" is replaced with a country name slot (words representing countries), the corresponding regular expression obtained is: ##Geographical name slot## [is located in] ##Country name slot##.
[0043] Another example is the sentence pattern "The son of Wang Dawei is Wang Xiaoming". The semantic slots corresponding to the nodes "Wang Dawei" and "Wang Xiaoming" are words representing personal names, simply referred to as personal name slots. When the nodes "Wang Dawei" and "Wang Xiaoming" are replaced with semantic slots, the regular expression 1 obtained is: ##Personal name slot## [of] [son] [is] ##Personal name slot##. According to the sentence pattern "The father of Wang Xiaoming is Wang Dawei", the following is obtained: The regular expression 2 is: ##Personal name slot## [of] [father] [is] ##Personal name slot##.
[0044] Using semantic slots to replace nodes is equivalent to replacing specific entities with a certain concept, which can improve the semantic parsing ability of regular expressions and also improve the generalization ability of regular expressions.
[0045] After obtaining the regular expression according to the sentence pattern, the existing regular expression library is updated according to this regular expression to make the regular expression library more perfect.
[0046] In this embodiment, regular expressions are automatically generated based on each triple in the domain knowledge graph without the need for manual analysis of the sentence structure and writing of regular expressions, which saves time and effort. Moreover, the nodes in the knowledge graph are clearly hierarchical and closely related, and standard and classic regular expressions can be obtained according to the knowledge graph. In addition, this method expands the existing regular expression library, makes the constructed regular expression library more perfect, improves the success rate of semantic parsing, and further improves the user experience of intelligent learning products.
[0047] In another embodiment of the present invention, as Figure 2As shown, a method for expanding regular expressions based on knowledge graphs includes:
[0048] Step S100 constructs a domain knowledge graph.
[0049] In step S210, when a bidirectional relationship exists between two adjacent nodes in the domain knowledge graph, different sentence patterns are obtained according to the bidirectional relationship.
[0050] Specifically, the relationship between two adjacent nodes is usually a unidirectional relationship, and a triple is obtained according to the unidirectional relationship, and a sentence pattern is obtained according to the triple. For example, the node "Hangzhou", the node "China" and the relationship "located in" constitute a triple (Hangzhou, located in, China), which means "Hangzhou is located in China", and a sentence pattern "Hangzhou is located in China" can be obtained according to this meaning.
[0051] Some nodes have bidirectional relationships, and two types of triples are obtained from the bidirectional relationship, and at least one sentence pattern is obtained from each triple. For example, there are two relationships ("author", "work") between the node "Quiet Night Thoughts" and the node "Li Bai", and the triples (Quiet Night Thoughts, author, Li Bai) and (Li Bai, work, Quiet Night Thoughts) are obtained from these two relationships, and the sentence patterns "The author of Quiet Night Thoughts is Li Bai" and "Li Bai's work is Quiet Night Thoughts" are obtained.
[0052] Step S300 obtains the semantic slot corresponding to the node;
[0053] Step S400 generates a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and updates a regular expression library.
[0054] Specifically, continuing with the above example, the sentence pattern "The author of Quiet Night Thoughts is Li Bai" is obtained from the triple (Quiet Night Thoughts, author, Li Bai), the node "Quiet Night Thoughts" is replaced by the poem name slot (a word indicating the name of the poem), and the node "Li Bai" is replaced by the person name slot (a word indicating the person's name), and the corresponding regular expression is obtained: ##poem name slot##[of][author][is]##person name slot##.
[0055] From (Li Bai, works, Quiet Night Thoughts), we get the sentence pattern "Li Bai's work is Quiet Night Thoughts", the node "Quiet Night Thoughts" is replaced by the poem name slot, and the node "Li Bai" is replaced by the person name slot, and we get the corresponding regular expression: ##person name slot##[of][works][is]##poem name slot##.
[0056] This embodiment provides a method for generating a regular expression when the relationship between adjacent nodes is a bidirectional relationship.
[0057] In another embodiment of the present invention, Figure 3As shown in the figure, a method for expanding regular expressions based on a knowledge graph includes:
[0058] Step S100 constructs a domain knowledge graph.
[0059] In step S220, when the relationship between two adjacent nodes in the domain knowledge graph is a noun, a first sentence pattern is obtained according to the two nodes and the relationship, and the predicate of the first sentence pattern is a judgment verb.
[0060] Specifically, when the relationship between two adjacent nodes is a noun, a first sentence pattern can be generated according to these two nodes and their relationship, and the predicate of this first sentence pattern is a judgment verb such as "is" or "is called".
[0061] For example, the nodes "Li Bai", "Thoughts in the Silent Night", and the relationship "work" form a triple (Li Bai, work, Thoughts in the Silent Night), where the part of speech of "work" is a noun. By adding the auxiliary word "of" before "work" and adding the judgment verb "is" or "is called" after "work", the first sentence pattern is obtained: The work of Li Bai is Thoughts in the Silent Night, and the semantics of this sentence pattern is "The work of Li Bai is Thoughts in the Silent Night".
[0062] In step S230, when the relationship between two adjacent nodes in the domain knowledge graph is a noun, the relationship is expressed by a verb with similar semantics to obtain a different sentence pattern with the same semantics as the first sentence pattern.
[0063] Specifically, when the relationship between two adjacent nodes is a noun, the relationship is expressed by a verb with similar semantics to obtain a different sentence pattern with the same or similar semantics as the first sentence pattern.
[0064] Continuing with the above example, for instance, the relationship "work" is a noun, and it is expressed by the verb with similar semantics "create", and a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: Li Bai created Thoughts in the Silent Night.
[0065] Another example, according to the triple (Xiaomei, hobby, dance), the first sentence pattern "Xiaomei's hobby is dance" can be obtained. Expressing the node relationship "hobby" with a verb with similar meaning, such as "like" or "love", a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: Xiaomei likes dance.
[0066] Another example, according to the triple (Wang Dawei, occupation, doctor), the first sentence pattern "Wang Dawei's occupation is doctor" can be obtained. Expressing "occupation" with a verb with similar meaning, such as "engage in... work", a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: Wang Dawei engages in doctor work.
[0067] Step S300 obtains the semantic slots corresponding to the nodes;
[0068] Step S400 generates a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and updates a regular expression library.
[0069] Specifically, the semantic slot corresponding to the node is obtained, and the semantic slot is used to replace the node in the sentence to generate a regular expression.
[0070] Continuing with the above example, for example, in the first sentence "Li Bai's work is Quiet Night Thoughts", the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poetry slot", thus generating the regular expression "##name slot##[of][work][is]##poetry slot##". A different sentence with the same or similar semantics as the first sentence "Li Bai created Quiet Night Thoughts" replaces the nodes with semantic slots to obtain a new regular expression "##name slot##[creates]##poetry slot##", which is different in form from "##name slot##[of][work][is]##poetry slot##", but has the same or similar semantics.
[0071] For another example, in the first sentence "Wang Dawei's occupation is a doctor", the node "Wang Dawei" is replaced by "name slot", and the node "doctor" is replaced by "occupation slot", thus generating the regular expression "##name slot##['s occupation is]##occupation slot##". A different sentence with the same or similar semantics as the first sentence "Wang Dawei works as a doctor" replaces the nodes with semantic slots to obtain a new regular expression "##name slot##[works]##occupation slot##[works]", which is different in form from "##name slot##['s occupation is]##occupation slot##", but has the same or similar semantics.
[0072] In this embodiment, when the relationship between nodes is a noun, a new regular expression is generated by using a verb with similar semantics to express the relationship, thereby expanding the existing regular expression library, making the constructed regular expression library more complete, and improving the semantic parsing ability of the regular expression library.
[0073] In another embodiment of the present invention, Figure 4 As shown, a method for expanding regular expressions based on knowledge graphs includes:
[0074] Step S100 constructs a domain knowledge graph.
[0075] Step S220: When the relationship between two adjacent nodes in the domain knowledge graph is a noun, a first sentence pattern is obtained according to the two nodes and the relationship, and the predicate of the first sentence pattern is a judgment verb.
[0076] Step S230: When the relationship between two adjacent nodes in the domain knowledge graph is a noun, the relationship is expressed by a verb with similar semantics to obtain a different sentence pattern with the same semantics as the first sentence pattern.
[0077] Step S240: When the relationship between two adjacent nodes in the domain knowledge graph is a verb, a second sentence pattern is obtained according to the two nodes and the relationship, and the predicate of the second sentence pattern is the relationship.
[0078] Step S250: When the relationship between two adjacent nodes in the domain knowledge graph is a verb, the relationship is expressed by nouns with similar semantics to obtain a different sentence pattern with the same semantics as the second sentence pattern.
[0079] Specifically, when the relationship between two adjacent nodes is a verb, a second sentence pattern can be generated according to the two nodes and their relationship, and the second sentence pattern uses the relationship as a predicate.
[0080] For example, the node "Li Bai", the node "Quiet Night Thoughts", and the relationship "Creation" form a triple (Li Bai, Creation, Quiet Night Thoughts), where the part of speech of "Creation" is a verb and can be directly used as the predicate of the sentence to obtain the second sentence: Li Bai created Quiet Night Thoughts, and the semantics of this sentence is "Li Bai created Quiet Night Thoughts".
[0081] When the relationship between two adjacent nodes is a verb, the relationship is expressed by nouns with similar semantics, thereby obtaining a different sentence pattern with the same or similar semantics as the second sentence pattern.
[0082] Continuing with the above example, for example, if the relation "create" is a verb and is expressed using the noun "works" which has similar semantics, we can get a different sentence pattern with the same or similar semantics as the second sentence pattern: "Li Bai's work is Quiet Night Thoughts."
[0083] Step S300 obtains the semantic slot corresponding to the node.
[0084] Step S400 generates a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and updates a regular expression library.
[0085] Specifically, the semantic slot corresponding to the node is obtained, and the semantic slot is used to replace the node in the sentence to generate a regular expression.
[0086] Continuing with the above example, for example, in the second sentence "Li Bai created Quiet Night Thoughts", the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poem name slot", thus generating the regular expression "##name slot##[creation]##poem name slot##".
[0087] A different sentence pattern with the same or similar semantics to the second sentence pattern is "Li Bai's work is Quiet Night Thoughts", in which the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poem name slot", thereby generating a new regular expression "##name slot##['s][work][is]##poem name slot##", which is different in form from "##name slot##[creation]##poem name slot##", but has the same or similar semantics.
[0088] In this embodiment, when the relationship between nodes is a verb, a new regular expression is generated by using nouns with similar semantics to express the relationship, thereby expanding the existing regular expression library, making the constructed regular expression library more complete, and improving the semantic parsing ability of the regular expression library.
[0089] In one embodiment of the present invention, Figure 5 As shown, a device for expanding regular expressions based on a knowledge graph includes:
[0090] The knowledge graph construction module 110 is used to construct a domain knowledge graph.
[0091] Specifically, the knowledge graph describes the complex relationships between concepts and entities in the objective world in a structured form. The knowledge graph is a network composed of nodes and node relationships. Concepts and entities in the objective world can be used as nodes in the knowledge graph. For example, people, height, weight, geographical location, literary works, film works, etc. can all be used as nodes. The knowledge graph contains nodes, relationships, and triples composed of nodes and relationships. Each triple represents a piece of knowledge, that is, there is a certain relationship or attribute between two nodes, which is represented by (head node, relationship or attribute, tail node) (this article will unify triples in this way in the future). For example, (Hangzhou, located in, China) represents the knowledge that "Hangzhou is located in China", and (apple, color, red) represents "the color of apple is red".
[0092] Domain knowledge graphs include general domain knowledge graphs, professional domain knowledge graphs, and segmented domain knowledge graphs. Professional domain or segmented domain knowledge graphs are more targeted and professional, so regular expressions generated from professional domain knowledge graphs are more suitable for semantic analysis of professional domain texts, especially for the recognition and analysis of some professional terms, and the success rate of semantic analysis will be higher. For example, smart learning products for primary school students require semantic recognition of primary school students' voices. If regular expressions generated from primary school education knowledge graphs are used for semantic recognition and analysis, they will be more targeted.
[0093] To construct a domain knowledge graph, a large amount of domain knowledge needs to be collected first, which can be obtained from existing knowledge bases or network data, etc. Then, concepts or entities are extracted from the acquired knowledge, and the relationships between each concept or entity are sorted out. Each concept or entity is used as a node, and the relationships between concepts or entities are used as the relationships between nodes. All the nodes and their relationships constitute the domain knowledge graph.
[0094] The sentence pattern generation module 120 is used to obtain at least one sentence pattern according to two adjacent nodes and the relationship between them in the domain knowledge graph.
[0095] Specifically, every two adjacent nodes and their relationship constitute at least one triple, and each triple corresponds to at least one sentence pattern. For example, the node "Hangzhou", the node "China", and the relationship "is located in" constitute the triple (Hangzhou, is located in, China), whose meaning is "Hangzhou is located in China". According to this meaning, a sentence pattern "Hangzhou is located in China" can be obtained.
[0096] Another example is that the triple (Wang Xiaoming, father, Wang Dawei) indicates that "Wang Xiaoming's father is Wang Dawei". According to this triple, the corresponding sentence pattern "Wang Xiaoming's father is Wang Dawei" is obtained. Since the relationship between these two nodes is reversible, it is easy to obtain another triple (Wang Dawei, son, Wang Xiaoming), that is, "Wang Dawei's son is Wang Xiaoming", and according to this triple, another sentence pattern "Wang Dawei's son is Wang Xiaoming" is obtained.
[0097] The semantic slot acquisition module 130 is used to acquire the semantic slot corresponding to the node;
[0098] The regular expression generation module 140 is used to generate a regular expression according to the sentence pattern, the semantic slot, and the non-node part in the sentence pattern, and update the regular expression library.
[0099] Specifically, the semantic slot reflects a certain specific concept and can be a certain type of word. According to the semantics of the node, words with similar semantics or words belonging to the semantic category are selected as the corresponding semantic slot. For example, for the node "Wang Xiaoming", it is a personal name and belongs to the category of personal names, so words representing personal names are selected as the corresponding semantic slot; for the node "Hangzhou", it is a city, so words representing cities can be selected as the corresponding semantic slot. "Hangzhou" can also be considered a place name, so words representing place names can also be selected as the corresponding semantic slot.
[0100] A regular expression refers to a string used to describe or match a series of strings that conform to a certain syntactic rule. By using the semantic slot to replace the node in the sentence pattern, and then according to the original sentence pattern structure and the non-node part in the sentence pattern, the regular expression corresponding to this sentence pattern can be generated, where the non-node part in the sentence pattern reflects the relationship between nodes.
[0101] For example, for the sentence pattern "Hangzhou is located in China", the node "Hangzhou" is replaced with a place name slot (a word representing a place name), and the node "China" is replaced with a country name slot (a word representing a country), resulting in the corresponding regular expression: ##Place name slot##[is located in]##Country name slot##.
[0102] Another example is the sentence pattern "Wang Dawei's son is Wang Xiaoming". The semantic slots corresponding to the nodes "Wang Dawei" and "Wang Xiaoming" are words representing personal names, abbreviated as personal name slots. Replacing the nodes "Wang Dawei" and "Wang Xiaoming" with semantic slots, the resulting regular expression 1 is: ##Personal name slot##[of][son][is]##Personal name slot##. According to the sentence pattern "Wang Xiaoming's father is Wang Dawei", the resulting regular expression 2 is: ##Personal name slot##[of][father][is]##Personal name slot##.
[0103] Replacing nodes with semantic slots is equivalent to replacing specific entities with a concept, which can improve the semantic parsing ability of regular expressions and also enhance the generalization ability of regular expressions.
[0104] In this embodiment, regular expressions are automatically generated based on each triple in the domain knowledge graph, eliminating the need for manual analysis of sentence structures and writing of regular expressions, saving time and effort. Moreover, the nodes in the knowledge graph are hierarchical and closely related, and standard and classic regular expressions can be obtained according to the knowledge graph. Additionally, this method expands the existing regular expression library, making the constructed regular expression library more complete, improving the success rate of semantic parsing, and thus enhancing the user experience of intelligent learning products.
[0105] In another embodiment of the present invention, as Figure 5 shown, a device for expanding regular expressions based on a knowledge graph includes:
[0106] A knowledge graph construction module 110 for constructing a domain knowledge graph.
[0107] A sentence pattern generation module 120 for obtaining different sentence patterns respectively according to the bidirectional relationship when there is a bidirectional relationship between two adjacent nodes in the domain knowledge graph.
[0108] Specifically, usually the relationship between two adjacent nodes is a unidirectional relationship. According to the unidirectional relationship, a triple is obtained, and a sentence pattern is obtained based on this triple. For example, the nodes "Hangzhou", "China" and the relationship "is located in" form a triple (Hangzhou, is located in, China), whose meaning is "Hangzhou is located in China", and based on this meaning, a sentence pattern "Hangzhou is located in China" can be obtained.
[0109] Some nodes have bidirectional relationships, and two types of triples are obtained from the bidirectional relationship, and at least one sentence pattern is obtained from each triple. For example, there are two relationships ("author", "work") between the node "Quiet Night Thoughts" and the node "Li Bai", and the triples (Quiet Night Thoughts, author, Li Bai) and (Li Bai, work, Quiet Night Thoughts) are obtained from these two relationships, and the sentence patterns "The author of Quiet Night Thoughts is Li Bai" and "Li Bai's work is Quiet Night Thoughts" are obtained.
[0110] The semantic slot acquisition module 130 is used to acquire the semantic slot corresponding to the node.
[0111] The regular expression generation module 140 is used to generate a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and update the regular expression library.
[0112] Specifically, continuing with the above example, the sentence pattern "The author of Quiet Night Thoughts is Li Bai" is obtained from the triple (Quiet Night Thoughts, author, Li Bai), the node "Quiet Night Thoughts" is replaced by the poem name slot (a word indicating the name of the poem), and the node "Li Bai" is replaced by the person name slot (a word indicating the person's name), and the corresponding regular expression is obtained: ##poem name slot##[of][author][is]##person name slot##.
[0113] From (Li Bai, works, Quiet Night Thoughts), we get the sentence pattern "Li Bai's work is Quiet Night Thoughts", the node "Quiet Night Thoughts" is replaced by the poem name slot, and the node "Li Bai" is replaced by the person name slot, and we get the corresponding regular expression: ##person name slot##[of][works][is]##poem name slot##.
[0114] This embodiment provides a method for generating a regular expression when the relationship between adjacent nodes is a bidirectional relationship.
[0115] In another embodiment of the present invention, Figure 5 As shown, a device for expanding regular expressions based on a knowledge graph includes:
[0116] The knowledge graph construction module 110 is used to construct a domain knowledge graph.
[0117] The sentence generation module 120 is used to obtain a first sentence pattern based on the two nodes and the relationship when the relationship between two adjacent nodes in the domain knowledge graph is a noun, and the predicate of the first sentence pattern is a judgment verb; and when the relationship between two adjacent nodes in the domain knowledge graph is a noun, the relationship is expressed by a verb with similar semantics to obtain a different sentence pattern with the same semantics as the first sentence pattern.
[0118] Specifically, when the relationship between two adjacent nodes is a noun, a first sentence pattern can be generated according to the two nodes and their relationship, and the predicate of the first sentence pattern is a judgment verb such as "is" or "for".
[0119] For example, the node "Li Bai", the node "Thoughts on a Quiet Night", and the relationship "work" form a triple (Li Bai, work, Thoughts on a Quiet Night), where the part of speech of "work" is a noun. By adding the auxiliary word "de" before "work" and the copular verb "is" or "wei" after "work", the first sentence pattern is obtained: The work of Li Bai is Thoughts on a Quiet Night, and the semantics of this sentence pattern is "The work of Li Bai is Thoughts on a Quiet Night".
[0120] When the relationship between two adjacent nodes is a noun, express this relationship with a verb with similar semantics to obtain a different sentence pattern with the same or similar semantics as the first sentence pattern.
[0121] Continuing with the above example, for instance, the relationship "work" is a noun, and it is expressed with the verb with similar semantics "create", and a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: "Li Bai created Thoughts on a Quiet Night".
[0122] Another example, according to the triple (Xiaomei, hobby, dance), the first sentence pattern "Xiaomei's hobby is dance" can be obtained. Express the node relationship "hobby" with a verb with similar meaning, such as "like" or "love", and a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: "Xiaomei likes dance".
[0123] Another example, according to the triple (Wang Dawei, occupation, doctor), the first sentence pattern "Wang Dawei's occupation is doctor" can be obtained. Express "occupation" with a verb with similar meaning, such as "be engaged in... work", and a different sentence pattern with the same or similar semantics as the first sentence pattern can be obtained: "Wang Dawei is engaged in doctor work".
[0124] The semantic slot acquisition module 130 is used to acquire the semantic slot corresponding to the node.
[0125] The regular expression generation module 140 is used to generate a regular expression according to the sentence pattern, the semantic slot, and the non-node part in the sentence pattern, and update the regular expression library.
[0126] Specifically, acquire the semantic slot corresponding to the node, and use the semantic slot to replace the node in the sentence pattern to generate a regular expression.
[0127] Continuing with the above example, for example, in the first sentence "Li Bai's work is Quiet Night Thoughts", the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poetry slot", thus generating the regular expression "##name slot##[of][work][is]##poetry slot##". A different sentence with the same or similar semantics as the first sentence "Li Bai created Quiet Night Thoughts" replaces the nodes with semantic slots to obtain a new regular expression "##name slot##[creates]##poetry slot##", which is different in form from "##name slot##[of][work][is]##poetry slot##", but has the same or similar semantics.
[0128] For another example, in the first sentence "Wang Dawei's occupation is a doctor", the node "Wang Dawei" is replaced by "name slot", and the node "doctor" is replaced by "occupation slot", thus generating the regular expression "##name slot##['s occupation is]##occupation slot##". A different sentence with the same or similar semantics as the first sentence "Wang Dawei works as a doctor" replaces the nodes with semantic slots to obtain a new regular expression "##name slot##[works]##occupation slot##[works]", which is different in form from "##name slot##['s occupation is]##occupation slot##", but has the same or similar semantics.
[0129] In this embodiment, when the relationship between nodes is a noun, a new regular expression is generated by using a verb with similar semantics to express the relationship, thereby expanding the existing regular expression library, making the constructed regular expression library more complete, and improving the semantic parsing ability of the regular expression library.
[0130] In another embodiment of the present invention, Figure 5 As shown, a device for expanding regular expressions based on a knowledge graph includes:
[0131] The knowledge graph construction module 110 is used to construct a domain knowledge graph.
[0132] The sentence generation module 120 is used to obtain a first sentence pattern according to the two nodes and the relationship when the relationship between two adjacent nodes in the domain knowledge graph is a noun, and the predicate of the first sentence pattern is a judgment verb; and, when the relationship between two adjacent nodes in the domain knowledge graph is a noun, express the relationship with a verb with similar semantics to obtain a different sentence pattern with the same semantics as the first sentence pattern; and, when the relationship between two adjacent nodes in the domain knowledge graph is a verb, obtain a second sentence pattern according to the two nodes and the relationship, and the predicate of the second sentence pattern is the relationship; and, when the relationship between two adjacent nodes in the domain knowledge graph is a verb, express the relationship with a noun with similar semantics to obtain a different sentence pattern with the same semantics as the second sentence pattern.
[0133] Specifically, when the relationship between two adjacent nodes is a verb, a second sentence pattern can be generated according to the two nodes and their relationship, and the second sentence pattern uses the relationship as a predicate.
[0134] For example, the node "Li Bai", the node "Quiet Night Thoughts", and the relationship "Creation" form a triple (Li Bai, Creation, Quiet Night Thoughts), where the part of speech of "Creation" is a verb and can be directly used as the predicate of the sentence to obtain the second sentence: Li Bai created Quiet Night Thoughts, and the semantics of this sentence is "Li Bai created Quiet Night Thoughts".
[0135] When the relationship between two adjacent nodes is a verb, the relationship is expressed by nouns with similar semantics, thereby obtaining a different sentence pattern with the same or similar semantics as the second sentence pattern.
[0136] Continuing with the above example, for example, if the relation "create" is a verb and is expressed using the noun "works" which has similar semantics, we can get a different sentence pattern with the same or similar semantics as the second sentence pattern: "Li Bai's work is Quiet Night Thoughts."
[0137] The semantic slot acquisition module 130 is used to acquire the semantic slot corresponding to the node.
[0138] The regular expression generation module 140 is used to generate a regular expression according to the sentence pattern, the semantic slot, and the non-node part of the sentence pattern, and update the regular expression library.
[0139] Specifically, the semantic slot corresponding to the node is obtained, and the semantic slot is used to replace the node in the sentence to generate a regular expression.
[0140] Continuing with the above example, for example, in the second sentence "Li Bai created Quiet Night Thoughts", the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poem name slot", thus generating the regular expression "##name slot##[creation]##poem name slot##".
[0141] A different sentence pattern with the same or similar semantics to the second sentence pattern is "Li Bai's work is Quiet Night Thoughts", in which the node "Li Bai" is replaced by "name slot", and the node "Quiet Night Thoughts" is replaced by "poem name slot", thereby generating a new regular expression "##name slot##['s][work][is]##poem name slot##", which is different in form from "##name slot##[creation]##poem name slot##", but has the same or similar semantics.
[0142] In this embodiment, when the relationship between nodes is a verb, a new regular expression is generated by using nouns with similar semantics to express the relationship, thereby expanding the existing regular expression library, making the constructed regular expression library more complete, and improving the semantic parsing ability of the regular expression library.
[0143] It should be noted that the above embodiments can be freely combined as needed. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention.
Claims
1. A method for expanding regular expressions based on knowledge graphs, It is characterized in that include: Build domain knowledge graph; At least one sentence pattern is obtained according to two adjacent nodes in the domain knowledge graph and the relationship between them, including: When the relationship between two adjacent nodes in the domain knowledge graph is a noun, a first sentence pattern is obtained according to the two nodes and the relationship, and the predicate of the first sentence pattern is a judgment verb; When the relationship between two adjacent nodes in the domain knowledge graph is a verb, a second sentence is obtained according to the two nodes and the relationship, and the predicate of the second sentence is the relationship; When the relationship between two adjacent nodes in the domain knowledge graph is a noun, the relationship is expressed by a verb with similar semantics, and a second sentence pattern with the same or similar semantics as the first sentence pattern is obtained according to the nodes and the verb with similar semantics to the relationship, and the verb is the predicate of the second sentence pattern; Get the semantic slot corresponding to the node; The nodes of the sentence are replaced with corresponding semantic slots to generate a regular expression, and the regular expression library is updated.
2. According to claim 1, a method for expanding regular expressions based on knowledge graph, It is characterized in that The obtaining of at least one sentence pattern according to two adjacent nodes in the domain knowledge graph and the relationship between them includes: When a bidirectional relationship exists between two adjacent nodes in the domain knowledge graph, different sentence patterns are obtained according to the bidirectional relationship.
3. According to the method for expanding regular expressions based on knowledge graph according to claim 1, It is characterized in that The step of obtaining at least one sentence pattern according to two adjacent nodes in the domain knowledge graph and the relationship between them also includes: When the relationship between two adjacent nodes in the domain knowledge graph is a verb, the relationship is expressed by nouns with similar semantics, and a first sentence pattern with the same or similar semantics as the second sentence pattern is obtained based on the nodes and the nouns with similar semantics to the relationship.
4. A device for expanding regular expressions based on knowledge graphs, It is characterized in that include: Knowledge graph construction module, used to build domain knowledge graph; The sentence generation module is used to obtain at least one sentence according to two adjacent nodes in the domain knowledge graph and the relationship between them, including: When the relationship between two adjacent nodes in the domain knowledge graph is a noun, a first sentence pattern is obtained according to the two nodes and the relationship, and the predicate of the first sentence pattern is a judgment verb; When the relationship between two adjacent nodes in the domain knowledge graph is a verb, a second sentence is obtained according to the two nodes and the relationship, and the predicate of the second sentence is the relationship; When the relationship between two adjacent nodes in the domain knowledge graph is a noun, the relationship is expressed by a verb with similar semantics, and a second sentence pattern with the same or similar semantics as the first sentence pattern is obtained according to the nodes and the verb with similar semantics to the relationship, and the verb is the predicate of the second sentence pattern; A semantic slot acquisition module, used to acquire the semantic slot corresponding to the node; The regular expression generation module replaces the nodes of the sentence with corresponding semantic slots to generate a regular expression and update the regular expression library.
5. A device for expanding regular expressions based on knowledge graph according to claim 4, Features: The sentence generation module is further used to express the relationship using nouns with similar semantics when the relationship between two adjacent nodes in the domain knowledge graph is a verb, and obtain a first sentence with the same or similar semantics as the second sentence based on the nodes and the nouns with similar semantics to the relationship.
Citation Information
Patent Citations
Rule matching method, device and equipment and storage medium
CN109558479A
