API (Application Program Interface) calling method and device
Using natural language text to describe API calling requirements and generate API calling instructions solves the usability problem caused by the complexity of API interfaces in the existing technology, and enables users to call API interfaces without in-depth learning.
Patent Information
- Application Number
- CN202410592602.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-09-10
AI Technical Summary
In the existing technology, software product API interfaces are numerous and have complex functions, which requires users to deeply study and understand the functions and calling logic of the API interface, which increases the learning cost and reduces the ease of use of the API interface.
By obtaining the API calling requirements described in natural language text, performing preset processing to generate API calling instructions, and calling the corresponding API interface based on these instructions, the interaction process between the user and the API interface is simplified.
There is no need to study the API interface functions and calling logic in depth. Users can call the API interface through natural language text, which improves the ease of use of the API interface.
Smart Images

Figure CN118626162A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of API interface calling, and in particular to an API interface calling method and device. Background Art
[0002] API (Application Program Interface) is an interface provided by a software product to the outside world. By calling the API interface of the software product, the software product can perform corresponding operations.
[0003] At present, users need to deeply study and understand the corresponding functions and calling logic of the software product API interface before they can implement API interface calls. However, there are many API interfaces in software products and their functions and calling logic are complex. Users need to have a high level of technical skills and spend a lot of learning costs to understand the API interface, which makes the software product API interface not easy to use. Summary of the invention
[0004] In view of this, the present application proposes an API interface calling method and device, the main purpose of which is to improve the usability of the software product API interface.
[0005] In order to achieve the above objectives, this application mainly provides the following technical solutions:
[0006] In a first aspect, the present application provides an API interface calling method, the API interface calling method comprising:
[0007] Obtaining a natural language text, where the natural language text is used to describe a call requirement for an API interface in a software product;
[0008] Performing preset processing on the natural language text to generate an API call instruction that meets the call requirement;
[0009] Based on the API calling instruction, the corresponding API interface is called.
[0010] In some embodiments of the present application, the natural language text is preset processed to generate API call instructions that meet the calling requirements, including: obtaining a knowledge graph of the software product, wherein the knowledge graph contains knowledge data required to generate API call instructions; pattern-linking the natural language text with the knowledge graph to obtain target knowledge data related to the natural language text; and generating API call instructions that meet the calling requirements based on the target knowledge data.
[0011] In some embodiments of the present application, the knowledge data includes the association relationship between keywords required to generate API call instructions and the corresponding semantic tags of the keywords, and the semantic tags are used to indicate the semantics expressed by the corresponding keywords in the process of generating API call instructions. Then, the natural language text is pattern-linked with the knowledge graph to obtain the target knowledge data related to the natural language text, including: performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text; matching the word segments with the knowledge graph to obtain the target semantic tags corresponding to the word segments; determining the word segments and the corresponding target semantic tags as the target knowledge data related to the natural language text.
[0012] In some embodiments of the present application, the word segmentation is matched with the knowledge graph to obtain a target semantic label corresponding to the word segmentation, including: determining a target keyword in the knowledge graph as a keyword to start the matching, wherein the target keyword is an entity keyword used to describe an entity related to an API interface; matching the word segmentation whose target semantic label is not determined in the natural language text with the keywords to participate in the matching; if there is a word segmentation whose target semantic label is not determined and matches a keyword in the keywords to participate in the matching, then determining the semantic label of the matched keyword as the target semantic label of the corresponding word segmentation, and determining the keyword associated with the matched keyword as the keyword to participate in the matching, and continuing to match the word segmentation whose target semantic label is still not determined with the newly determined keyword to participate in the matching; if there is a word segmentation whose target semantic label is not determined and does not match a keyword in the keywords to participate in the matching, and there is a word segmentation whose target semantic label is not determined and matches a keyword in the keywords to participate in the matching and the matched keyword does not have an associated keyword, or the word segmentation whose target semantic label is not determined does not match a keyword in the keywords to participate in the matching, then a prompt indicating that the target semantic label determination failed is issued for the word segmentation that does not match the keyword.
[0013] In some embodiments of the present application, the word segmentation of the undetermined target semantic tag in the natural language text is matched with the keywords participating in the matching, including: determining whether the word segmentation of the undetermined target semantic tag is contained in the keywords participating in the matching; if contained, determining that the word segmentation of the corresponding undetermined target semantic tag matches the keyword in the keywords participating in the matching; if not contained, determining that the word segmentation of the corresponding undetermined target semantic tag does not match the keyword in the keywords participating in the matching.
[0015] In some embodiments of the present application, before issuing a prompt that the target semantic tag determination failed for the word segmentation that did not match the keyword, the API interface calling method also includes: detecting whether the word segmentation that did not match the keyword is a specified data type; if so, determining the first semantic tag corresponding to the specified data type as the target semantic tag of the corresponding word segmentation.
[0016] In some embodiments of the present application, the API interface calling method also includes: if it is detected that the word segmentation that does not match the keyword is not a specified data type, a second semantic tag is determined as the target semantic tag of the corresponding word segmentation, and the second semantic tag is used to indicate that the semantics of the corresponding word segmentation is unknown.
[0017] In some embodiments of the present application, the API interface calling method also includes: after determining the target semantic label of the corresponding word segmentation, detecting whether the corresponding word segmentation is contained in the word segmentation whose target semantic label has not yet been determined; if contained, the corresponding word segmentation whose target semantic label has not yet been determined is eliminated.
[0018] In some embodiments of the present application, after performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text, the API interface calling method also includes: determining the number of word units, the number of word units is used to indicate the number of adjacent word segments that need to be merged together, and the number of word units is an integer not less than 2 and not greater than the total number of word segments; merging the adjacent word units into a new word segment according to the order of appearance of each word segment in the natural language text; and adding the merged new word segment to the word segment included in the natural language text.
[0019] In some embodiments of the present application, the adjacent word-unit number of word-units are merged into a new word-unit according to the order of appearance of each word-unit in the natural language text, including: for each word-unit, based on the order of appearance of the word-unit in the natural language text, the word-unit and a target number of word-units that are located after the word-unit and are continuously adjacent to the word-unit are merged into a new word-unit, where the target number is the value of the word-unit number minus one.
[0020] In some embodiments of the present application, after performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text, the API interface calling method also includes: detecting whether there are word segments with unknown semantics in the word segments included in the natural language text; if so, removing the corresponding word segments.
[0021] In some embodiments of the present application, based on the target knowledge data, an API call instruction that meets the calling requirements is generated, including: determining the word embedding vector of each of the word segments and the semantic tag embedding vector of the corresponding target semantic tag; integrating the word embedding vector and the semantic tag embedding vector corresponding to each word segment to obtain the description data corresponding to each word segment; using the API call instruction generation model corresponding to the software product to process the description data to obtain the API call instruction that meets the calling requirements.
[0022] In some embodiments of the present application, the API interface calling method also includes: determining the semantic information of each of the word segments in the natural language text, wherein the semantic information is used to indicate the semantic expression of the corresponding word segment for the calling requirement; determining the semantic embedding vector of the corresponding semantic information of each of the word segment; and adding the semantic embedding vector to the description data of the corresponding word segment.
[0023] In some embodiments of the present application, determining the semantic information of each of the segmented words in the natural language text includes: determining the position of each of the segmented words in the natural language text; and determining the semantic information of the corresponding segmented words based on the position;
[0024] And / or, determining the sentence component corresponding to each of the segmented words in the natural language text; and determining the semantic information of the corresponding segmented word based on the sentence component.
[0025] In some embodiments of the present application, the API interface calling method also includes: obtaining API interface configuration information of the API interface included in the software product; extracting keywords and association relationship information from the API interface configuration information, the keywords including entity keywords for describing API interface-related entities and attribute keywords for describing entity attributes, and the association relationship information including keywords for describing association relationships between API interface-related entities and keywords for describing association relationships between entity attributes and entities; performing semantic recognition on the extracted keywords to obtain semantic tags of the corresponding keywords; based on the relationship information, establishing associations between entity keywords and between attribute keywords and corresponding entity keywords; associating semantic tags with corresponding keywords to obtain the knowledge graph.
[0026] In some embodiments of the present application, after generating an API call instruction that meets the call requirements, the API interface calling method further includes: determining completion data for the API call instruction corresponding to the software product; and using the completion data to complete the API call instruction.
[0027] In some embodiments of the present application, the completion data includes at least one of the following: a request header, a request method, and a request attribute.
[0028] In a second aspect, the present application provides an API interface calling device, the API interface calling device comprising:
[0029] An acquisition module is used to acquire natural language text, where the natural language text is used to describe the call requirements for the API interface in the software product;
[0030] A generation module, used to perform preset processing on the natural language text to generate an API call instruction that meets the call requirement;
[0031] The calling module is used to call the corresponding API interface based on the API calling instruction.
[0032] In a third aspect, the present application provides a computer-readable storage medium, which includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the API interface calling method described in the first aspect.
[0033] In a fourth aspect, the present application provides an electronic device, comprising: a memory for storing a program; and a processor, coupled to the memory, for running the program to execute the API interface calling method described in the first aspect.
[0034] The API interface calling method and device provided by the present application implement API interface calling through natural language text, specifically, obtaining natural language text for describing the calling requirements for the API interface in the software product, and then pre-processing the natural language text to generate an API calling instruction that meets the calling requirements, and calling the corresponding API interface based on the generated API calling instruction. It can be seen that the scheme provided by the present application uses natural language to interact with the software product. After expressing the calling requirements for the API interface in the software product through natural language text, the natural language text can be processed to obtain the API calling instruction that meets the calling requirements, and the corresponding API interface in the software product can be called based on the API calling instruction. In this way, the user does not need to deeply study and understand the corresponding functions and calling logic of the API interface, and can call the API interface in the software product through natural language, thereby improving the ease of use of the API interface of the software product.
[0035] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0037] Figure 1 A flowchart of an API interface calling method provided by an embodiment of the present application is shown;
[0038] Figure 2A schematic diagram of a knowledge graph provided by an embodiment of the present application is shown;
[0039] Figure 3 A schematic diagram of an API call instruction generation model provided by an embodiment of the present application is shown;
[0040] Figure 4 A schematic diagram showing the structure of an API interface calling device provided by an embodiment of the present application is shown;
[0041] Figure 5 A schematic diagram of the structure of an API interface calling device provided in another embodiment of the present application is shown. DETAILED DESCRIPTION
[0042] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0043] At present, there are more and more API interfaces in software products, and the functions and calling logic are becoming more and more complicated. It is difficult for ordinary users to deeply learn and understand the corresponding functions and calling logic of API interfaces in a short period of time and implement API interface calls. Therefore, how to improve the usability of software product API interfaces has become a key issue in the industry.
[0044] After research, the inventors found that if natural language can be used to interact with software products, users do not need to deeply learn and understand the corresponding functions and calling logic of the API interface. After expressing the calling requirements for the API interface in the software product through natural language text, they can call the API interface in the software product that meets the calling requirements, thereby improving the usability of the software product API interface.
[0045] Based on the above findings, this embodiment specifically provides a technical solution for calling an API interface, specifically: obtaining natural language text, the natural language text is used to describe the calling requirements of the API interface in the software product; pre-processing the natural language text to generate API calling instructions that meet the calling requirements; based on the API calling instructions, calling the corresponding API interface.
[0046] The technical solution for calling the API interface provided in this embodiment can be applied to any software product provided with an API interface to implement the call of the API interface of the software product. This embodiment does not limit the specific type of the software product, which can be flexibly determined based on specific requirements. Exemplarily, the software product is a network security operation product.
[0047] Based on the above-mentioned technical solution of API interface calling, this embodiment specifically provides an API interface calling method and device. The API interface calling method and device provided in this embodiment are specifically described below.
[0048] like Figure 1 As shown, the embodiment of the present application provides an API interface calling method, and the API interface calling method may include the following steps 101 to 103:
[0049] 101. Obtain natural language text, where the natural language text is used to describe the call requirements for the API interface in the software product.
[0050] In this embodiment, in order to improve the usability of the software product API interface, natural language is used to interact with the software product, so that the user does not need to deeply learn and understand the corresponding functions and calling logic of the API interface. After expressing the calling requirements of the API interface in the software product through natural language text, the API interface that meets the calling requirements can be called. Therefore, the first step of the API interface calling method provided in this embodiment is to obtain natural language text.
[0051] The methods for obtaining natural language text may include but are not limited to the following two: First, in order to improve the convenience of obtaining natural language text, the user inputs natural language text through voice input, so the specific process of obtaining natural language text may include the following steps: monitor whether there is voice input; if so, determine whether the input voice is related to the API interface call; if so, convert the voice into corresponding natural language text. The other is that the user inputs natural language text through text input, so the specific process of obtaining natural language text may include the following steps: monitor whether there is natural language text input, and if so, obtain the natural language text.
[0052] Natural language text is used to describe the call requirements for the API interface in the software product. When the user submits the natural language text, he may not know which API interface in the software product can meet the call requirements. Therefore, the call requirement is only an expectation of using the API interface, which represents the functions and actions that the API interface is expected to perform, so that the corresponding API interface can be matched based on these functions and actions for calling, so that these functions or actions can be realized through the call. Exemplarily, the natural language text is "query the high-risk alarm of the destination IP containing 192.168.1.1", and the call requirement it describes is the expectation to call the API interface that can perform the action of "query the high-risk alarm of the destination IP containing 192.168.1.1".
[0053] 102. Perform preset processing on the natural language text to generate API call instructions that meet the calling requirements.
[0055] After obtaining the natural language text, it is necessary to perform preset processing on the natural language text to generate an API call instruction that meets the call requirements, so as to implement the call of the corresponding API interface based on the API call instruction. The preset processing is to obtain the target knowledge data required for calling the API interface that meets the call requirements based on the natural language text. The target knowledge data is the necessary knowledge data required to generate the API call instruction that meets the call requirements.
[0056] The specific process of performing preset processing on the natural language text to generate an API call instruction that meets the call requirements may include the following steps 102A to 102C:
[0057] 102A. Obtain a knowledge graph of the software product, where the knowledge graph contains knowledge data required to generate API call instructions.
[0058] After obtaining the natural language text, it is necessary to obtain the knowledge graph of the software product in order to obtain the target knowledge data required to generate API call instructions that meet the calling requirements based on the natural language text and the knowledge data contained in the knowledge graph.
[0059] Taking into account the different configurations of API interfaces in different software products, the knowledge data required by the API call instructions contained in the knowledge graph are strongly related to the software products. Therefore, it is necessary to obtain the corresponding knowledge graph of the software products in a targeted manner, so as to obtain the corresponding target knowledge data more accurately based on the natural language text and the knowledge data contained in the knowledge graph.
[0060] The knowledge data in the knowledge graph includes the association relationship between the keywords required to generate the API call instruction and the semantic tags corresponding to the keywords, and the semantic tags are used to indicate the semantics expressed by the corresponding keywords in the process of generating the API call instruction. The semantic tags may include but are not limited to at least one of the following: a semantic unknown tag (for example, none), which is used to indicate that the semantics of the corresponding keyword is unknown, an API tag (for example, API), which is used to indicate that the corresponding keyword is the function of the API interface, a business tag (for example, Business), which is used to indicate that the corresponding keyword is the business of the API interface, a parameter tag (for example, Param), which is used to indicate that the corresponding keyword is a parameter required to generate the API call instruction, and a parameter value tag (for example, Value), which is used to indicate that the corresponding keyword is a parameter value required to generate the API call instruction.
[0061] 102B. Link the natural language text with the knowledge graph to obtain target knowledge data related to the natural language text.
[0062] Schema linking can link and associate different types of data. In this way, regardless of whether the data type of the natural language text and the knowledge graph is the same, by schema linking the natural language text with the knowledge graph, the natural language text can be successfully matched to the relevant target knowledge data from the knowledge graph.
[0063] The specific process of pattern-linking the natural language text with the knowledge graph to obtain target knowledge data related to the natural language text may include the following steps 102B1 to 102B3:
[0064] 102B1. Perform word segmentation processing on the natural language text to obtain the word segments included in the natural language text.
[0065] The specific process of performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text may be: using a preset word segmentation tool to perform word segmentation processing on the natural language text to obtain the word segments included in the natural language text. The type of word segmentation tool can be determined based on business needs, and this embodiment does not make specific limitations. Exemplarily, the word segmentation tool uses the HanLP word segmentation tool.
[0066] For example, the natural language text is: query the destination IP containing 192.168.1.2 for high-risk alarm. After the natural language text is segmented as follows: query / destination / IP / containing / 192.168.1.2 / of / high-risk alarm. The natural language text includes the following segmentations: query, destination, IP, containing, 192.168.1.2, of, high-risk alarm.
[0067] Furthermore, in order to more accurately generate API call instructions that meet the call requirements, after the natural language text is segmented to obtain the segmented words included in the natural language text, the API interface call method may also include a segmentation enrichment step to enrich a large number of segmented words. The segmentation enrichment step is specifically as follows: determine the number of word units, the number of word units is used to indicate the number of adjacent segmented words that need to be merged together, and the number of word units is an integer not less than 2 and not greater than the total number of segmented words. According to the order of appearance of each segmented word in the natural language text, the adjacent segmented words of the number of word units are merged into a new segmented word. The merged new segmented words are added to the segmented words included in the natural language text.
[0068] The number of word units is used to indicate the number of adjacent word segments that need to be merged together. The number of word units can be determined based on business needs, and this embodiment does not limit it. It should be noted that the number of word units is an integer not less than 2 and not greater than the total number of word segments. Exemplarily, the total number of word segments included in the natural language text is 8, then the number of word units can take values in the range of: 2, 3, 4, 5, 6, 7, 8. In addition, it should be noted that the number of word units can be set to one or more based on business needs, and this embodiment does not limit it.
[0069] After determining the number of tokens, perform the step of merging adjacent tokens into a new token according to the order of appearance of each token in the natural language text. The specific execution process of this step can be: for each token, based on the order of appearance of the token in the natural language text, merge the token and the target number of tokens that are consecutive and adjacent to the token after the token. The target number is the value obtained by subtracting one from the number of tokens. That is to say, the first target number of tokens included in the new token are the last target number of tokens of the previous new token.
[0070] Exemplarily, the tokens included in the natural language text are: query, purpose, IP, contain, 192.168.1.2, of, high-risk, warning. Determine the number of tokens 2 and the number of tokens 3. The new tokens obtained after the step of token enrichment for the number of tokens 2 include: query purpose, purpose IP, IP contain, contain 192.168.1.2, 192.168.1.2 of, of high-risk, high-risk warning. The new tokens obtained after the step of token enrichment for the number of tokens 3 include: query purpose IP, purpose IP contain, IP contain 192.168.1.2, contain 192.168.1.2 of, 192.168.1.2 of high-risk, of high-risk warning. The step of token enrichment can be performed based on the number of tokens in a selected token enrichment model. The token enrichment model can be selected but is not limited to the n-gram model.
[0071] The new tokens obtained based on the number of tokens are all added to the tokens included in the natural language text, thereby realizing the expansion of the tokens included in the natural language text.
[0072] Furthermore, considering that tokens with unknown semantics do not contribute much to the determination of the target knowledge data, in order to reduce the processing volume of pattern linking, this API interface call method can also include the following token elimination step: detect whether there are tokens with unknown semantics in the tokens included in the natural language text; if so, eliminate the corresponding tokens.
[0073] Tokens with unknown semantics are tokens for which the corresponding semantics cannot be summarized through prior knowledge. Here, tokens with unknown semantics include two types: one is tokens that are clearly known to have no semantics, such as "of"; the other is tokens for which it is not possible to clearly know whether they have no semantics.
[0074] The methods for detecting whether there are word segments with unknown semantics in the word segments included in natural language text can include the following two types: One is to match the word segments included in natural language text with preset words with unknown semantics. If the match is successful, the corresponding word segment is determined to be a word segment with unknown semantics. For example, the preset words with unknown semantics can include, but are not limited to, "de", "děi". The other is to input the word segments included in natural language text into a semantic recognition model, which is used to recognize the semantics of the word segments. If there are word segments whose semantics are not recognized by the semantic recognition model, the corresponding word segments are determined to be word segments with unknown semantics.
[0075] 102B2. Match the word segments with a knowledge graph to obtain the corresponding target semantic labels of the word segments.
[0076] After obtaining the word segments included in natural language text, in order to more accurately understand the true API interface call requirements expressed by natural language text, it is necessary to match the word segments with a knowledge graph to obtain the corresponding target semantic labels of the word segments. The specific process of matching the word segments with a knowledge graph to obtain the corresponding target semantic labels of the word segments can include the following steps 1 to 4:
[0077] Step 1. Determine the target keywords in the knowledge graph as the keywords starting to participate in the match. The target keywords are entity keywords used to describe API interface-related entities.
[0078] The knowledge data of the knowledge graph includes the association relationships between the keywords required to generate API call instructions and the corresponding semantic labels of the keywords. Among them, the keywords include entity keywords used to describe API interface-related entities and attribute keywords used to describe entity attributes. The association relationships between entity keywords are used to describe the association relationships between API interface-related entities, and the association relationships between entity keywords and attribute keywords are used to describe the association relationships between entities and entity attributes.
[0079] Considering that entity keywords are the basis of all association relationships in the knowledge graph, entity keywords are selected as the target keywords, and the target keywords are determined as the keywords starting to participate in the match, so as to start matching with the word segments included in natural language text from the entity keywords.
[0080] Exemplarily, Figure 2 shows a knowledge graph. Figure 2 In the knowledge graph shown, the dotted circles represent entity keywords used to describe API interface-related entities, the solid circles represent attribute keywords used to describe entity attributes, and the arrows represent the association relationships between the keywords. It should be noted that the semantic category labels associated with each keyword are not shown in Figure 2 herein.
[0081] Step 2: Match the word segments without a determined target semantic label in the natural language text with the keywords involved in the matching.
[0082] The specific process of matching the segmented words of the undetermined target semantic label in the natural language text with the keywords participating in the matching may include the following steps: determining whether the segmented words of the undetermined target semantic label are contained in the keywords participating in the matching; if contained, determining that the segmented words of the corresponding undetermined target semantic label are matched to the keywords participating in the matching; if not contained, determining that the segmented words of the corresponding undetermined target semantic label are not matched to the keywords participating in the matching.
[0083] The specific process of judging whether a word with an undetermined target semantic label is included in the keywords participating in the matching can be: for each word with an undetermined target semantic label, detecting whether the keywords participating in the matching include the same keyword as the word; if included, determining that the word matches the keyword in the keywords participating in the matching; if not included, detecting whether the keywords participating in the matching include a character substring that is the keyword of the word; if so, determining that the word matches the keyword in the keywords participating in the matching; if not, determining that the word does not match the keyword in the keywords participating in the matching.
[0084] For example, the word segmentation of the undetermined target semantic tag is "hazard", and the keywords currently involved in the matching are Figure 2 All entity keywords in the knowledge graph shown. First, check whether the keywords involved in the matching include the same keywords as the segmentation word "harm". After detection, it is found that the keywords involved in the matching do not include the same keywords as the segmentation word "harm". Then continue to check whether there are keywords involved in the matching that contain the character substring of the segmentation word "harm". After detection, it is found that the keyword "harm level" whose character substring is the segmentation word "harm" is included in the keyword for parameter matching. Then it is determined that the segmentation word "harm" matches the keyword in the keywords involved in the matching, and the matched keyword is "harm level".
[0085] Step 3: If there is a word segmentation whose target semantic label has not been determined and it matches a keyword among the keywords participating in the matching, the semantic label of the matched keyword will be determined as the target semantic label of the corresponding word segmentation, and the keyword associated with the matched keyword will be determined as the keyword participating in the matching, and the word segmentation whose target semantic label has not yet been determined will continue to be matched with the newly determined keyword participating in the matching.
[0086] If there is a word segmentation with an undetermined target semantic label that matches a keyword among the keywords participating in the matching, it means that the corresponding word segmentation and the matched keyword have the same semantics expressed in the process of generating the API call instruction, so the semantic label of the matched keyword is determined as the target semantic label of the corresponding word segmentation. At the same time, the keyword associated with the matched keyword is determined as the keyword participating in the matching, and the word segmentation whose target semantic label is still undetermined continues to be matched with the newly determined keyword participating in the matching, so as to continue to determine the corresponding target semantic label for the word segmentation whose target semantic label is still undetermined.
[0087] For example, the participle "hazard" in Figure 2 If a keyword is matched among the keywords participating in the matching of the knowledge graph shown in the figure, and the matched keyword is "hazard level", the semantic label of "hazard level" is determined as the target semantic label of the word segmentation "hazard". Figure 2 The keywords "urgent, high risk, medium risk, low risk, enumerated values and Severity" associated with "hazard level" are determined as the keywords participating in the matching, and the word segmentations included in the natural language text whose target semantic labels have not yet been determined are continued to be matched with the newly determined keywords participating in the matching "urgent, high risk, medium risk, low risk, enumerated values and Severity".
[0088] Furthermore, in order to avoid repeatedly determining the target semantic label for similar word segmentations, the API interface calling method, after determining the target semantic label of the corresponding word segmentation, needs to detect whether the corresponding word segmentation is contained in the word segmentation whose target semantic label has not yet been determined; if contained, the corresponding word segmentation whose target semantic label has not yet been determined will be eliminated.
[0089] The specific process of detecting whether the corresponding participle is included in the participle whose target semantic label has not yet been determined can be: detecting whether the participle whose target semantic label has not yet been determined includes the participle that is the same as the participle; if it is included, determining that the participle is included in the participle whose target semantic label has not yet been determined; if it is not included, detecting whether there is a participle whose character substring is the participle in the participle whose target semantic label has not yet been determined; if it exists, determining that the participle is included in the participle whose target semantic label has not yet been determined; if it does not exist, determining that the participle is not included in the participle whose target semantic label has not yet been determined.
[0090] Exemplarily, after determining the target semantic tag of the word "query", it is detected whether the word "query" is included in the word "query purpose, target IP, IP contains" whose target semantic tag has not yet been determined. After detection, if "query" is included in the word "query purpose, target IP, IP contains" whose target semantic tag has not yet been determined, the word "query purpose" whose target semantic tag has not yet been determined will be removed.
[0091] Step 4: If there is a segmentation with an undetermined target semantic label that does not match any keyword among the keywords participating in the matching, or there is a segmentation with an undetermined target semantic label that matches any keyword among the keywords participating in the matching and the matched keyword does not have any associated keyword, or there is a segmentation with an undetermined target semantic label that does not match any keyword among the keywords participating in the matching, a prompt indicating that the target semantic label determination failed is issued for the segmentation that did not match any keyword.
[0092] If there are segmented words with undetermined target semantic labels that do not match keywords among the keywords involved in the matching, or if there are segmented words with undetermined target semantic labels that match keywords among the keywords involved in the matching and the matched keywords do not have any associated keywords, it means that the knowledge graph can no longer provide keywords for matching with segmented words with undetermined target semantic labels in natural language texts. Based on the knowledge graph, it is no longer possible to determine the corresponding target semantic labels for these segmented words with undetermined target semantic labels. Therefore, a prompt indicating that the target semantic label determination failed is issued for the segmented words that did not match the keywords.
[0093] If the segmented word with undetermined target semantic label does not match any keyword among the keywords involved in the matching, it means that the corresponding target semantic label cannot be determined for the segmented word with undetermined target semantic label based on the knowledge graph. Therefore, a prompt indicating that the target semantic label determination failed is issued for the segmented word that does not match the keyword.
[0094] The purpose of issuing a prompt of target semantic label determination failure for word segments that do not match keywords is to prompt the fact that the target semantic label cannot be determined for the corresponding word segmentation with undetermined target semantic label based on the knowledge graph.
[0095] Furthermore, considering that some word segments cannot determine the corresponding target semantic labels based on the knowledge graph, other methods can also be used to determine the corresponding target semantic labels. Therefore, before issuing a prompt of failure to determine the target semantic label for the word segment that does not match the keyword in the above step four, the API interface calling method can also include the following steps: detecting whether the word segment that does not match the keyword is of a specified data type; if so, determining the first semantic label corresponding to the specified data type as the target semantic label of the corresponding word segment.
[0096] The specified data type and the first semantic tag corresponding to the specified data type can be determined based on business requirements, and this embodiment does not specifically limit it. Exemplarily, the specified data type may include but is not limited to an IP address, a domain name, and the like.
[0097] If it is detected that the word segmentation that does not match the keyword is of the specified data type, it means that although the corresponding target semantic label of the word segmentation cannot be determined based on the knowledge graph, its corresponding specified data type represents its corresponding semantic label. Therefore, the first semantic label corresponding to the specified data type is determined as the target semantic label of the corresponding word segmentation.
[0098] Further, if it is detected that the segmented word that is not matched with the keyword is not of the specified data type, the second semantic tag is determined as the target semantic tag of the corresponding segmented word, and the second semantic tag is used to indicate that the semantics of the corresponding segmented word is unknown.
[0099] If it is detected that the word segmentation that does not match the keyword is not the specified data type, it means that neither the data type based on the knowledge graph nor the word segmentation can clearly identify its semantic label. Therefore, it is determined that the current semantics of the word segmentation is unknown, so the second semantic label is determined as the target semantic label of the corresponding word segmentation.
[0100] 102B3. Determine the word segmentation and the corresponding target semantic label as the target knowledge data related to the natural language text.
[0101] After determining the target semantic labels corresponding to the word segments included in the natural language text, it means that the necessary knowledge data required to generate API call instructions that meet the call requirements are already available. Therefore, the word segments and the corresponding target semantic labels are determined as the target knowledge data related to the natural language text.
[0102] For example, the natural language text includes the following segmentation words: query, destination IP, including, 192.168.1.2, of, high risk, and warning. After the target semantic label is determined, the target knowledge data related to the natural language text is obtained as shown in Table 1.
[0103] Table-1
[0104]
[0105] 102C. Based on the target knowledge data, generate an API call instruction that meets the call requirements.
[0106] After the target knowledge data is determined, the step of generating an API call instruction that meets the call requirement based on the target knowledge data may be executed. The specific execution process of this step may include the following steps 102C1 to 102C3:
[0107] 102C1. Determine the word embedding vector of each word segment and the semantic label embedding vector of the corresponding target semantic label.
[0108] For each word segmentation, a preset word embedding vector determination tool is used to process the word segmentation to obtain the corresponding word embedding vector of the word segmentation, and a preset semantic label embedding vector determination tool is used to process the corresponding target semantic label to obtain the semantic label embedding vector of the corresponding target semantic label.
[0109] 102C2. Integrate the word embedding vector and semantic label embedding vector corresponding to each word segment to obtain the description data corresponding to each word segment.
[0110] For each word segmentation, the word embedding vector and the semantic label embedding vector corresponding to the word segmentation are integrated to obtain the description data corresponding to the word segmentation. The integration process here limits the combination of the word embedding vector and the semantic label embedding vector.
[0111] For example, the combination of the integration processing qualifier embedding vector and the semantic label embedding vector is as follows: i , type i ), where token i Represents the word embedding vector corresponding to the i-th word segmentation, type i Represents the semantic label embedding vector corresponding to the i-th word segmentation.
[0112] Furthermore, in order to further ensure that the generated API call instructions meet the calling requirements, the API interface calling method may also include the following steps: determining the semantic information of each word segment in the natural language text; determining the semantic embedding vector of the corresponding semantic information of each word segment; adding the semantic embedding vector to the description data of the corresponding word segment.
[0113] Semantic information is used to indicate the semantic expression of the corresponding segmentation to the call demand, which can be combined with the target semantic tag to more accurately express the semantics of the segmentation, so that the semantics of the segmentation can more accurately express the API interface call demand. Therefore, the semantic information of each segmentation in the natural language text can be determined, and the determination method can include the following two methods: one is to determine the position of each segmentation in the natural language text; based on the position, the semantic information of the corresponding segmentation is determined. For a segmentation, the position of the segmentation in the natural language text can reflect the semantic relevance between the segmentation and other segmentations, and can indicate the semantic expression of the segmentation to the call demand, so the semantic information of the corresponding segmentation is determined based on the position. The other is to determine the sentence component (for example, subject, predicate, object, etc.) corresponding to each segmentation in the natural language text; based on the sentence component, the semantic information of the corresponding segmentation is determined. For a segmentation, the corresponding sentence component of the segmentation in the natural language text can reflect the semantic relevance between the segmentation and other segmentations, and can indicate the semantic expression of the segmentation to the call demand, so the semantic information of the corresponding segmentation is determined based on the sentence component.
[0114] After determining the semantic information corresponding to each word segment, a preset semantic embedding vector determination tool can be used to process the semantic information to obtain a semantic embedding vector corresponding to the semantic information. After obtaining the semantic embedding vector corresponding to the word segment, the semantic embedding vector is added to the description data of the corresponding word segment to achieve supplementary update of the corresponding description data.
[0115] For example, the description data of the i-th word segment is (token i , type i ), and determine the semantic embedding vector of the i-th word as index i After adding the semantic embedding vector to the description data of the corresponding word segment, the corresponding description data is updated to (token i , type i , index i ).
[0116] 102C3. Use the corresponding API call instruction generation model of the software product, process the description data, and obtain the API call instruction that meets the call requirements.
[0117] In this embodiment, the description data is used as the input of the API call instruction generation model, and the API call instruction generation model processes it to obtain an API call instruction that meets the call requirements. The process of forming the input of the API call instruction generation model based on the description data can be: combining each description data according to the order in which the segmentation appears in the natural language text to form an input, and the format of the input is: [(token 1 , type 1 , index i ),…(token m , type m , index m )], m represents the last participle.
[0118] In this embodiment, in order to improve the availability of API interface call requests in software products, the API call instruction generation model needs to be strongly related to the software product, that is, the API call instruction generation model is a model trained based on the knowledge data required for generating API call instructions corresponding to the software product. The type of API call instruction generation model can be flexibly selected based on business needs, and an exemplary API call instruction generation model can be, but is not limited to, a BERT model.
[0119] Exemplarily, the API call instruction generation model may have the following Figure 3 The encoding and decoding structure shown in Figure 3It can be seen that the encoder and decoder of the API call instruction generation model both use GRU units, and each description data has a corresponding GRU in the encoding structure. Then the output of the encoder will enter the corresponding GRU in the decoding structure. In addition, Figure 3 bos in the figure indicates the prediction start special word, eos indicates the prediction end special word, and S1 and S2 indicate the corresponding intermediate decoding results. Decoding structure After the last GRU decoding, the API call instruction generation model will output the corresponding API call instruction.
[0120] Taking into account the compatibility of API call instructions with software products, and ensuring that the API call instructions can successfully call the corresponding API interface in the software product, after generating API call instructions that meet the call requirements, the API interface call method may also include the following completion steps: determining the completion data of the corresponding API call instructions of the software product; and using the completion data to complete the API call instructions.
[0121] The software product has a corresponding API call instruction format. If the API call instruction lacks the necessary data required by the format, the API interface call cannot be implemented based on the API call instruction. Therefore, it is necessary to determine the corresponding API call instruction completion data of the software product based on the type of software product. The completion data may include but is not limited to at least one of the following: request header, request method, and request attribute. Then, the API call instruction is completed with the completion data.
[0122] The specific process of using the completion data to complete the API call instruction may include: based on the format requirements of the software product for the API call instruction, determining the position of the completion data in the API call instruction, and adding corresponding completion data to the corresponding position.
[0123] Exemplarily, the natural language text is "query destination IP contains 192.168.1.1 high-risk alarm", and then after step 102, after completing the data of the API call instruction generated in step 102, the obtained API call instruction is:
[0124] http: / / 127.0.0.1:88 77 / alarms / query? dst lp=192.168.1.1&severity=3.
[0125] 103. Based on the API call instruction, call the corresponding API interface.
[0126] After obtaining the API call instruction, it means that the corresponding API interface in the software product can be called to meet the call requirements. Therefore, in order to meet the call requirements, the corresponding API interface is called based on the API call instruction. The specific process of calling the corresponding API interface based on the API call instruction can be: calling the corresponding target API interface based on the API interface call request through a preset tool, and the preset tool can be the CURL open source command line tool.
[0127] The API interface calling method provided in the embodiment of the present application implements the API interface calling through natural language text, specifically, obtaining the natural language text used to describe the calling requirements for the API interface in the software product, and then pre-processing the natural language text to generate an API calling instruction that meets the calling requirements, and calling the corresponding API interface based on the generated API calling instruction. It can be seen that the scheme provided in the embodiment of the present application uses natural language to interact with the software product. After expressing the calling requirements for the API interface in the software product through natural language text, the natural language text can be processed to obtain the API calling instruction that meets the calling requirements, and the corresponding API interface in the software product can be called based on the API calling instruction. In this way, the user does not need to deeply study and understand the corresponding functions and calling logic of the API interface, and can call the API interface in the software product through natural language, thereby improving the ease of use of the API interface of the software product.
[0128] In some embodiments of the present application, after the natural language text is preset processed in the above-mentioned step 102 to generate API calling instructions that meet the calling requirements, the API interface calling method may also include the following steps: recording the mapping relationship between the natural language text and the API calling instructions, and / or recording the mapping relationship between the calling requirements described in the natural language text and the API calling instructions.
[0129] When the same natural language text is received again or a natural language text with the same calling requirement is received again, the corresponding API calling instruction can be directly obtained based on the mapping relationship without the need to perform preset processing on the obtained natural language text.
[0130] In some embodiments of the application, in order to obtain the corresponding knowledge graph of the software product in step 102A, the API interface calling method may also include the step of constructing a knowledge graph, which is specifically: obtaining the API interface configuration information of the API interface included in the software product; extracting keywords and association relationship information from the API interface configuration information, the keywords include entity keywords for describing API interface-related entities and attribute keywords for describing entity attributes, and the association relationship information includes describing the association relationship between API interface-related entities and describing the association relationship between entity attributes and entities; performing semantic recognition on the extracted keywords to obtain semantic labels of the corresponding keywords; based on the relationship information, establishing associations between entity keywords and between attribute keywords and corresponding entity keywords; associating semantic labels with corresponding keywords to obtain a knowledge graph.
[0131] API interface configuration information is used to describe information related to the API interface, including API-related metadata, which may include but is not limited to at least one of the following: business name, API interface, parameter name, parameter type, and structured data of parameter optional values. Therefore, API interface configuration information is obtained as the data basis for building a knowledge graph.
[0132] After obtaining the API interface configuration information, the corresponding data can be extracted through the corresponding entity keyword extraction tool, association relationship extraction tool and attribute keyword extraction tool.
[0133] For example, through entity keyword extraction, entity keywords used to indicate entities related to the API interface are extracted from the API interface configuration information. Specifically, the entity is first extracted. The entity format is: <entity name, entity type>, and then the entity name is extracted as the corresponding entity keyword. Entities can include the following: business entities (format: <entity name, entity type>, for example: <alarm, Business>), API entities (format: <entity name, entity type>, for example:<http: / / ip / alarms / query,API> ), parameter entity (format: <entity name, entity type>, for example: <alarm name, Param>). When identifying the semantic tag corresponding to the entity keyword, the corresponding entity type can be extracted as the semantic tag of the corresponding entity keyword.
[0134] For example, through attribute keyword extraction, attribute keywords used to indicate entity attributes are extracted from the API interface configuration information. Specifically, attribute information such as parameter name, parameter value, parameter type, etc. are extracted from the attribute information related to the entity, and corresponding attribute keywords are extracted based on the corresponding attribute information. When identifying the semantic tags corresponding to the attribute keywords, the corresponding semantic tag identification tool can be used to extract the semantic tags of the corresponding attribute keywords.
[0135] For example, through the relationship extraction tool, the relationship information used to describe the relationship between entities related to the API interface and the relationship between entity attributes and entities is extracted, such as the relationship between the alarm entity and the API entity.
[0136] After completing the above extraction, based on the relationship information, the association between entity keywords and between attribute keywords and corresponding entity keywords is established, and the semantic tags are associated with the corresponding keywords to obtain a knowledge graph.
[0137] Furthermore, an embodiment of the present application also provides an API interface calling device, such as Figure 4 As shown, the API interface calling device includes:
[0138] An acquisition module 21 is used to acquire a natural language text, where the natural language text is used to describe the call requirements for the API interface in the software product;
[0139] A generating module 22 is used to perform preset processing on the natural language text obtained by the obtaining module 21 to generate an API calling instruction that meets the calling requirements;
[0140] The calling module 23 is used to call the corresponding API interface based on the API calling instruction generated by the generating module 22.
[0141] The API interface calling device provided in the embodiment of the present application realizes API interface calling through natural language text, specifically, obtains natural language text for describing the calling requirements of the API interface in the software product, then performs preset processing on the natural language text, generates API calling instructions that meet the calling requirements, and calls the corresponding API interface based on the generated API calling instructions. It can be seen that the scheme provided in the embodiment of the present application uses natural language to interact with the software product. After expressing the calling requirements of the API interface in the software product through natural language text, the natural language text can be processed to obtain the API calling instructions that meet the calling requirements, and the corresponding API interface in the software product can be called based on the API calling instructions. In this way, the user does not need to deeply study and understand the corresponding functions and calling logic of the API interface, and can realize the calling of the API interface in the software product through natural language, thereby improving the ease of use of the API interface of the software product.
[0142] In some embodiments of the present application, Figure 5 As shown, the generating module 22 includes:
[0143] An acquisition unit 221 is used to acquire a knowledge graph of the software product, wherein the knowledge graph contains knowledge data required to generate an API call instruction;
[0144] A processing unit 222 is used to perform pattern linking between the natural language text and the knowledge graph acquired by the acquisition unit 221 to obtain target knowledge data related to the natural language text;
[0145] The generating unit 223 is used to generate an API calling instruction that meets the calling requirement based on the target knowledge data obtained by the processing unit 222.
[0146] In some embodiments of the present application, Figure 5 As shown, the knowledge data includes the association relationship between the keywords required to generate the API call instruction and the semantic tags corresponding to the keywords, and the semantic tags are used to indicate the semantics expressed by the corresponding keywords in the process of generating the API call instruction. Then, the processing unit 222 includes:
[0147] The word segmentation subunit 2221 is used to perform word segmentation processing on the natural language text to obtain the word segments included in the natural language text;
[0148] The matching subunit 2222 is used to match the word segmentation obtained by the word segmentation subunit 2221 with the knowledge graph to obtain the target semantic label corresponding to the word segmentation;
[0149] The first determination subunit 2223 is used to determine the word segmentation and the corresponding target semantic label as the target knowledge data related to the natural language text.
[0150] In some embodiments of the present application, Figure 5 As shown, the matching subunit 2222 is specifically used to determine the target keyword in the knowledge graph as the keyword to start the matching, and the target keyword is an entity keyword used to describe entities related to the API interface; match the segmented words whose target semantic tags are not determined in the natural language text with the keywords participating in the matching; if there is a segmented word whose target semantic tag is not determined and matches the keyword in the keywords participating in the matching, the semantic tag of the matched keyword is determined as the target semantic tag of the corresponding segmented word, and the keyword associated with the matched keyword is determined as the keyword participating in the matching, and the segmented word whose target semantic tag is still not determined is continued to be matched with the newly determined keyword participating in the matching; if there is a segmented word whose target semantic tag is not determined and does not match the keyword in the keywords participating in the matching, and there is a segmented word whose target semantic tag is not determined and matches the keyword in the keywords participating in the matching and the matched keyword does not have an associated keyword, or the segmented word whose target semantic tag is not determined does not match the keyword in the keywords participating in the matching, a prompt indicating that the target semantic tag determination failed is issued for the segmented word that did not match the keyword.
[0151] In some embodiments of the present application, Figure 5As shown, the matching subunit 2222 executes the step of matching the word segmentation of the undetermined target semantic tag in the natural language text with the keywords participating in the matching, specifically including: determining whether the word segmentation of the undetermined target semantic tag is contained in the keywords participating in the matching; if contained, determining that the word segmentation of the corresponding undetermined target semantic tag matches the keyword in the keywords participating in the matching; if not contained, determining that the word segmentation of the corresponding undetermined target semantic tag does not match the keyword in the keywords participating in the matching.
[0152] In some embodiments of the present application, Figure 5 As shown, the processing unit 222 also includes:
[0153] The first detection subunit 2224 is used to detect whether the word segment that does not match the keyword is of a specified data type before the matching subunit 2222 issues a prompt that the target semantic tag determination fails for the word segment that does not match the keyword; if so, determine the first semantic tag corresponding to the specified data type as the target semantic tag of the corresponding word segment.
[0154] In some embodiments of the present application, Figure 5 As shown, the first detection subunit 2224 is also used to determine the second semantic label as the target semantic label of the corresponding word segment if it is detected that the word segment that does not match the keyword is not of the specified data type, and the second semantic label is used to indicate that the semantics of the corresponding word segment is unknown.
[0155] In some embodiments of the present application, Figure 5 As shown, the processing unit 222 also includes:
[0156] The second detection subunit 2225 is used to detect whether the corresponding word is included in the word whose target semantic label has not yet been determined after the matching subunit 2222 determines the target semantic label of the corresponding word; if included, the corresponding word whose target semantic label has not yet been determined will be eliminated.
[0157] In some embodiments of the present application, Figure 5 As shown, the processing unit 222 also includes:
[0158] A second determining subunit 2226 is used to determine the number of word units, where the number of word units is used to indicate the number of adjacent word segments that need to be merged together, and the number of word units is an integer not less than 2 and not greater than the total number of word segments;
[0159] A merging subunit 2227 is used to merge adjacent word-unit-number segmentations into a new segmentation according to the order of appearance of each segmentation obtained by the segmentation subunit 2221 in the natural language text;
[0160] The adding subunit 2228 is used to add the merged new segmented words to the segmented words included in the natural language text.
[0161] In some embodiments of the present application, Figure 5 As shown, the merging subunit 2227 is specifically used to merge, for each word segment, the word segment and a target number of word segments that are located after the word segment and are continuously adjacent to the word segment into a new word segment based on the order of appearance of the word segment in the natural language text, where the target number is the value of the word unit number minus one.
[0162] In some embodiments of the present application, Figure 5 As shown, the processing unit 222 also includes:
[0163] The third detection subunit 2229 is used to perform word segmentation processing on the natural language text in the word segmentation subunit 2221, and after obtaining the word segments included in the natural language text, detect whether there are word segments with unknown semantics in the word segments included in the natural language text; if so, remove the corresponding word segments.
[0164] In some embodiments of the present application, Figure 5 As shown, the generating unit 223 includes:
[0165] The third determining subunit 2231 is used to determine the word embedding vector of each of the word segments and the semantic label embedding vector of the corresponding target semantic label;
[0166] An integration subunit 2232 is used to integrate the word embedding vector and the semantic label embedding vector corresponding to each word segment to obtain the description data corresponding to each word segment;
[0167] The generating subunit 2233 is used to adopt the API calling instruction generating model corresponding to the software product, process the description data, and obtain the API calling instruction that meets the calling requirement.
[0168] In some embodiments of the present application, Figure 5 As shown, the generating unit 223 also includes:
[0169] Adding subunit 2234 is used to determine the semantic information of each of the word segments in the natural language text, wherein the semantic information is used to indicate the semantic expression of the corresponding word segment to the calling requirement; determine the semantic embedding vector of the corresponding semantic information of each word segment; and add the semantic embedding vector to the description data of the corresponding word segment obtained by the integrating subunit 2232.
[0170] In some embodiments of the present application, Figure 5As shown, a subunit 2234 is added, which is specifically used to determine the position of each of the segmented words in the natural language text; based on the position, determine the semantic information of the corresponding segmented word;
[0171] and / or,
[0172] Adding subunit 2234 is specifically used to determine the sentence component corresponding to each of the segmented words in the natural language text; based on the sentence component, determine the semantic information of the corresponding segmented word.
[0173] In some embodiments of the present application, Figure 5 As shown, the API interface calling device also includes:
[0174] A construction module 24 is used to obtain API interface configuration information of the API interface included in the software product; extract keywords and association relationship information from the API interface configuration information, the keywords include entity keywords for describing API interface-related entities and attribute keywords for describing entity attributes, and the association relationship information includes keywords for describing association relationships between API interface-related entities and for describing association relationships between entity attributes and entities; perform semantic recognition on the extracted keywords to obtain semantic tags of the corresponding keywords; based on the relationship information, establish associations between entity keywords and between attribute keywords and corresponding entity keywords; associate semantic tags with corresponding keywords to obtain the knowledge graph.
[0175] In some embodiments of the present application, Figure 5 As shown, the API interface calling device also includes:
[0176] The completion module 25 is used to determine the completion data of the API call instruction corresponding to the software product after the generation module 22 generates the API call instruction that meets the call requirement; and use the completion data to complete the API call instruction.
[0177] In some embodiments of the present application, the completion data includes at least one of the following: a request header, a request method, and a request attribute.
[0178] In the API interface calling device provided in the embodiment of the present application, the detailed explanations used in the operation of each functional module can be found in the corresponding detailed explanations of the above-mentioned API interface calling method embodiment, which will not be repeated here.
[0179] Furthermore, an embodiment of the present application also provides a computer-readable storage medium, which includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the above-mentioned API interface calling method.
[0180] Furthermore, an embodiment of the present application also provides an electronic device, which includes: a memory for storing a program; and a processor, coupled to the memory, for running the program to execute the above-mentioned API interface calling method.
[0181] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0182] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.
[0183] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0184] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the application described herein, and the description of the above specific language is to disclose the preferred embodiment of the application.
[0185] In addition, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0186] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0187] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data cutover device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data cutover device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0188] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data switching device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0189] These computer program instructions can also be loaded onto a computer or other programmable data transfer device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0190] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0191] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0192] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0193] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0194] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0195] The above are only embodiments of the present application and are 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 within the scope of the claims of the present application.
Claims
1. An API interface calling method, characterized in that: The method comprises: Obtaining a natural language text, where the natural language text is used to describe a call requirement for an API interface in a software product; Performing preset processing on the natural language text to generate an API call instruction that meets the call requirement; Based on the API calling instruction, the corresponding API interface is called.
2. The method according to claim 1, characterized in that: The natural language text is processed in a preset manner to generate an API call instruction that meets the call requirement, including: Obtaining a knowledge graph of the software product, wherein the knowledge graph contains knowledge data required to generate an API call instruction; Performing pattern linking between the natural language text and the knowledge graph to obtain target knowledge data related to the natural language text; Based on the target knowledge data, an API calling instruction that meets the calling requirement is generated.
3. The method according to claim 2, characterized in that The knowledge data includes the association relationship between the keywords required to generate the API call instruction and the semantic tags corresponding to the keywords, and the semantic tags are used to indicate the semantics expressed by the corresponding keywords in the process of generating the API call instruction. Then, the natural language text is pattern-linked with the knowledge graph to obtain the target knowledge data related to the natural language text, including: Performing word segmentation processing on the natural language text to obtain word segments included in the natural language text; Matching the word segmentation with the knowledge graph to obtain a target semantic label corresponding to the word segmentation; The word segments and corresponding target semantic labels are determined as target knowledge data related to the natural language text.
4. The method according to claim 3, characterized in that: Matching the word segmentation with the knowledge graph to obtain a target semantic label corresponding to the word segmentation includes: Determine the target keyword in the knowledge graph as the keyword to start matching, wherein the target keyword is an entity keyword used to describe an entity related to the API interface; Matching the segmented words without a determined target semantic label in the natural language text with the keywords involved in the matching; If there is a word segmentation whose target semantic label has not been determined and matches a keyword among the keywords participating in the matching, the semantic label of the matched keyword is determined as the target semantic label of the corresponding word segmentation, and the keyword associated with the matched keyword is determined as the keyword participating in the matching, and the word segmentation whose target semantic label has not yet been determined is continued to be matched with the newly determined keyword participating in the matching; If there is a segmentation with an undetermined target semantic label that does not match any keyword among the keywords participating in the matching, or there is a segmentation with an undetermined target semantic label that matches any keyword among the keywords participating in the matching and the matched keyword does not have any associated keyword, or there is a segmentation with an undetermined target semantic label that does not match any keyword among the keywords participating in the matching, a prompt indicating that the target semantic label determination failed is issued for the segmentation that did not match any keyword.
5. The method according to claim 4, characterized in that Matching the segmented words without a determined target semantic label in the natural language text with the keywords involved in the matching, including: Determine whether the word segmentation of the undetermined target semantic label is included in the keywords involved in the matching; If it is included, it is determined that the word segmentation of the corresponding undetermined target semantic label matches the keyword among the keywords participating in the matching; If not, it is determined that the word segmentation of the corresponding undetermined target semantic tag does not match the keyword among the keywords participating in the matching.
6. The method according to claim 4, characterized in that Before issuing a prompt indicating a failure in determining a target semantic tag for a word segment that is not matched with a keyword, the method further includes: Check whether the word segmentation that does not match the keyword is of the specified data type; If so, the first semantic label corresponding to the specified data type is determined as the target semantic label of the corresponding word segmentation.
7. The method according to claim 6, characterized in that The method further comprises: If it is detected that the word segment that does not match the keyword is not of the specified data type, a second semantic tag is determined as the target semantic tag of the corresponding word segment, and the second semantic tag is used to indicate that the semantics of the corresponding word segment is unknown.
8. The method according to claim 4, characterized in that The method further comprises: After determining the target semantic label of the corresponding word, detecting whether the corresponding word is included in the word whose target semantic label has not yet been determined; If included, the corresponding word segmentation whose target semantic label has not yet been determined will be removed.
9. The method according to claim 3, characterized in that: After performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text, the method further includes: Determine the number of word units, where the number of word units is used to indicate the number of adjacent word segments that need to be merged together, and the number of word units is an integer not less than 2 and not greater than the total number of word segments; According to the order of appearance of each segmentation in the natural language text, the adjacent segmentations of the number of word units are merged into a new segmentation; The merged new word segmentation is added to the word segmentation included in the natural language text.
10. The method according to claim 9, characterized in that According to the order in which each segmentation word appears in the natural language text, the adjacent segmentations of the number of word units are merged into a new segmentation word, including: For each word segment, based on the order of appearance of the word segment in the natural language text, the word segment and a target number of word segments that are located after the word segment and are continuously adjacent to the word segment are merged into a new word segment, where the target number is the value of the word unit number minus one.
11. The method according to claim 3, characterized in that After performing word segmentation processing on the natural language text to obtain the word segments included in the natural language text, the method further includes: Detecting whether there are semantically unknown segmentations among the segmentations included in the natural language text; If it exists, the corresponding word will be removed.
12. The method according to claim 3, characterized in that Based on the target knowledge data, an API call instruction that meets the call requirement is generated, including: Determine a word embedding vector for each of the word segments and a semantic label embedding vector for the corresponding target semantic label; Integrate the word embedding vector and semantic label embedding vector corresponding to each word segment to obtain the corresponding description data of each word segment; The API calling instruction generation model corresponding to the software product is adopted to process the description data to obtain the API calling instruction that meets the calling requirement.
13. The method according to claim 12, characterized in that The method further comprises: Determine semantic information of each of the segmented words in the natural language text, wherein the semantic information is used to indicate the semantic expression of the corresponding segmented word to the call requirement; Determine a semantic embedding vector of the semantic information corresponding to each of the word segments; Add the semantic embedding vector to the description data of the corresponding word segment.
14. The method according to claim 13, characterized in that Determining the semantic information of each of the word segments in the natural language text includes: Determine the position of each of the word segments in the natural language text; Based on the position, determining semantic information of the corresponding word segment; and / or, Determine the sentence component corresponding to each of the participles in the natural language text; Based on the sentence components, semantic information of corresponding word segments is determined.
15. The method according to any one of claims 3 to 14, characterized in that: The method further comprises: Acquire API interface configuration information of the API interface included in the software product; Extracting keywords and association relationship information from the API interface configuration information, wherein the keywords include entity keywords for describing entities related to the API interface and attribute keywords for describing entity attributes, and the association relationship information includes keywords for describing association relationships between entities related to the API interface and keywords for describing association relationships between entity attributes and entities; Perform semantic recognition on the extracted keywords to obtain semantic tags of the corresponding keywords; Based on the relationship information, establishing associations between entity keywords and between attribute keywords and corresponding entity keywords; The semantic tags are associated with corresponding keywords to obtain the knowledge graph.
16. The method according to any one of claims 1 to 14, characterized in that After generating an API call instruction that meets the call requirement, the method further includes: Determine the completion data of the API call instruction corresponding to the software product; The API call instruction is completed using the completion data.
17. The method according to claim 16, characterized in that The completion data includes at least one of the following: a request header, a request method, and a request attribute.
18. An API interface calling device, characterized in that: The device comprises: An acquisition module is used to acquire natural language text, where the natural language text is used to describe the call requirements for the API interface in the software product; A generation module, used to perform preset processing on the natural language text to generate an API call instruction that meets the call requirement; The calling module is used to call the corresponding API interface based on the API calling instruction.
19. A computer-readable storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the API interface calling method described in any one of claims 1 to claim 17.
20. An electronic device, characterized in that: The electronic device comprises: Memory, used to store programs; A processor, coupled to the memory, is used to run the program to execute the API interface calling method described in any one of claims 1 to claim 17.
