Natural statement conversion method, device and equipment and readable storage medium
Through word segmentation, preprocessing and triple combination matching technology, natural language is converted into SparQL statements, which solves the problem of low semantic extraction efficiency of AI models and realizes the efficiency and convenience of knowledge graph query.
Patent Information
- Application Number
- CN202411293225.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, the use of AI models to perform semantic extraction of natural languages has problems such as difficult implementation and low implementation efficiency. Especially when converting natural language into SparQL statements to query knowledge graphs, a large amount of labeled data and complex processing flow are required.
By obtaining the natural statement to be converted, performing word segmentation and preprocessing, extracting the contents in the preset mark as parameters, and combining words according to the preset triple grammar rules, matching the entity relationship of the knowledge graph ontology model, and converting them into SparQL statements to perform Query.
The conversion process of natural language to SparQL statements is realized with high convenience and efficiency, reducing dependence on labeled data, and improving the accuracy and efficiency of query.
Smart Images

Figure CN119226438A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of knowledge graph query technology, and in particular to a natural sentence conversion method, device, equipment and readable storage medium. Background Art
[0002] RDF (Resource Description Framework) is a resource description language. Its essence is a data model. It provides a unified standard for describing entities / resources and their attributes and relationships. RDF is formally represented as SPO triples, which are subject, predicate and object.
[0003] Knowledge graph technology is increasingly used in intelligent question-answering systems, and most knowledge graphs are built based on RDF databases, whose data query language is SparQL (SPARQL Protocol and RDF QueryLanguage, a query language and data acquisition protocol developed for RDF). From the natural language input by the user to the query of the knowledge graph RDF database, the core lies in extracting the user's intention based on the natural language input by the user and converting it into SparQL statements.
[0004] Currently, the industry usually uses AI (Artificial Intelligence) models to extract semantics from natural language. However, the generation of AI models requires a training data set, and the training data set needs to be labeled, so there are problems of difficulty in implementation and low efficiency. Summary of the invention
[0005] The present application provides a natural sentence conversion method, device, equipment and readable storage medium, aiming to solve the problem that the industry currently uses AI models to extract semantics from natural language. The generation of AI models requires a training data set, and the training data set needs to be annotated, which has technical problems such as high implementation difficulty and low efficiency.
[0006] In a first aspect, an embodiment of the present application provides a natural sentence conversion method, the natural sentence conversion method comprising:
[0007] Get the natural sentence to be converted;
[0008] Performing word segmentation and preprocessing on the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and a part of speech of each word;
[0009] Extract the content in the preset tag from the natural sentence to be converted as a parameter;
[0010] The parameters and each word in the first intermediate text except the parameters are combined according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that a plurality of words and parameters of different parts of speech are combined into a subject-predicate-object triple;
[0011] For each first triple, the first triple is converted into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model;
[0012] SparQL statements are generated using all the second triples, so as to query the knowledge graph using the SparQL statements.
[0013] Optionally, obtaining the natural sentence to be converted includes:
[0014] Get the original natural sentence;
[0015] The preset common question words included in the original natural sentence are removed to obtain the natural sentence to be converted.
[0016] Optionally, performing word segmentation and preprocessing on the natural sentence to be converted to obtain the first intermediate text includes:
[0017] Segmenting the natural sentence to be converted to obtain a second intermediate text, wherein the second intermediate text includes all words after segmentation and the part of speech of each word;
[0018] Each word in the second intermediate text is traversed in the order of the natural sentence to be converted, and the words whose part of speech of the current word is a verb and the part of speech of the next word is an auxiliary word are removed, and the words whose part of speech is a distinguishing word are removed, and multiple words whose part of speech of adjacent words is a noun are merged into one word to obtain the first intermediate text.
[0019] Optionally, before converting each first triple into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model for each first triple, the method further includes:
[0020] For each first triple, traverse each word in the first triple. If the current word has a corresponding replacement word in the preset keyword mapping list, replace the current word with the corresponding replacement word. The replacement word in the preset keyword mapping list exists in the ontology model of the knowledge graph.
[0021] Optionally, converting the first triple into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model includes:
[0022] If there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple;
[0023] If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then the entity relationship from the subject to the object of the first triple is searched in the entity relationship of the knowledge graph ontology model, and the entity relationship from the subject to the object of the found first triple is converted into multiple second triples.
[0024] Optionally, in the process of generating SparQL statements using all the second triples, if the second triples include parameters, a SparQL type qualification statement is added to the subject in the second triples including the parameters.
[0025] In a second aspect, an embodiment of the present application provides a natural sentence conversion device, the natural sentence conversion device comprising:
[0026] An acquisition module, used for acquiring natural sentences to be converted;
[0027] A word segmentation module, used for performing word segmentation and preprocessing on the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and a part of speech of each word;
[0028] An extraction module, used for extracting the content in a preset tag from the natural sentence to be converted as a parameter;
[0029] A combining module, used for combining the parameters and each word in the first intermediate text except the parameters according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that a plurality of words and parameters of different parts of speech are combined into a subject-predicate-object triple;
[0030] A conversion module, for converting each first triple into one or more second triples by matching and searching the first triple with an entity relationship of a knowledge graph ontology model;
[0031] A generation module is used to generate SparQL statements using all the second triples, so as to query the knowledge graph using the SparQL statements.
[0032] Optionally, the conversion module is used to:
[0033] If there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple;
[0034] If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then the entity relationship from the subject to the object of the first triple is searched in the entity relationship of the knowledge graph ontology model, and the entity relationship from the subject to the object of the found first triple is converted into multiple second triples.
[0035] In a third aspect, an embodiment of the present application provides a natural sentence conversion device, which includes a processor, a memory, and a natural sentence conversion program stored in the memory and executable by the processor, wherein when the natural sentence conversion program is executed by the processor, the steps of the natural sentence conversion method described above are implemented.
[0036] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a natural sentence conversion program is stored, wherein when the natural sentence conversion program is executed by a processor, the steps of the natural sentence conversion method as described above are implemented.
[0037] The beneficial effects brought by the technical solution provided by the embodiments of the present application include:
[0038] In an embodiment of the present application, a natural sentence to be converted is obtained; the natural sentence to be converted is segmented and preprocessed to obtain a first intermediate text, wherein the first intermediate text includes multiple words and the part of speech of each word; the content in a preset tag is extracted from the natural sentence to be converted as a parameter; the parameters and each word in the first intermediate text except the parameters are combined according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that multiple words and parameters of different parts of speech are combined into subject-predicate-object triples; for each first triple, the first triple is converted into one or more second triples by matching and searching the entity relationship between the first triple and the knowledge graph ontology model; and all the second triples are used to generate SparQL statements for querying the knowledge graph using the SparQL statements. The embodiment of the present application performs word segmentation, preprocessing and parameter extraction on the natural sentence to be converted, combines subject-predicate-object triples according to preset triple grammar rules, and then converts the combined triples based on the entity relationship of the knowledge graph ontology model, and uses the converted triples to generate SparQL statements. Compared with the prior art solution of using AI models for semantic extraction, this embodiment has the advantages of convenient implementation and high efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is a flow chart of an embodiment of a natural sentence conversion method of the present application;
[0040] Figure 2 For this application Figure 1A detailed flow chart of step S10;
[0041] Figure 3 For this application Figure 1 Detailed flow chart of step S20;
[0042] Figure 4 For this application Figure 1 A detailed flow chart of step S50;
[0043] Figure 5 This is a functional module diagram of an embodiment of a natural sentence conversion device of the present application;
[0044] Figure 6 This is a schematic diagram of the hardware structure of the natural sentence conversion device involved in the embodiment of the present application. DETAILED DESCRIPTION
[0045] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0046] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0047] In a first aspect, an embodiment of the present application provides a natural sentence conversion method.
[0048] In one embodiment, referring to Figure 1 , Figure 1 This is a flow chart of an embodiment of the natural sentence conversion method of the present application. Figure 1 As shown, the natural sentence conversion method includes:
[0049] Step S10, obtaining the natural sentence to be converted.
[0050] In this embodiment, the natural sentence to be converted is a sentence in natural language input by the user for querying the knowledge graph database. The natural sentence to be converted is simply understood as a sentence in natural language. Of course, multiple sentences in natural language can also be processed one by one. The query language of the knowledge graph RDF database is SparQL. Since SparQL has a certain degree of professionalism, it is more convenient for ordinary users to query the knowledge graph by inputting natural sentences. Therefore, it is necessary to convert the natural sentence into a SparQL sentence to realize the query of the knowledge graph.
[0051] Step S20, segmenting and preprocessing the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and the part of speech of each word.
[0052] In this embodiment, a segmentation tool such as HanLP can be used to segment the natural sentence to be converted, wherein HanLP is a multilingual natural language processing toolkit for production environments, supporting 10 joint tasks in 104 languages including simplified and traditional Chinese, English, Japanese, Russian, French and German: segmentation, part-of-speech tagging, named entity recognition, dependency syntax analysis, component syntax analysis, semantic dependency analysis, semantic role labeling, stem extraction, lexical and grammatical feature extraction, abstract meaning representation; as well as reference resolution, semantic text similarity, and text style conversion. Preprocessing, such as removing distinguishing words and merging adjacent nouns for multiple words after segmentation, can improve the accuracy of semantic analysis. The first intermediate text obtained after segmentation and preprocessing of the natural sentence to be converted includes multiple words and the part of speech of each word, which serves as the basis for the subsequent combination of subject-verb-object triples. The part of speech includes nouns, verbs, adjectives, numerals, quantifiers, pronouns, adverbs, prepositions, conjunctions, auxiliary words, interjections and onomatopoeia.
[0053] Step S30: extracting the content in the preset tag from the natural sentence to be converted as a parameter.
[0054] In this embodiment, the preset mark may be, for example, [], etc. The content within the preset mark is extracted from the natural sentence to be converted as a parameter. For example, if the natural sentence to be converted includes [127.0.0.1], the content 127.0.0.1 within [] is extracted as the parameter. The preset mark can be used to flexibly extract the parameters, and a more flexible natural sentence query method can be implemented. By using preset marks for specific content, the word segmentation tool can be avoided from segmenting the specific content within the preset mark, and the accuracy of semantic analysis can be improved. For example, the aforementioned parameter 127.0.0.1 is actually a whole. If it is divided into multiple words by the word segmentation tool, it is easy to cause errors in querying the knowledge graph database.
[0055] Step S40, combining the parameters and each word in the first intermediate text except the parameters according to the preset triple grammar rules to obtain one or more first triples, wherein the preset triple grammar rules include a rule that multiple words and parameters of different parts of speech are combined into subject-predicate-object triples.
[0056] In this embodiment, it can be understood that the natural sentence to be converted is used to query the database of the knowledge graph. At present, the database of the knowledge graph is usually built based on RDF. The formal expression of RDF is the form of subject-verb-object triples. The query language used to query the RDF database is SparQL, and SparQL is actually in the form of subject-verb-object triples. Therefore, here, for the multiple words obtained in the above step S20 and the parameters obtained in step S30, one or more first triples are obtained according to the preset triple grammar rules for the generation of subsequent SparQL statements. The preset triple grammar rules include rules for combining multiple words and parameters of different parts of speech into subject-verb-object triples, such as but not limited to "BA param", "{has / includes / contains}A{particle}B" and "A{particle}B", etc., where A and B represent words of different parts of speech, and param represents parameters. For example, based on the preset triple grammar rule of "{has / includes / contains}A{particle}B", the triple that can be combined is "B has A", and based on the preset triple grammar rule of "A{particle}B", the triple that can be combined is "A's B".
[0057] Step S50, for each first triple, convert the first triple into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model.
[0058] In this embodiment, in order to achieve accurate query of the knowledge graph database using the natural sentences to be converted, it is necessary to establish a mapping relationship between the natural sentences to be converted and the knowledge graph ontology model. It is easy to understand that, for example, a first triple is "network element's business", if the entity relationship of the knowledge graph's ontology model is "network element-port" and "port-business", that is, the three entities of the knowledge graph's ontology model "network element", "port" and "business", there is no direct entity relationship between "network element" and "business", but "network element" is associated with "port" and "port" is associated with "business". Therefore, the SparQL statement generated by the triple of "network element's business" is used to query the knowledge graph database, which will result in no data content being queried. Therefore, it is necessary to convert each first triple into one or more second triples by matching and searching the entity relationship between the first triple and the knowledge graph ontology model, that is, converting the first triple into a second triple that is adapted to the entity relationship in the knowledge graph ontology model. As mentioned above, the first triplet is "the business of the network element". By matching and searching the first triplet "the business of the network element" and the entity relationship of the knowledge graph ontology model (the entity relationship includes "network element" associated with "port", and "port" associated with "business"), the first triplet "the business of the network element" is converted into two second triplet, namely "the port of the network element" and "the business of the port". Among them, the knowledge graph ontology model refers to the abstraction, classification and representation of knowledge elements to form a graph so that computers can better understand and use this knowledge. The construction of the knowledge graph ontology model mainly includes three levels: entity, attribute, and relationship. Entity represents an entity with independent meaning, attribute represents the attribute of the entity, and relationship represents the relationship between entities. The ontology model of the knowledge graph is equivalent to the data organization structure model of the knowledge graph, and the specific data in the knowledge graph is equivalent to the instance under the corresponding ontology model.
[0059] Step S60: Generate SparQL statements using all second triples, so as to query the knowledge graph using the SparQL statements.
[0060] In this embodiment, all converted second triples are used to generate SparQL statements according to the grammatical format of SparQL. Since the second triples are processed by word segmentation, preprocessing, parameter extraction, and entity relationship conversion based on the knowledge graph ontology model of the natural sentences to be converted, the generated SparQL statements can realize accurate query of the knowledge graph database.
[0061] In this embodiment, the natural sentences to be converted are segmented and preprocessed, which can improve the accuracy of the semantic analysis of the natural sentences to be converted. The extraction of parameters can be flexibly implemented through preset tags, and a more flexible natural sentence query method can be implemented. By using preset tags for specific content, the word segmentation tool can be avoided from segmenting the specific content within the preset tags, which can improve the accuracy of semantic analysis. The subject-predicate-object triples are combined according to the preset triple grammar rules, and then the combined triples are converted based on the entity relationship of the knowledge graph ontology model. The converted triples are used to generate SparQL statements. Compared with the prior art solution of using AI models for semantic extraction, it has the advantages of convenient implementation and high efficiency.
[0062] Further, in one embodiment, referring to Figure 2 , Figure 2 For this application Figure 1 The detailed flow chart of step S10 is as follows: Figure 2 As shown, step S10 includes:
[0063] Step S101, obtaining an original natural sentence;
[0064] Step S102, removing the preset common question words included in the original natural sentence to obtain the natural sentence to be converted.
[0065] In this embodiment, the user may input the original natural sentence in a manner such as voice input and text input, etc. The original natural sentence input by the user may include some common question words, such as "query and ask", etc. Since the SparQL statement is the query statement of the knowledge graph RDF database, the common question words included in the original natural sentence are not helpful for generating SparQL statements. If they are not removed, it will affect the efficiency and accuracy of subsequent processing.
[0066] Further, in one embodiment, referring to Figure 3 , Figure 3 For this application Figure 1 The detailed flow chart of step S20 is as follows: Figure 3 As shown, step S20 includes:
[0067] Step S201, segmenting the natural sentence to be converted to obtain a second intermediate text, wherein the second intermediate text includes all the words after segmentation and the part of speech of each word;
[0068] Step S202, traverse each word in the second intermediate text in the order of the natural sentence to be converted, remove the words whose part of speech of the current word is a verb and the part of speech of the next word is an auxiliary word, remove the words whose part of speech is a distinguishing word, merge multiple words whose part of speech of adjacent words is a noun into one word, and obtain the first intermediate text.
[0069] In this embodiment, if the word segmentation tool HanLP is used to segment the natural sentence to be converted, a second intermediate text is obtained. The second intermediate text includes all the words after word segmentation and the part of speech of each word. The words in the second intermediate text are traversed in the order in the natural sentence to be converted, and the words whose part of speech of the current word is a verb and the part of speech of the next word is an auxiliary word are removed. The words whose part of speech is a distinguishing word (such as "all") are removed. These two types of words are not helpful for generating SparQL statements. If they are not removed, the efficiency and accuracy of subsequent processing will be affected. Multiple words whose part of speech of adjacent words is nouns are merged into one word because the word segmentation tool usually recognizes multiple names as multiple noun words, and generally this grammar actually represents an object. For example, "RLOS alarm", "RLOS" will be recognized as a noun, and "alarm" will be recognized as a noun. In fact, "RLOS alarm" represents a specific alarm type.
[0070] Furthermore, in one embodiment, before step S50, the following steps are included:
[0071] For each first triple, traverse each word in the first triple. If the current word has a corresponding replacement word in the preset keyword mapping list, replace the current word with the corresponding replacement word. The replacement word in the preset keyword mapping list exists in the ontology model of the knowledge graph.
[0072] In this embodiment, it is easy to understand that the words in the first triple obtained from the natural sentence to be converted may not exist in the ontology model of the knowledge graph. For example, the knowledge graph ontology model uses "age" when modeling. If the word in the first triple obtained from the natural sentence to be converted is "age", it will result in no data content being queried. However, "age" and "age" actually express the same meaning. Therefore, when the knowledge graph ontology model is established, a preset keyword mapping list can be established. Each replacement word in the preset keyword mapping list is constructed based on the ontology model of the knowledge graph, and then multiple synonyms of each replacement word are mapped to it and stored in the preset keyword mapping list. After obtaining the first triple based on the natural sentence to be converted, the words in the first triple that exist in the preset keyword mapping list are replaced. For example, the synonyms of the words "age" and "age" in the first triple are replaced with "age" in the knowledge graph ontology model based on the preset keyword mapping list.
[0073] Further, in one embodiment, referring to Figure 4 , Figure 4 For this application Figure 1 The detailed flow chart of step S50 is as follows: Figure 4 As shown, step S50 includes:
[0074] Step S501: if there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple;
[0075] Step S502: If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then search for the entity relationship from the subject to the object of the first triple in the entity relationship of the knowledge graph ontology model, and convert the found entity relationship from the subject to the object of the first triple into multiple second triples.
[0076] In this embodiment, we continue to take the first triplet of "network element business" as an example. If there is an entity relationship such as "network element-business" in the entity relationship of the knowledge graph ontology model, there is no need to convert the first triplet, and the first triplet is directly used as the second triplet. If there is no entity relationship such as "network element-business" in the entity relationship of the knowledge graph ontology model, the entity relationship from subject to object of the first triplet is searched in the entity relationship of the knowledge graph ontology model. For example, the entity relationship from subject to object of the first triplet "network element-port" and "port-business" is converted into two second triplet, namely "network element port" and "port business". It should be noted that this is only based on knowledge graph ontology model. Taking the entity relationships such as "network element-port" and "port-service" in the graph ontology model as an example, in practice, the knowledge graph ontology model may also have entity relationships such as "network element-port", "port-entity" and "entity-service". The conversion results in three second triples, namely "port of network element", "entity of port" and "service of entity". There may also be entity relationships with multiple different paths from "network element" to "service". For the case where there are multiple different entity relationship paths, when converting the first triplet into the second triplet, the triples on each entity relationship path are unioned, or the entity relationship on the shortest path can be selected and converted into multiple second triples.
[0077] Further, in the process of generating SparQL statements using all the second triples, if the second triples include parameters, a SparQL type qualification statement is added to the subject in the second triples including the parameters.
[0078] In this embodiment, the converted second triple may or may not include parameters. If no parameters are included, the subject, predicate, and object in the triple are all composed of words other than parameters. For the second triple that includes parameters, for example, "network element ip1.1.1.1", where "1.1.1.1" is the parameter, after adding the SparQL type qualification statement type to the subject "network element", "?A rdf:type: network element" and "?A:ip1.1.1.1" are obtained. For the second triple that does not include parameters, for example, "port associated service", there is no need to add the SparQL type qualification statement type, and after conversion, "?B:associated?C" is obtained.
[0079] In this embodiment, the original natural sentence "Query what services are associated with the port of the network element with an alarm whose IP is [1.1.1.1]?" is taken as an example, the preset common question word "query" of the original natural sentence is removed to obtain the natural sentence to be converted "What services are associated with the port of the network element with an alarm whose IP is [1.1.1.1]?", the content in the preset mark [] is extracted from the natural sentence to be converted as a parameter, and the parameter "1.1.1.1" is obtained. The parameter and each word except the parameter in the first intermediate text are combined according to the preset triple grammar rule to obtain multiple first triples, namely "network element IP 1.1.1.1", "port of network element", "port has an alarm", "service of the port" and "what services are there". For each first triple, the first For each word in the triplet, keyword replacement is performed according to a preset keyword mapping list, and the first triplet is converted into multiple second triples by matching and searching the entity relationship between the first triplet and the knowledge graph ontology model, such as "network element has port port", "port has Alarm alarm" and "port has Biz business". Finally, all the second triples are used to generate SparQL statements, and the generated SparQL statement is: "select distinct? R4where{? R1rdf:type: network element.? R1:ip"1.1.1.1".? R1:hasPort? R2.? R2:hasAlarm? R3.? R2:hasBiz? R4.}".
[0080] In a second aspect, an embodiment of the present application also provides a natural sentence conversion device.
[0081] In one embodiment, referring to Figure 5 , Figure 5 This is a functional module diagram of an embodiment of the natural sentence conversion device of the present application. Figure 5 As shown, the natural sentence conversion device includes:
[0082] An acquisition module 10 is used to acquire a natural sentence to be converted;
[0083] A word segmentation module 20, used for performing word segmentation and preprocessing on the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and a part of speech of each word;
[0084] An extraction module 30 is used to extract the content in the preset mark from the natural sentence to be converted as a parameter;
[0085] A combining module 40 is used to combine the parameters and each word in the first intermediate text except the parameters according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that a plurality of words and parameters of different parts of speech are combined into a subject-predicate-object triple;
[0086] A conversion module 50, for converting each first triple into one or more second triples by matching and searching the first triple with an entity relationship of the knowledge graph ontology model;
[0087] The generating module 60 is used to generate SparQL statements using all the second triples, so as to query the knowledge graph using the SparQL statements.
[0088] Furthermore, in one embodiment, the acquisition module 10 is used to:
[0089] Get the original natural sentence;
[0090] The preset common question words included in the original natural sentence are removed to obtain the natural sentence to be converted.
[0091] Furthermore, in one embodiment, the word segmentation module 20 is used to:
[0092] Segmenting the natural sentence to be converted to obtain a second intermediate text, wherein the second intermediate text includes all words after segmentation and the part of speech of each word;
[0093] Each word in the second intermediate text is traversed in the order of the natural sentence to be converted, and the words whose part of speech of the current word is a verb and the part of speech of the next word is an auxiliary word are removed, and the words whose part of speech is a distinguishing word are removed, and multiple words whose part of speech of adjacent words is a noun are merged into one word to obtain the first intermediate text.
[0094] Furthermore, in one embodiment, the natural sentence conversion device further includes a replacement module, which is used to:
[0095] For each first triple, traverse each word in the first triple. If the current word has a corresponding replacement word in the preset keyword mapping list, replace the current word with the corresponding replacement word. The replacement word in the preset keyword mapping list exists in the ontology model of the knowledge graph.
[0096] Furthermore, in one embodiment, the conversion module 50 is used to:
[0097] If there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple;
[0098] If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then the entity relationship from the subject to the object of the first triple is searched in the entity relationship of the knowledge graph ontology model, and the entity relationship from the subject to the object of the found first triple is converted into multiple second triples.
[0099] Furthermore, in one embodiment, in the process of generating SparQL statements using all the second triples, if the second triples include parameters, a SparQL type qualification statement is added to the subject in the second triples including the parameters.
[0100] Among them, the functional implementation of each module in the above-mentioned natural sentence conversion device corresponds to the various steps in the above-mentioned natural sentence conversion method embodiment, and its functions and implementation processes will not be repeated here one by one.
[0101] In a third aspect, an embodiment of the present application provides a natural sentence conversion device.
[0102] Reference Figure 6 , Figure 6 Schematic diagram of the hardware structure of the natural sentence conversion device involved in the embodiment of the present application. In the embodiment of the present application, the natural sentence conversion device may include a processor, a memory, a communication interface and a communication bus.
[0103] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.
[0104] The communication interface includes an input / output (I / O) interface, a physical interface, and a logical interface, etc., which are used to interconnect the devices inside the natural sentence conversion device, and an interface used to interconnect the natural sentence conversion device with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, an optical fiber interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.
[0105] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0106] The processor may be a general-purpose processor, and the general-purpose processor may call the natural sentence conversion program stored in the memory and execute the natural sentence conversion method provided by the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the natural sentence conversion program is called may refer to the various embodiments of the natural sentence conversion method of the present application, which will not be repeated here.
[0107] Those skilled in the art will understand that Figure 6 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0108] In a fourth aspect, an embodiment of the present application also provides a readable storage medium.
[0109] A natural sentence conversion program is stored on the readable storage medium of the present application, wherein when the natural sentence conversion program is executed by a processor, the steps of the natural sentence conversion method as described above are implemented.
[0110] Among them, the method implemented when the natural sentence conversion program is executed can refer to the various embodiments of the natural sentence conversion method of the present application, and will not be repeated here.
[0111] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0112] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.
[0113] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0114] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0115] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.
[0116] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0117] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A natural sentence conversion method, characterized in that: The natural sentence conversion method comprises: Get the natural sentence to be converted; Performing word segmentation and preprocessing on the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and a part of speech of each word; Extract the content in the preset tag from the natural sentence to be converted as a parameter; The parameters and each word in the first intermediate text except the parameters are combined according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that a plurality of words and parameters of different parts of speech are combined into a subject-predicate-object triple; For each first triple, the first triple is converted into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model; SparQL statements are generated using all the second triples, so as to query the knowledge graph using the SparQL statements.
2. The natural sentence conversion method according to claim 1, characterized in that: The obtaining of the natural sentence to be converted comprises: Get the original natural sentence; The preset common question words included in the original natural sentence are removed to obtain the natural sentence to be converted.
3. The natural sentence conversion method according to claim 1, characterized in that: The segmentation and preprocessing of the natural sentence to be converted to obtain the first intermediate text includes: Segmenting the natural sentence to be converted to obtain a second intermediate text, wherein the second intermediate text includes all the words after segmentation and the part of speech of each word; Each word in the second intermediate text is traversed in the order of the natural sentence to be converted, and the words whose part of speech of the current word is a verb and the part of speech of the next word is an auxiliary word are removed, and the words whose part of speech is a distinguishing word are removed, and multiple words whose part of speech of adjacent words is a noun are merged into one word to obtain the first intermediate text.
4. The natural sentence conversion method according to claim 1, characterized in that: Before converting each first triple into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model for each first triple, the method further includes: For each first triple, traverse each word in the first triple. If the current word has a corresponding replacement word in the preset keyword mapping list, replace the current word with the corresponding replacement word. The replacement word in the preset keyword mapping list exists in the ontology model of the knowledge graph.
5. The natural sentence conversion method according to claim 1, characterized in that: The converting the first triple into one or more second triples by matching and searching the first triple with the entity relationship of the knowledge graph ontology model comprises: If there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple; If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then the entity relationship from the subject to the object of the first triple is searched in the entity relationship of the knowledge graph ontology model, and the entity relationship from the subject to the object of the found first triple is converted into multiple second triples.
6. The natural sentence conversion method according to claim 1, characterized in that: In the process of generating SparQL statements using all the second triples, if the second triples include parameters, a SparQL type qualification statement is added to the subject in the second triples including the parameters.
7. A natural sentence conversion device, characterized in that: The natural sentence conversion device comprises: An acquisition module, used for acquiring natural sentences to be converted; A word segmentation module, used for performing word segmentation and preprocessing on the natural sentence to be converted to obtain a first intermediate text, wherein the first intermediate text includes a plurality of words and a part of speech of each word; An extraction module, used for extracting the content in a preset tag from the natural sentence to be converted as a parameter; A combining module, used for combining the parameters and each word in the first intermediate text except the parameters according to a preset triple grammar rule to obtain one or more first triples, wherein the preset triple grammar rule includes a rule that a plurality of words and parameters of different parts of speech are combined into a subject-predicate-object triple; A conversion module, for converting each first triple into one or more second triples by matching and searching the first triple with an entity relationship of a knowledge graph ontology model; A generation module is used to generate SparQL statements using all the second triples, so as to query the knowledge graph using the SparQL statements.
8. The natural sentence conversion device according to claim 7, characterized in that: The conversion module is used for: If there is an entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, the first triple is used as the second triple; If there is no entity relationship matching the first triple in the entity relationship of the knowledge graph ontology model, then the entity relationship from the subject to the object of the first triple is searched in the entity relationship of the knowledge graph ontology model, and the entity relationship from the subject to the object of the found first triple is converted into multiple second triples.
9. A natural sentence conversion device, characterized in that: The natural sentence conversion device includes a processor, a memory, and a natural sentence conversion program stored in the memory and executable by the processor, wherein when the natural sentence conversion program is executed by the processor, the steps of the natural sentence conversion method as described in any one of claims 1 to 6 are implemented.
10. A readable storage medium, characterized in that: The readable storage medium stores a natural sentence conversion program, wherein when the natural sentence conversion program is executed by a processor, the steps of the natural sentence conversion method according to any one of claims 1 to 6 are implemented.
