A hybrid-mode-based adaptive construction and intelligent question-answering method for API knowledge graph

Through the adaptive construction of API knowledge graphs and intelligent question-and-answer methods of hybrid mode, natural language processing and machine learning are used to solve the limitations of traditional API document retrieval methods, and efficient query of unknown or partially known API information is achieved, and programming is improved Personnel’s work efficiency and query accuracy.

CN114840657BActive Publication Date: 2024-12-13BEIJING UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210589958.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-27
Publication Date
2024-12-13
Estimated Expiration
2042-05-27

AI Technical Summary

Technical Problem

Traditional API document retrieval methods are limited, and it is difficult for programmers to efficiently query unknown or partially known API information, resulting in time-consuming and low accuracy in the query process. Especially for unknown and unknown queries, the efficiency and quality of programming tasks are affected.

Method used

Adaptive construction method of API knowledge graph using a hybrid mode, collects information from Stack Overflow, Github and local API documents, builds knowledge graphs, and combines natural language processing and machine learning to realize the classification and query of query statements, providing rules-based Template and machine learning query methods to enhance the accuracy and speed of query results.

Benefits of technology

It improves the accuracy and speed of API queries, fills the gap between natural language queries and knowledge graphs, enhances programmers' work efficiency, and ensures the time efficiency and result quality of programming tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840657B_ABST
    Figure CN114840657B_ABST
Patent Text Reader

Abstract

The present invention discloses a hybrid mode API knowledge graph adaptive construction and intelligent question-answering method. The content of the method includes: based on Stack Overflow platform question discussion, Github open source project, network software library API description document, local project collection API information and knowledge extraction to build API knowledge graph; adaptive training hybrid mode API knowledge graph query model; query user uses hybrid mode knowledge graph query to query API information through natural language description; build a structure partitioned visual API information display page. The present invention solves the problems of low accuracy, slow speed, low content richness and unintuitive presentation when using natural language description query in traditional API query. The hybrid mode knowledge graph API query method provides query users with more accurate, richer content and more intuitive API information, thereby improving the development efficiency of programmers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of API recommendation and information search, and more specifically, to a hybrid-mode-based API knowledge graph adaptive construction and intelligent question-answering method. Background Art

[0002] With the development of software projects, the scale and complexity of software projects are increasing day by day. In the face of increasingly complex software development projects, the programming interface in the software library plays a vital role. Programmers can complete software development tasks more efficiently with the help of API. However, with the frequent updates of APIs and API documents in the software library on the Internet, and the sharp increase in API description documents generated in the project and Internet software packages, it is almost impossible for programmers to be familiar with all the relevant knowledge of each API. Therefore, programmers need to learn the relevant knowledge and functional usage of the required API in the project, and also need to find suitable APIs to complete development tasks according to the implementation requirements. In this context, the search for API documents and related information naturally becomes a crucial part of determining the work efficiency of programmers.

[0003] However, the traditional way of searching for API documents and related information has strong limitations. Taking the search of the Chinese API documents of the C++ standard library as an example, the API document search page only provides a classification of API types and only supports the search method for API names. For an API name that we already know or can directly retrieve the relevant information of the API, we need to view the API function or other related detailed information. We call it a query for "known unknowns".

[0004] Many times, programmers need to query a class function whose class is known but whose name is unknown. For example, if they need to find the function in the C++ standard library "String class that can convert numbers to string form", they need to traverse all the functions under the String class and read the functional description of each function to find the class function that meets the requirements. Furthermore, programmers may need to face the situation of finding a class or function that can meet the requirements of the programming task without any known information, such as finding "a function that can convert a number to string form". In this case, there is no way to start. Programmers do not have time and are not allowed to traverse and read all the API introductions. In programming tasks, we can often only quickly screen all APIs that may meet our needs in the categories we think are possible based on our programming experience, or seek help from Internet forums and wait for others to answer. For the first solution, we need to spend a lot of time, and there is a risk that the correct answer will be ignored during the review process, resulting in the API document that could have solved our problem, but the search does not get the results we need; for the second solution, it takes an unpredictable amount of waiting time to wait for others' answers, and there is also a risk that no one will answer or the answer is incorrect. We call this situation where we know some information but cannot directly retrieve the API target to be queried, or we do not know the API target to be queried at all, a query of "unknown unknowns". Obviously, in programming work, the process of querying "unknown unknown" APIs based on traditional API document search will consume a lot of our time and bring unpredictable fluctuations to the completion time and quality of our programming tasks.

