Disclosure of Invention
The embodiment of the application provides a question-answering method and device based on a dictionary tree, question-answering equipment and a readable storage medium, and can solve the problem that user input cannot be well recognized in the prior art.
In a first aspect, an embodiment of the present application provides a question-answering method based on a dictionary tree, including:
acquiring inquiry information input by a user, wherein the inquiry information comprises an alias name;
inputting the query information into a preset dictionary tree to obtain a first entity of the query information;
inputting the first entity into a preset knowledge graph to obtain a second entity corresponding to the first entity;
and generating answer information according to the second entity, and returning the answer information to the user.
In a possible manner of the first aspect, before the obtaining of the query information input by the user, the method includes:
finding out the first entity from the preset knowledge graph;
acquiring an alias name corresponding to the first entity according to a preset alias construction rule, and establishing a corresponding relation between the first entity and the alias name;
and constructing the preset dictionary tree according to the alias name.
In a possible manner of the first aspect, constructing the preset trie according to the alias name includes:
converting the alias name into character data, wherein the character data comprises a first head element, a first middle element and a first tail element;
inserting character data with the same first head element into a first branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, a first middle element and a first tail element, and inserting character data with different first head elements into a second branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element, so as to form the preset dictionary tree.
In a possible implementation manner of the first aspect, acquiring an alias name corresponding to the first entity according to a preset alias construction rule, and establishing a correspondence between the first entity and the alias name includes:
dividing the first entity into sub-entities;
determining a sub-alias name corresponding to the sub-entity;
combining the sub-alias names to obtain the alias names;
and establishing a corresponding relation between the first entity and the alias name.
In a possible implementation manner of the first aspect, inputting the query information into a preset dictionary tree to obtain a first entity of the query information includes:
searching the alias name corresponding to the inquiry information in the preset dictionary tree;
and taking the first entity corresponding to the alias name as the first entity of the query information based on the corresponding relation between the alias name and the first entity.
In a possible implementation manner of the first aspect, generating answer information according to the second entity, and returning the answer information to the user includes:
acquiring candidate answer information matched with the second entity from a preset answer library;
screening out candidate answer information with the highest weight value in the candidate answer information, and taking the candidate answer information with the highest weight value as the answer information.
In a second aspect, an embodiment of the present application provides a question answering device based on a dictionary tree, including:
and the acquisition device is used for acquiring inquiry information input by a user.
Wherein the query information includes an alias name;
the first searching module is used for inputting the inquiry information into a preset dictionary tree to obtain a first entity of the inquiry information.
The second searching module is used for inputting the first entity into a preset knowledge graph to obtain a second entity corresponding to the first entity;
and the feedback module is used for generating answer information according to the second entity and returning the answer information to the user.
In a possible implementation manner of the second aspect, the question answering device further includes:
the searching unit is used for searching the first entity from the preset knowledge graph;
the obtaining unit is used for obtaining an alias name corresponding to the first entity according to a preset alias construction rule and establishing a corresponding relation between the first entity and the alias name;
and the construction unit is used for constructing the preset dictionary tree according to the alias name.
In a possible implementation manner of the second aspect, the building unit includes:
a conversion subunit, configured to convert the alias name into character data, where the character data includes a first head element, a first middle element, and a first tail element;
and the construction subunit is used for inserting the character data with the same first head element into a first branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element, and inserting the character data with different first head elements into a second branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element to form the preset dictionary tree.
In a possible implementation manner of the second aspect, the obtaining unit includes:
a partitioning subunit, configured to partition the first entity into sub-entities;
a determining subunit, configured to determine a sub-alias name corresponding to the sub-entity;
the combination unit is used for combining the sub-alias names to obtain the alias names;
and the establishing subunit is used for establishing the corresponding relation between the first entity and the alias name.
In a possible implementation manner of the second aspect, the first lookup module includes:
the alias name searching unit is used for searching the alias name corresponding to the inquiry information in the preset dictionary tree;
and the searching unit is used for taking the first entity corresponding to the alias name as the first entity of the query information based on the corresponding relation between the alias name and the first entity.
In one possible implementation manner of the second aspect, the feedback module includes:
the candidate answer obtaining module is used for obtaining candidate answer information matched with the second entity from a preset answer library;
and the screening module is used for screening out the candidate answer information with the highest weight value in the candidate answer information, and taking the candidate answer information with the highest weight value as the answer information.
In a third aspect, an embodiment of the present application provides a question answering device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the processor implements the method according to the first aspect
In a fourth aspect, the present application provides a readable storage medium, and the computer program when executed by a processor implements the method as described in the first aspect.
Compared with the prior art, the embodiment of the application has the advantages that:
according to the embodiment of the application, the alias name of the inquiry information and the first entity corresponding to the alias name are firstly identified by using the preset dictionary tree, then the second entity corresponding to the first entity is obtained according to the preset knowledge graph, and finally the answer information is formed according to the second entity, so that the problem that in the prior art, the question answering system in the prior art cannot well identify the user input due to the fact that the alias names of the entities are in a plurality of calling modes is solved, and the effect of accurately replying the user in the question answering process is achieved.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
The technical solution provided by the present application is described below by specific examples.
Referring to fig. 1, a schematic flow chart of a question-answering method based on a dictionary tree provided in an embodiment of the present application is applied to a question-answering device, where the question-answering device includes a server or a terminal device, and the method includes:
and step S101, acquiring inquiry information input by a user.
The query information includes an alias name and a common name.
It should be noted that the query information input by the user may be text information or text information converted according to the voice information input by the user, and the source of the query information input by the user is not limited in this embodiment of the application.
Referring to fig. 2 by way of example and not limitation, a flow chart of the method for question answering based on a dictionary tree in fig. 1 before step S101 according to the embodiment of the present application is shown, where before obtaining query information input by a user, the method includes:
step S201, finding out a first entity from a preset knowledge graph.
The preset knowledge graph comprises a question-answer association relation; the preset knowledge graph includes a first entity, a relationship between the first entity and a second entity, specifically, the first entity may refer to an entity extracted from query information input by a user, for example, how many nationalities the china has, and then the entity extracted from how many nationalities the china has is "china", "how many" and "nationalities", and correspondingly, the second entity may refer to an entity corresponding to the first entity, for example, "56".
In specific application, the knowledge graph content to be displayed is stored in a database in advance according to different application scenes, and different databases such as a neo4j database, a mongoDB database and the like can be selected according to corresponding service scenes. Then, the first entity is found from the preset knowledge graph, namely the first entity is found from the database corresponding to the preset knowledge graph.
Step S202, obtaining an alias name corresponding to the first entity according to a preset alias construction rule, and establishing a corresponding relation between the first entity and the alias name.
As an example and not by way of limitation, the preset alias construction rule may refer to different expression ways of the same entity, that is, the different expression ways substantially point to the same entity, for example, a common name of the entity "china" may be "china", and an alias name may be "china", "the people's republic of china"; for example, the alias name of the entity "frog, level I, mid-landing ship" may be "Frosch, type 108, LSM", where it may be "hundredth company" or "hundredth", "Frosch" is substantially the same as "frog", "level I" is substantially the same as "type 108", and "LSM" is substantially the same as "mid-landing ship". Also for example, the alias name of the entity "Beijing Baidu network science and technology Co., Ltd" may be "Baidu", or "Baidu Co., Ltd".
Specifically, referring to fig. 3, for a specific flowchart of step S202 in fig. 1 of the question-answering method based on the dictionary tree provided in the embodiment of the present application, obtaining an alias name corresponding to a first entity according to a preset alias construction rule, and establishing a corresponding relationship between the first entity and the alias name includes:
step S301, dividing the first entity into sub-entities.
For example, the first entity is "frog, level l, medium landing ship", then the sub-entities are "frog", "level l", "medium landing ship", respectively.
Step S302, the name of the sub-alias corresponding to the sub-entity is determined.
For example, the sub-alias name corresponding to the sub-entity "frog" may be "Frosch", and the sub-alias name corresponding to the sub-entity "medium landing ship" may be "LSM".
And step S303, combining the sub-alias names to obtain the alias names.
It will be appreciated that there may be more than one of each sub-entity and that each of the sub-entities may be combined with each other.
Preferentially, after the sub-alias name corresponding to the sub-entity is determined, some unreasonable data can be cleaned, for example, the entity "Manshan (525) guard ship", and the obtained alias name includes "Manshan" guard ship, "525" and "525 guard ship", where "525" only contains data and cannot actually obtain the corresponding equipment entity through "525", and therefore, similar data which do not conform to the actual situation are removed, and redundancy of the data is reduced.
And step S304, establishing a corresponding relation between the first entity and the alias name.
Specifically, the correspondence between the first entity and the alias name may be established in a mapping manner.
And step S203, constructing a preset dictionary tree according to the alias name.
Specifically, referring to fig. 4, for a specific flowchart illustration in step S203 in fig. 1 of the question-answering method based on the dictionary tree provided in the embodiment of the present application, the construction of the dictionary tree according to the alias name includes:
step S401 converts the alias name into character data.
The character data comprises a first head element, a first middle element and a first tail element.
For example, if the alias name is "Jian-15", the character data is "a, b, c", where "a" corresponds to "Jian", "b" corresponds to "1", and "c" corresponds to "5", where "a" is the first head element, "b" is the first middle element, and "c" is the first tail element.
Step S402, inserting character data with the same first head element into a first branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, a first middle element and a first tail element, and inserting character data with different first head elements into a second branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element, so as to form a preset dictionary tree.
Referring to fig. 9, a schematic structural diagram of a preset dictionary tree of the question-answering method based on the dictionary tree provided in the embodiment of the present application includes character data "fighter 15", character data "fighter 32", and character data "fortune 18", where a first head element of the character data "fighter 15" is "fighter", an intermediate element is "1" and a first tail element is "5", a first head element of the character data "fighter 32" is "fighter", an intermediate element is "3" and a first tail element is "2", a first head element of the character data "fortune 18" is "fortune", an intermediate element is "1" and a first tail element is "8". As can be seen, the character data "fighter 15" and the character data "fighter 32" form a first branch, and the character data "fortune 18" form a second branch.
Step S102, inputting the inquiry information into a preset dictionary tree to obtain a first entity of the inquiry information.
Referring to fig. 5 by way of example and not limitation, a specific flowchart of step S102 in fig. 1 of a method for question answering based on a dictionary tree according to an embodiment of the present application is shown, where query information is input into a preset dictionary tree to obtain a first entity of the query information, where the first entity includes:
step S501, looking up the alias name corresponding to the query information in a preset dictionary tree.
Specifically, each character data in the query information is input into the preset dictionary tree, and is matched with the character data corresponding to the alias name of the preset dictionary tree, so that the alias name corresponding to the successfully matched character data is obtained.
Step S502, based on the corresponding relation between the alias name and the first entity, the first entity corresponding to the alias name is used as the first entity of the query information.
It can be understood that, after the alias name corresponding to the query information is found, the first entity corresponding to the alias name can be obtained.
Step S103, inputting the first entity into a preset knowledge graph to obtain a second entity corresponding to the first entity.
The preset knowledge graph stores the corresponding relation between the first entity and the second entity.
And step S104, generating answer information according to the second entity, and returning the answer information to the user.
By way of example and not limitation, referring to fig. 6, a specific flowchart of step S104 in fig. 1 of the method for question answering based on a dictionary tree according to an embodiment of the present application is shown, where generating answer information according to a second entity and returning the answer information to a user includes:
step S601, obtaining candidate answer information matched with the second entity from a preset answer library.
It is understood that after the second entity is found, the answer information is formed by using the preset answer library.
Step S602, the candidate answer information with the highest weight value among the candidate answer information is screened out, and the candidate answer information with the highest weight value is used as the answer information.
The weight value is preset, and may be set manually, or set according to the number of occurrences of the candidate answer information.
According to the embodiment of the application, the alias name of the inquiry information and the first entity corresponding to the alias name are firstly identified by using the preset dictionary tree, then the second entity corresponding to the first entity is obtained according to the preset knowledge graph, and finally the answer information is formed according to the second entity, so that the problem that in the prior art, the question answering system in the prior art cannot well identify the user input due to the fact that the alias names of the entities are in a plurality of calling modes is solved, and the effect of accurately replying the user in the question answering process is achieved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Corresponding to the question-answering method based on the dictionary tree described in the above embodiment, fig. 7 shows a structural block diagram of the question-answering device based on the dictionary tree provided in the embodiment of the present application, and for convenience of explanation, only the parts related to the embodiment of the present application are shown.
Referring to fig. 7, the trehelf-based question answering apparatus includes:
the obtaining device 71 is used for obtaining the inquiry information input by the user.
Wherein the query information includes an alias name;
the first lookup module 72 is configured to input the query information into a preset dictionary tree, so as to obtain a first entity of the query information.
A second searching module 73, configured to input the first entity into a preset knowledge graph, so as to obtain a second entity corresponding to the first entity;
and a feedback module 74, configured to generate answer information according to the second entity, and return the answer information to the user.
In one possible implementation manner, the question answering apparatus further includes:
the searching unit is used for searching the first entity from the preset knowledge graph;
the obtaining unit is used for obtaining an alias name corresponding to the first entity according to a preset alias construction rule and establishing a corresponding relation between the first entity and the alias name;
and the construction unit is used for constructing the preset dictionary tree according to the alias name.
In one possible implementation, the building unit includes:
a conversion subunit, configured to convert the alias name into character data, where the character data includes a first head element, a first middle element, and a first tail element;
and the construction subunit is used for inserting the character data with the same first head element into a first branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element, and inserting the character data with different first head elements into a second branch of the dictionary tree from near to far according to the arrangement sequence of the first head element, the first middle element and the first tail element to form the preset dictionary tree.
In one possible implementation, the obtaining unit includes:
a partitioning subunit, configured to partition the first entity into sub-entities;
a determining subunit, configured to determine a sub-alias name corresponding to the sub-entity;
the combination unit is used for combining the sub-alias names to obtain the alias names;
and the establishing subunit is used for establishing the corresponding relation between the first entity and the alias name.
In one possible implementation, the first lookup module includes:
the alias name searching unit is used for searching the alias name corresponding to the inquiry information in the preset dictionary tree;
and the searching unit is used for taking the first entity corresponding to the alias name as the first entity of the query information based on the corresponding relation between the alias name and the first entity.
In one possible implementation, the feedback module includes:
the candidate answer obtaining module is used for obtaining candidate answer information matched with the second entity from a preset answer library;
and the screening module is used for screening out the candidate answer information with the highest weight value in the candidate answer information, and taking the candidate answer information with the highest weight value as the answer information.
It should be noted that, for the information interaction, execution process, and other contents between the above-mentioned devices/units, the specific functions and technical effects thereof are based on the same concept as those of the embodiment of the method of the present application, and specific reference may be made to the part of the embodiment of the method, which is not described herein again.
Fig. 8 is a schematic structural diagram of a question answering device according to an embodiment of the present application. As shown in fig. 8, the question answering apparatus of this embodiment includes: at least one processor 80, a memory 81, and a computer program 82 stored in the memory 81 and executable on the at least one processor 80, the processor 80 implementing the steps in the above-described dictionary-tree based method embodiment when executing the computer program 82.
The question answering device 8 may be a terminal device or a server, wherein the terminal device may be a computing device such as a desktop computer, a notebook computer, a palm computer, and the like, and the server may be a computing device such as a cloud server. The question answering device may include, but is not limited to, a processor 80, a memory 81.
The Processor 80 may be a Central Processing Unit (CPU), and the Processor 80 may be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 81 may be an internal storage unit of the question answering device 8 in some embodiments, such as a hard disk or a memory of the question answering device 8.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The embodiments of the present application further provide a readable storage medium, which may be a computer readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the above-mentioned method embodiments.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/network device and method may be implemented in other ways. For example, the above-described apparatus/network device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implementing, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.