[0005] Therefore, we urgently need an API question-answering method that can make up for the above-mentioned defects in traditional API information retrieval methods to improve the efficiency of programmers in software development. Summary of the invention

[0006] The purpose of the present invention is to provide a hybrid mode API knowledge graph adaptive construction and intelligent question-answering method, which utilizes the structural advantages of the knowledge graph established with API-related information and combines it with the natural language processing of query statements to expand the scope of query question search and the richness of search results. At the same time, the processing of query statements completes the expansion of Chinese, and can be expanded to other languages. In addition, the classification of query statements and the hybrid query method based on rule templates and machine learning improve the accuracy of query results while ensuring the search speed of queries, providing time guarantees for programmers in the search process during development.

[0007] To achieve the above object, the present invention adopts the following method:

[0008] Based on Stack Overflow platform discussion, Github open source projects, network software library API documentation, local projects collect API information and perform knowledge extraction to build an API knowledge graph;

[0009] Adaptively train hybrid API knowledge graph query models;

[0010] Query users use hybrid knowledge graph query to query API information through natural language description;

[0011] Build a visual API information display page for structure partitions.

[0012] Specifically, based on the discussion of Stack Overflow platform issues, Github open source projects, network software library API documentation, and local projects, API information is collected and knowledge is extracted to build an API knowledge graph, including: extracting API names as API entities and extracting relationships between APIs, API attributes, and sample codes based on the tags of HTML pages and tags of documentation from API documentation pages in network software libraries and local API documentation, as entity relationships, and storing them in the form of triples; obtaining software projects from Github in star order, splitting source code files from them, and obtaining API entities and relationships between entities in the source code together with the local project source code according to the structure of the abstract syntax tree, and verifying the integrity of the entity sample code, extracting sample codes from the source code as a supplement to the API relationship for missing API entities, and storing the API entity relationship in the form of triples; extracting non-structural information knowledge from the text of API documentation and Github project questions and answers. Named entity recognition is completed by using long short-term memory artificial neural networks and adding conditional random fields to mark the text at the character level. Based on the Chinese vocabulary and the extracted entity vocabulary, the text is segmented and the parts of speech are marked. The segmentation results are subjected to dependency syntax analysis to generate a dependency syntax tree. Semantic role analysis is performed through the dependency syntax tree to obtain semantic role annotations for words. Semantic roles extract relation triples based on the semantic roles of words according to pre-defined rules. The API knowledge graph is constructed with the extracted API entities as nodes and relation triples as edges.

[0013] Furthermore, the method for training a hybrid mode knowledge graph query model includes: obtaining popular API query questions and adopted answers on the community platform, building query statement classification rules, and classifying query statements into rule query questions and non-rule query questions according to the rules; querying rule questions using a query method based on rule templates, and querying queries that do not match the rules through similarity matching; and querying non-rule questions using a query method based on machine learning.

[0014] Furthermore, the method in which a user uses a natural language statement to query through a hybrid mode API knowledge graph query method includes: the user inputs a query statement; the query is divided into rule questions and non-rule questions according to a query statement classification model; according to the query classification, a rule template-based knowledge graph query method or a machine learning-based knowledge graph query method is adaptively selected to query, and the query result is returned.

[0015] Preferably, the method of building a visual API information display page includes: building a front-end display interface based on Django, displaying API information through an interactive tree diagram and a structured partitioned page, and annotating core answer API information based on query question content analysis.

[0016] The beneficial effects of the present invention are as follows:

[0017] (1) The hybrid API knowledge graph and question-and-answer method disclosed in the examples of this specification provide natural language query statements for API information query, meet the needs of programmers for API information search through natural language function descriptions, fill the gap between knowledge graph search and query statements, improve the accuracy and query speed of natural language query in API query in traditional methods, solve the difficulties of programmers in querying unknown APIs, and improve the work efficiency of programmers.

[0018] (2) By supplementing the knowledge graph with external data such as local project API documents and source code and project source code on the Internet, the information in the knowledge graph is enriched, the query search scope is expanded, and the content presented in the API query results is expanded, helping programmers solve the problem that the query API results are not sufficient to handle the difficulties they face.

[0019] (3) This specification proposes a hybrid mode API knowledge graph API adaptive construction and hybrid question-and-answer method. By adopting a hybrid mode query method, query statements are classified and queried, thereby improving the accuracy of the query while ensuring the query time, thereby ensuring the time efficiency of programmers in querying APIs during programming tasks.

[0020] (4) Visual and interactive API information presentation methods enrich the way the knowledge graph information is presented, highlighting the core query content, helping programmers to obtain the core information for solving problems more quickly and accurately, and improving the query efficiency of programmers. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The specific implementation modes of the present invention are further described in detail below in conjunction with the accompanying drawings.

[0022] Figure 1 A schematic diagram showing the overall method of the present invention.

[0023] Figure 2 This is a diagram showing the data collection source for the present invention.

[0024] Figure 3 This is a diagram illustrating source code knowledge extraction according to the present invention.

[0025] Figure 4 A graph is constructed to represent the text knowledge extraction knowledge graph of the present invention.

[0026] Figure 5 The present invention represents a hybrid mode knowledge graph query model training flow chart.

[0027] Figure 6 The present invention represents a mixed mode knowledge graph query flow chart. DETAILED DESCRIPTION

[0028] In order to explain the present invention more clearly, the present invention is further described below in conjunction with preferred embodiments and drawings. It should be understood by those skilled in the art that the content described below is illustrative rather than restrictive, and should not be used to limit the scope of protection of the present invention.

[0029] First, the technical concept of the technical solution disclosed by the present invention is explained. The traditional API document query method has high limitations, especially the index query of the API document needs to be performed when the API name is known. The functional description often fails to obtain the expected search results due to the difference between the natural language description of the problem and the API document description. At the same time, the query results of the API document have low content richness, and the text form of the display method is not intuitive, so programmers may spend a lot of time reading the API query results, but still cannot find the expected information to solve the problem.

[0030] The technical solution provided by the embodiments of the present application is described in detail below in conjunction with the accompanying drawings.

[0031] Embodiment 1

[0032] Figure 1This is a flow chart of the hybrid API knowledge graph API construction and intelligent question answering method. Figure 1 This embodiment provides a hybrid mode API knowledge graph adaptive construction and intelligent question answering method, including:

[0033] To achieve the above object, the present invention adopts the following method:

[0034] Based on Stack Overflow platform discussion, Github open source projects, network software library API documentation, local projects collect API information and perform knowledge extraction to build an API knowledge graph;

[0035] Adaptively train hybrid API knowledge graph query models;

[0036] Query users use hybrid knowledge graph query to query API information through natural language description;

[0037] Build a visual API information display page for structure partitions.

[0038] According to the hybrid mode knowledge graph API construction and intelligent question answering method provided in the above embodiment, please refer to Figure 2 , extract the API name as API entity and the relationship between APIs, API attributes, and sample code according to the tags of HTML pages and description documents in the API documentation pages in the network software library and the local API description documents, and store them in the form of triples as entity relationships; obtain software projects from the Github platform in star order, split the source code files from them, and merge them with the local project source code files to build a source code database; select API query question statements and corresponding adopted answer texts according to popularity from Stack Overflow question discussions, and merge the collected question and answer texts from Github open source projects into unstructured API question and answer text storage.

[0039] For further information, see Figure 3Process the source code file. Obtain the abstract syntax tree of the code by compiling the source code of different languages. The abstract syntax tree is a tree representation of the abstract syntax structure of the source code, and each node on the tree represents a structure in the source code. By converting the textual code into this structured form, the relevant information of the class and function definition can be quickly extracted from it. According to the structure of the abstract syntax tree, obtain the name of the class defined in the source code (belonging file.class name), the initialization parameters of the class, the class function, the public variables of the class, the inheritance relationship of the class, the full name of the function (belonging file.(class).function), the function parameters, the return value of the function, the calling relationship of the function and other related information, and store them in the form of triples. For each class and function entity, verify the integrity of its sample code, functional description and other relationships. For functions with missing functional descriptions, try to find comments near the definition of the class or function; then refer to Figure 4 , extract 5 entities of project, file, class, function, and variable from the non-structural information in the API documentation and Github project q&a text, as well as 9 relationships of using class (file-class), using function (file-function), using variable (file-variable), inheritance (class-class), class function (class-function), initialization parameter (class-variable), calling (function-function), parameter (function-variable), and return value (function-variable). Use long short-term memory artificial neural network to add conditional random field to perform character-level entity recognition on text and obtain entity tag sequence in the correct order. Based on the Chinese vocabulary library and the extracted entity vocabulary, the text is segmented and the part of speech is marked, and then the segmentation result is subjected to dependency syntactic analysis to generate a dependency syntactic tree. Semantic role analysis is performed through the dependency syntactic tree to obtain the semantic role labeling of words, and the relationship three is extracted according to the semantic role of the word according to the pre-established rules as a knowledge supplement. Based on the acquired entities and relationships, the knowledge graph is constructed.

[0040] Further, see Figure 5, train the model in the hybrid knowledge graph API query. First, train the query statement classification model, collect question descriptions and corresponding adopted answers from Stack Overflow, and classify them into regular query questions and non-regular query questions, train the LSTM query statement classification model, and classify the user query API information into regular questions and non-regular questions after training by the LSTM query statement classification model; then train the query model based on machine learning. The entities and relations in the knowledge graph are converted into two matrices, each row represents the word vector of an entity or relationship, and the TransE knowledge graph model is used to train the entity word vector and relationship vector. The entity word vector is used to represent the triple relationship in the knowledge graph. Furthermore, the GRU query statement mapping model is trained to transform the query statement into the vector of the fact API entity node.

[0041] For further information, see Figure 6 , the user enters a natural language query statement from the front-end query interface to query the API information. The program classifies the query statement into a rule problem or a non-rule problem according to the rules. For rule problems, the query statement is segmented using the Chinese vocabulary and the entity vocabulary, and the part of speech of the segmentation result is marked. Then, the word tuple sequence is used for dependency syntactic analysis to obtain the dependency syntactic relationship between words, and the specific dependency syntactic relationship related to the words in the entity table is selected according to the rules and converted into a query statement according to the pre-set rules. In the case where the query statement does not obtain a query result through the above query, the knowledge graph is queried for API information with the entity in the query statement as the core, and the similarity between the entity in the candidate set and the query statement is calculated. The API entity with the highest similarity is selected as the query result, and the relevant API information is returned. For non-rule problems, the query statement is mapped to an entity node vector in the knowledge graph vector space according to the query statement mapping model, and the API entity node is queried in the knowledge graph through similarity matching, and the relevant information is returned.

[0042] Then, the returned API information is organized into an API information presentation structure according to the query question content. API related information is returned to the front end, and the API information is presented in a label partitioned manner according to the query question content and the returned information structure. According to the semantics of the query question, the core information of the question answer is highlighted, and the API relationship information is visually presented in the form of an interactive tree diagram.

[0043] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium or deployed in a cloud server. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a ROM, a RAM, etc.

[0044] The above content is an example of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. A hybrid-mode-based adaptive construction and intelligent question-answering method for API knowledge graphs. It is characterized in that include: Based on Stack Overflow platform discussion, Github open source projects, network software library API documentation, local projects collect API information and perform knowledge extraction to build an API knowledge graph; Adaptively train hybrid API knowledge graph query models; Query users use the hybrid knowledge graph to query API information through natural language descriptions; Build a visual API information display page for structure partitions; Methods for collecting structured API information and unstructured API text information include: Using Internet API documents and local project description documents as sources, we obtain structured API information through the tags of API documents, and extract API entities and the relationships between APIs. Collect unstructured software code files from Github project code repositories and local projects, and extract API entities and relationships between APIs through abstract syntax tree analysis. Using Stack Overflow platform question discussions and GitHub Q&A, local project source code and API documentation as sources, we extract API entities and the relationships between APIs in unstructured API text information in the form of API question and answer pairs through named entity recognition, dependency parsing and semantic role recognition. The hybrid API knowledge graph query method includes: The query statements are classified through rule algorithms and neural networks, and the query problems are divided into rule query problems and non-rule query problems; According to the problem classification, choose the rule template-based method or the machine learning-based method to complete the subsequent query; Building a visual API information display page includes: The front-end display interface is built based on Django, and the API information is displayed through interactive tree diagrams and structured partition pages.

2. The method according to claim 1, It is characterized in that The method for adaptively training a hybrid-mode API knowledge graph query model includes: The training query pairs are classified into a regular query problem and a non-regular query problem; Train the word embedding matrix of entities and relations in the knowledge graph and the query statement mapping vector space model.

Citation Information

Patent Citations

  • An API knowledge graph construction method based on a reference document

    CN109739994A

  • Construction method and device of security knowledge self-service query system based on knowledge graph

    CN113312501A