API matching model establishment method and cross-city government API matching method
The API matching model built through machine learning utilizes semantic similarity to construct similarity vectors and employs the XGBoost model, which solves the problem of low API matching accuracy in existing technologies and achieves efficient and automated cross-city API matching.
Patent Information
- Application Number
- CN202011558922.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-25
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-12-25
AI Technical Summary
The existing API matching method has too low an accuracy rate, resulting in high cost and low efficiency when developing cross-city applications, and it relies heavily on manual intervention.
An API matching model is built using machine learning methods. By calculating the semantic similarity of API description text, a similarity vector is constructed and trained using an XGBoost model to automatically match APIs.
It improved the accuracy and efficiency of API matching, achieved highly automated cross-city API matching, reduced manual costs, and improved the efficiency of application development.
Smart Images

Figure CN112650833B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to a method for establishing an API matching model and a method for matching cross-city government APIs. Background Art
[0002] In recent years, local governments in China have launched government data open platforms, which have led to many applications based on government open data. However, since there is no unified standard between the APIs provided by the open data platforms of various governments, it is difficult for developers to find the same APIs between different cities. They need to search and filter manually, which is inefficient and prone to errors. This results in higher development costs when developing cross-city applications and higher migration costs when migrating applications between cities.
[0003] At present, in addition to the manual search and matching methods, some people also use string matching to find the same APIs between different cities, such as the longest common string or calculating the edit distance. Based on the description text of the API, the string similarity between the API to be matched and all APIs in the target city is calculated one by one. Then, based on the similarity calculation results, several APIs with the highest similarity are selected and returned to the user. However, due to the richness of Chinese expressions and the inconsistency between the names of various government APIs, the accuracy of string matching is low. At the same time, this method does not minimize manual participation and only achieves semi-automatic matching. Summary of the invention
[0004] The problem solved by the present invention is that the matching accuracy of the existing API matching method is too low.
[0005] In order to solve the above problems, the present invention provides a method for establishing an API matching model and a method for matching cross-city government affairs APIs.
[0006] The present invention provides a method for establishing an API matching model, comprising:
[0007] Acquire a training sample, wherein one training sample includes description texts of two APIs, and the description text of each API consists of at least one short text;
[0008] Calculating the semantic similarity between the short texts of the two APIs in each of the training samples;
[0009] Constructing a similarity vector corresponding to each training sample according to the semantic similarity between the short texts of the two APIs in each training sample;
[0010] The similarity vector is input into a preset model for training until the loss function of the preset model converges, and the preset model with converged loss function is used as the API matching model.
[0011] Optionally, the description text includes a name short text, a keyword short text and at least one return parameter name short text;
[0012] The calculating of the semantic similarity between the short texts of the two APIs in each training sample comprises:
[0013] Arrange and combine the short texts of the return parameter names of the two APIs in each of the training samples to obtain multiple short text pairs of the return parameter names;
[0014] Calculate the similarity of all the return parameter name short text pairs;
[0015] Calculate the similarity between the short texts of two API names and the short texts of keywords.
[0016] Optionally, constructing a similarity vector corresponding to each training sample according to the semantic similarity between the short texts of two APIs in each training sample includes:
[0017] From the similarities of all the returned parameter name short text pairs, select the similarities of a preset number of pairs with the largest similarities, where the preset number is recorded as N;
[0018] The preset number of similarities are combined with the similarity of the name short text, the similarity of the keyword short text, and the training sample label to form a 1×M-dimensional similarity vector, where M=N+3.
[0019] Optionally, the API matching model is an XGBoost model.
[0020] Optionally, the calculating the semantic similarity between the short texts of the two APIs in each of the training samples includes:
[0021] The Jieba word segmentation algorithm is used to segment the short texts of the two APIs to obtain the word set after word segmentation.
[0022] Using the FastText algorithm to map each word in the word set into a vector;
[0023] Calculate the TextRank value of each word in the word set;
[0024] According to the vector and TextRank value of each word in the word set, the sentence vector of each short text of the two APIs is obtained;
[0025] The semantic similarity between the sentence vectors of the short texts of the two APIs is calculated, where the semantic similarity between the sentence vectors of the short texts of the two APIs is the semantic similarity between the short texts of the two APIs.
[0026] The present invention also provides an API matching method, comprising:
[0027] Obtain description texts of two APIs to be matched, wherein the description text of each API consists of at least one short text;
[0028] Calculate the semantic similarity between the short texts of the two APIs to be matched;
[0029] Determine the similarity vectors corresponding to the two APIs to be matched according to the semantic similarity between the short texts of the two APIs to be matched;
[0030] The similarity vectors corresponding to the two APIs to be matched are input into the API matching model, and the output result of the API matching model is the matching result of the two APIs to be matched, wherein the API matching model is generated based on the API matching model establishment method as described in any of the above items.
[0031] Optionally, after obtaining the description texts of the two APIs to be matched and before calculating the semantic similarity between the short texts of the two APIs to be matched, the method further includes:
[0032] Identify whether the description text of each API contains a short text of a geographic location qualifier;
[0033] When the description text of any API contains a short text of a geographic location qualifier, the short text of the geographic location qualifier is removed.
[0034] The present invention also provides a cross-city government affairs API matching method, comprising:
[0035] Receiving a cross-city government affairs API matching query request, and obtaining a query API and a query scope based on the cross-city government affairs API matching query request;
[0036] Traversing the preset government affairs API database, respectively forming an API pair to be matched with the query API and each API within the query range in the preset government affairs API database, and determining whether the API pair to be matched matches based on the API matching method described above;
[0037] Output all APIs in the preset government affairs API database that match the query API within the query scope.
[0038] The present invention provides an electronic device, comprising a memory and a processor; the memory is used to store a computer program; the processor is used to implement the API matching model establishment method as described above, the API matching method as described above, or the cross-city government affairs API matching method as described above when executing the computer program.
[0039] The present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the API matching model establishment method as described above or the API matching method as described above or the cross-city government affairs API matching method as described above are implemented.
[0040] The beneficial effects of the API matching model establishment method and the cross-city government affairs API matching method of the present invention are: by using machine learning methods to perform automated API matching, the cost problem of manual matching is solved. At the same time, in terms of feature extraction, the API description text similarity is used as a feature to convert the API description information into a similarity vector, which effectively improves the matching accuracy and ultimately achieves a high-accuracy, high-efficiency, and highly automated API matching solution. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 A schematic diagram of a flow chart of an embodiment of a method for establishing an API matching model according to the present invention;
[0042] Figure 2 A schematic diagram of a flow chart of another embodiment of the method for establishing an API matching model of the present invention;
[0043] Figure 3 A flowchart of another embodiment of the method for establishing an API matching model of the present invention;
[0044] Figure 4 A schematic diagram of the process of constructing a similarity vector from an API pair;
[0045] Figure 5 This is a flow chart of an embodiment of an API matching method of the present invention;
[0046] Figure 6 This is a flow chart of an embodiment of an API matching method of the present invention;
[0047] Figure 7 This is a schematic diagram of an implementation example of an API cross-city matching system;
[0048] Figure 8 This is a schematic diagram of another embodiment of the API cross-city matching system. DETAILED DESCRIPTION
[0049] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0050] Obviously, the described embodiments are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0051] According to the "China Local Data Openness Report", as of the first half of 2019, China has 82 government data open platforms, opening 62,801 data sets. This is a nearly seven-fold increase compared to 2017. At the same time, more and more open platforms provide callable APIs for data sets, allowing developers to integrate APIs into city service applications and obtain the latest data in real time. However, the problem is that there is no unified standard for defining APIs on various government open data platforms, which has created obstacles for developers to use the same type of APIs. When a city service application needs to integrate APIs from multiple cities, or an application is migrated from one city to another, developers need to find the same type of API from different open platforms. We call this work cross-city matching of APIs. The irregularity of API naming and the diversity of Chinese expressions have brought challenges to cross-city matching, which in turn has led to difficulties in application migration. Applications that have been successfully migrated from other cities are one of the most economical and efficient ways for a city to expand its city service system. Therefore, the problem of API cross-city matching needs to be solved urgently.
[0052] The present disclosure provides a method for establishing an API matching model, which can be executed by a processor in an electronic device, where the electronic device can be implemented as a smart phone, a tablet computer, a computer device, a computer device as a server, etc. Figure 1 As shown, it is a flow chart of a method for establishing an API matching model according to an embodiment of the present invention; wherein the method for establishing an API matching model includes:
[0053] Step S10, obtaining a training sample, wherein one training sample includes description texts of two APIs, and the description text of each API consists of at least one short text.
[0054] The description text of the API includes at least one short text, for example: the description text includes one or more of the API name, API keywords, and API return parameter names, wherein, since there may be multiple API return parameter names, the API return parameter name short text may be one or more. For cross-city API matching, the description text also includes geographic location qualifiers such as the city or region to which the API belongs, but when constructing training samples, the geographic location qualifiers can be automatically identified and removed to improve the matching accuracy of the trained model. As the open data platform becomes more and more perfect, the description text of the API may contain more short texts, and the types of short texts may also be different. For the situation where the description text contains changes in short texts, it can also be applied to the embodiments of the present disclosure and is included in the protection scope of the present invention.
[0055] The training samples are labeled samples, that is, labels that identify whether the training samples are positive samples or negative samples.
[0056] Step S20, calculating the semantic similarity between the short texts of the two APIs in each of the training samples.
[0057] The semantic similarity between the short texts of two APIs refers to the semantic similarity of the same type of short texts of the two APIs. For example, an API contains three short texts including the API name, API keywords and API return parameter name. The semantic similarity between the short texts of the two APIs refers to: the semantic similarity between the name of one API and the name of another API, the semantic similarity between the keywords of one API and the keywords of another API, and the semantic similarity between the return parameter name of one API and the return parameter name of another API.
[0058] It should be noted that, since the present invention is applied to the matching of cross-city government APIs, and due to the limitations of the government data platform, only API keywords, API names, and API return parameter names can be obtained. These keywords, nouns, and return parameter names are all short texts, and there are different words in each short text. Some words are very universal and cannot well reflect the current short text. Therefore, this method uses semantic similarity as the short text similarity, weakens meaningless words in the text, and reduces the interference caused by different synonyms in Chinese, so as to more accurately characterize the similarity of the corresponding short texts between the two APIs and greatly improve the accuracy of API matching.
[0059] Step S30: construct a similarity vector corresponding to each training sample according to the semantic similarity between the short texts of the two APIs in each training sample.
[0060] For a training sample, after calculating the semantic similarity between the short texts of the two APIs contained therein, multiple semantic similarities are obtained. At this time, the number of semantic similarities obtained is greater than or equal to the number of short texts contained in the API description text.
[0061] To facilitate subsequent model training and simplify the data format of model input, a similarity vector is obtained by integrating the semantic similarity between the short texts of the two APIs. That is, each training sample corresponds to a similarity vector. In subsequent model training, the similarity vector corresponding to each training sample is input into the model to represent the corresponding training sample.
[0062] According to the semantic similarity between the short texts of the two APIs in each of the training samples, a similarity vector corresponding to each of the training samples is constructed. In one embodiment, it specifically includes: combining the semantic similarities between all the short texts of the two APIs to form a similarity vector. In another embodiment, it specifically includes: taking multiple similarities from the semantic similarities between the short texts of the two APIs, and integrating the similarities into a similarity vector. In yet another embodiment, it specifically includes: assigning a weight to each short text, calculating the final similarity of each short text based on the similarity and weight corresponding to each short text, and combining the final similarities of each short text to form a similarity vector. By converting the description text of the API into a similarity vector, the model training speed and prediction speed are effectively improved, and the API matching accuracy and matching efficiency are also effectively improved.
[0063] Step S40: input the similarity vector into a preset model for training until the loss function of the preset model converges, and use the preset model with converged loss function as the API matching model.
[0064] The preset model is an initialized machine learning model. The API matching model trained based on the preset model ultimately achieves automatic binary classification, and the output result is that the two APIs "match" or "do not match". The preset model / API matching model can be a LightGBM model, which is a Gradient Boosting Decision Tree (GBDT). Its related principles belong to the existing technology and are not described here.
[0065] Optionally, the preset model / API matching model is an XGBoost model. Compared with traditional machine learning classification algorithms, such as logistic regression, support vector machines, etc., XGBoost can automatically handle missing values. In terms of overfitting, traditional machine learning methods usually do not have the ability to prevent overfitting, and have high requirements for the number, purity, feature dimensions, model complexity, etc. of training data. XGBoost uses regularization to prevent overfitting, which reduces the requirements in these aspects. It can be seen that using the XGBoost model for API matching can achieve better matching results with higher accuracy.
[0066] The loss function of the preset model can be the logarithmic loss function logloss or other custom loss functions.
[0067] The existing technology has the disadvantages of low API matching accuracy, high labor cost, low efficiency, etc., and cannot be widely used in actual production. In view of the above shortcomings, the present invention uses machine learning methods to perform automated API matching, which solves the cost problem of manual matching. At the same time, in terms of feature extraction, the similarity of each short text of the API description text is used as a feature. Since the semantic similarity between each short text of the API is strongly correlated with whether the API matches, the description text of the API is converted into a similarity vector constructed based on the semantic similarity between each short text of the API, which effectively improves the matching accuracy and finally realizes a high-accuracy, high-efficiency, and highly automated API matching solution.
[0068] The present invention uses semantic similarity as the semantic similarity between the short texts of two APIs, and uses a machine learning algorithm to train an automatic API matching model to solve the API matching problem. This can realize automated API matching, save costs and improve efficiency, and can solve the problems of low accuracy, poor practical application effects, and still requiring a large reliance on manual labor in existing methods. For cross-city API matching, it can help the development of various applications based on government open data and accelerate the implementation of smart cities.
[0069] Optionally, the description text includes a name short text, a keyword short text and at least one return parameter name short text; Figure 2 , the step S20 comprises:
[0070] Step S201, arranging and combining the short texts of the return parameter names of the two APIs in each of the training samples to obtain a plurality of short text pairs of the return parameter names.
[0071] The number and order of return parameter names of different APIs may be different. Therefore, the return parameter names of the two APIs are arranged and combined, and the similarity of each return parameter name short text pair formed by the arrangement and combination is calculated respectively to accurately calculate the similarity of the return parameter name short text. At the same time, because the return parameter name short text may contain multiple return parameter names, when calculating the semantic similarity, the semantic similarity between the two return parameter names from the two APIs is calculated, so the return parameter name short text may contain multiple similarities.
[0072] Step S202, calculating the similarity of all the returned parameter name short text pairs.
[0073] For two APIs with identical or highly similar return parameter names, even if the number and arrangement order of the two API return parameter names are different, after calculating the similarity through permutations and combinations, the identical or highly similar return parameter names of the two APIs can be determined based on the similarity. The similarity of the short text pairs of the return parameter names with the maximum preset number of similarities can be taken, which can solve the problem of misjudgment caused by the different number and arrangement order of the return parameter names, and can further improve the matching accuracy.
[0074] For two APIs that do not have the same or highly similar return parameter names, taking the similarity of the preset number of similarities with the largest similarity as the similarity of the short texts of the two API return parameter names can also better characterize the similarity of the short texts of the two API return parameter names.
[0075] Step S203, calculating the similarity between the two API name short texts and the similarity between the keyword short texts.
[0076] The order of calculating the similarity of the name short text, keyword short text, and the returned parameter name short text is not limited here. The calculation of the similarity of the name short text and keyword short text can be performed before, after, or at the same time as the calculation of the similarity of the returned parameter name short text. The order of calculating the similarity of the name short text and the keyword short text is also not limited.
[0077] When the description text contains a short name text, a short keyword text, and a short return parameter name text, the similarity of each short text is calculated separately to obtain the similarity of each short text and a similarity set, so that a similarity vector can be generated based on the similarity set in subsequent steps to comprehensively characterize the similarity between the two API description texts, thereby ensuring the accuracy of feature construction and improving the accuracy of model training and prediction accuracy.
[0078] Optionally, the step S30 includes: selecting a preset number of similarities with the largest similarities from the similarities of all the returned parameter name short text pairs, where the preset number is denoted as N; combining the preset number of similarities with the similarity of the name short text, the similarity of the keyword short text, and the training sample label to form a 1×M-dimensional similarity vector, where M=N+3.
[0079] Because the number of return parameter name short text pairs obtained after permutation and combination may be large, and the similarity of the return parameter name short text pairs with the maximum preset number of similarities can more accurately characterize the similarity of the two API return parameter name short texts, so by limiting the number of similarities that ultimately represent the similarity of the two API return parameter name short texts, it can avoid the similarity vector that is finally input into the preset model for training from being too large, ensuring training efficiency and prediction efficiency, and through the construction of the similarity vector, taking into account both the accuracy and efficiency of model training.
[0080] When the number of similarities of all returned parameter name short text pairs is greater than the preset number, the preset number of similarities with the largest similarity is taken as the similarity of the two API return parameter name short texts, and the excess similarities are discarded; when the number of similarities of all returned parameter name short text pairs is less than the preset number, the similarities of all returned parameter name short text pairs are taken as the similarity of the two API return parameter name short texts, and at the same time, one or more similarities are added, and the sum of the newly added similarities and the number of similarities of all returned parameter name short text pairs is equal to the preset number, where the newly added similarities are filled with 0. The preset number can be selected from 6 to 10.
[0081] The similarity vector also includes a training sample label. The training sample label is used to identify whether the training sample is a positive sample or a negative sample. A positive sample refers to two APIs that are matching APIs of the same type, and a negative sample refers to two APIs that are not matching APIs of different types.
[0082] The training sample labels can be expressed in the similarity vector in the form of 1 or 0. The positive sample can be marked as 1 and the negative sample can be marked as 0. Of course, it can also be the other way around, the positive sample can be marked as 0 and the negative sample can be marked as 1.
[0083] The training sample label can be set at the beginning or end of the similarity vector to facilitate model acquisition. The formed similarity vector is a vector containing the similarities of the short texts of the two APIs and the training sample label.
[0084] like Figure 4 The figure shows a schematic diagram of the process of constructing a similarity vector from an API pair. Figure 4In the API-A shown, the description text includes 1 name of A, 1 keyword of A and a short text LA of return parameter name including 6 return parameter names. In the API-B, the description text includes 1 name of B, 1 keyword of B and a short text LB of return parameter name including 5 return parameter names. At the same time, Figure 4 The API pair shown also includes a label indicating whether A matches B.
[0085] Calculate the similarity of each short text, that is, calculate the similarity between the name of A and the name of B, calculate the similarity between the keywords of A and the keywords of B, and then arrange and combine the 6 return parameter names of LA and the 5 return parameter name short texts of LB to calculate the similarity of the return parameter name short text pairs. A total of 30 similarities are obtained under the return parameter name short texts. The 30 similarities are sorted by size, and the largest preset number of similarities is selected from them as the final return parameter name short text similarity, which is used in the subsequent feature vector (i.e., the similarity vector mentioned above) construction;
[0086] The similarity of the name short text, the similarity of the keyword short text and the final return parameter name short text similarity are combined with the label to construct a feature vector, which is used to train the machine learning model (i.e., the preset model or API matching model referred to above).
[0087] from Figure 4 It can be seen that the final feature vector constructed is a 1×M-dimensional vector, where the dimensions are: 1 (name similarity) + 1 (keyword similarity) + N (return parameter name similarity) + 1 (label).
[0088] In other schemes that use vectors as model input, word vectors trained by the word2vec model are often used as model input. One of the characteristics of traditional word vectors generated by the word2vec model is that the dimension is large, usually more than 1×200 dimensions. The present invention proposes a self-developed vector construction method, which combines the similarity of each short text of two APIs and the training sample labels to form a similarity vector, and uses the similarity vector as a model input for training. The vector constructed based on this vector construction scheme of the present invention can better characterize the API features because the similarity of each short text is strongly related to whether the API matches. The prediction results of the model trained based on this are also more accurate. At the same time, because the number of short texts contained in the API description text is usually low, the number of similarities obtained is also low, so the final vector dimension is also low, that is, compared with the word vector generated by the word2vec model, the vector dimension is reduced, thereby improving the model training speed and prediction speed.
[0089] Alternatively, if Figure 3 , the step S20 comprises:
[0090] Step S211, using Jieba word segmentation algorithm to perform word segmentation processing on each short text of the two APIs respectively, to obtain a word set after word segmentation processing.
[0091] Jieba word segmentation algorithm uses a prefix dictionary to achieve efficient word graph scanning, generates a directed acyclic graph consisting of all possible word generation situations of Chinese characters in a sentence, and then uses dynamic programming to find the maximum probability path and find the maximum segmentation combination based on word frequency. For unregistered words, the HMM model based on the word-forming ability of Chinese characters is used, and the Viterbi algorithm is used. Jieba word segmentation algorithm is an existing open source Chinese word segmentation algorithm and will not be described here.
[0092] The short texts of the two APIs are segmented by Jieba word segmentation algorithm to obtain the word sets corresponding to the short texts. For example, the keywords are segmented to obtain the word sets corresponding to the keyword short texts, and the names are segmented to obtain the word sets corresponding to the name short texts.
[0093] Step S212, using the FastText algorithm to map each word in the word set into a vector.
[0094] FastText is a fast text classification algorithm. Compared with other text classification models such as support vector machines, logistic regression models, and neural networks, FastText greatly shortens the training time while maintaining the classification effect. At the same time, FastText does not require pre-trained word vectors. FastText will train word vectors by itself, which facilitates the training of the XGBoost model.
[0095] Step S213, calculating the TextRank value of each word in the word set.
[0096] Step S213 specifically includes: (1) performing part-of-speech tagging on the words after word segmentation of each short text in the API, and filtering out stop words, and only retaining words with specified parts of speech, such as retaining nouns, verbs, and adjectives, that is, S i =[t i,1 ,t i,2 ,...,t i,n ], where S i Represents the short text of the API. i,n Represents the retained words. (2) Construct a candidate keyword graph G = (V, E), where V is a node set consisting of the candidate keywords generated by (1), and then use the co-occurrence relationship to construct an edge between any two nodes: an edge exists between two nodes only if their corresponding words co-occur in a window of length K, where K represents the window size, i.e., at most K words co-occur, and K is generally 2. (3) Then according to the formula:
[0097]
[0098] Iterate and propagate the weights of each node until convergence. In(Vi) represents the set of predecessor nodes of the node, Out(Vj) represents the set of successor nodes of node Vj, d is the damping coefficient, ω ji Used to indicate that the edge connection between two nodes has different importance.
[0099] According to the above formula, the TextRank value of each word can be obtained.
[0100] Step S214, obtaining the sentence vectors of the short texts of the two APIs according to the vectors and TextRank values of the words in the word set.
[0101] The execution order of step S212 and step S213 is not limited, and step S212 can be executed before step S213 or after step S213.
[0102] Each short text has its own corresponding word set. For a word set corresponding to a short text, take the inverse of the TextRank value of the words in the word set to get the weight of each word, multiply the vector of each word by the weight, and add the multiplied vectors to get the sentence vector of the short text.
[0103] Step S215 , calculating the semantic similarity between the sentence vectors of the short texts of the two APIs, where the semantic similarity between the sentence vectors of the short texts of the two APIs is the semantic similarity between the short texts of the two APIs.
[0104] The semantic similarity between sentence vectors can be calculated by cross-calculating the cosine similarity. The cosine formula is as follows:
[0105]
[0106] Among them, similarity refers to the similarity, V A 、V B is the sentence vector, A i and B i V A and V B Each dimension has a value, a total of k dimensions.
[0107] Since the name, keywords and return parameter name of the API are short texts composed of multiple words, there are different words in each short text, and some words are very universal and cannot reflect the current short text well. Therefore, the feature engineering independently developed by the present invention first performs word segmentation on each short text (i.e. each short text) of the API through Jieba word segmentation, and then uses the FastText algorithm to map each word after word segmentation into a vector, and calculates the weight of each word after word segmentation through the TextRank algorithm (the weight is the inverse of the TextRank value), and then multiplies the vector of each word by the weight, and adds the vector after multiplying the weight to obtain the vector of the short text, and then calculates the semantic similarity between the vectors of each short text, that is, obtains the semantic similarity between the short texts of the two APIs. The similarity thus obtained can accurately reflect the similarity between the short texts of the two APIs, provide accurate input data for subsequent model training, and is conducive to improving the accuracy of API matching model prediction.
[0108] Based on the semantic similarities between the short texts of the two APIs obtained in the above steps, a specified number of similarity values can be selected therefrom. For example, when the return parameter name short text contains multiple return parameter names, it has multiple return parameter names. The multiple return parameter names of the two APIs are arranged and combined to obtain return parameter name short text pairs. The similarity is calculated for each return parameter name short text pair according to the above steps S211-S215 to obtain multiple similarities, from which a preset number of similarities are selected as the final return parameter name short text similarity. The name short text and keyword short text are also calculated using steps S211-S215 to calculate the similarity. All the similarities finally obtained constitute a vector, that is, a similarity vector, which is input into the machine learning model for training, thereby greatly reducing the training time of the machine learning model and obtaining more accurate prediction results.
[0109] The present disclosure provides an API matching method. The method can be executed by a processor in an electronic device, where the electronic device refers to a computer, a server, etc. Figure 5 As shown, it is a flowchart of an API matching method according to an embodiment of the present disclosure, and the API matching method includes:
[0110] Step S50, obtaining description texts of two APIs to be matched, wherein the description text of each API consists of at least one short text.
[0111] The short text may be one or more of an API name, an API keyword, and an API return parameter name, wherein the API return parameter name short text may contain one or more return parameter names, that is, the API return parameter name contains the names of each API return parameter name.
[0112] For cross-city API matching, its description text also includes geographic location qualifiers such as the city or region to which the API belongs. Therefore, before the two APIs to be matched are matched, the geographic location qualifiers in the API description text are automatically identified and removed. The description texts of the two APIs after the geographic location qualifiers are removed are then subsequently processed to improve the accuracy of model prediction. As the open data platform becomes more and more complete, the description text of the API may contain more short texts, and the types of short texts may also be different. For such a situation where the description text contains changes in short texts, it can also be applied to the embodiments of the present disclosure and is included in the protection scope of the present invention.
[0113] Step S60: Calculate the semantic similarity between the short texts of the two APIs to be matched.
[0114] The semantic similarity between the short texts of two APIs refers to the similarity of the same short texts of the two APIs. For example, an API contains three short texts including the API name, API keywords and API return parameter name. The semantic similarity between the short texts of the two APIs refers to: the similarity between the name of one API and the name of another API, the similarity between the keywords of one API and the keywords of another API, and the similarity between the return parameter name of one API and the return parameter name of another API.
[0115] The specific method for calculating the semantic similarity between the short texts of the two APIs may be consistent with the method for calculating the similarity of the training samples during the API matching model training. A variety of implementation examples are given above for calculating the similarity of the training samples. These various implementation examples may all be applied to the calculation of the semantic similarity between the short texts of the two APIs in this embodiment, and will not be described in detail here.
[0116] Step S70: determining the similarity vectors corresponding to the two APIs to be matched according to the semantic similarity between the short texts of the two APIs to be matched.
[0117] The semantic similarities between the short texts of the two APIs to be matched are combined to form a similarity vector, and this similarity vector is the similarity vector corresponding to the two APIs to be matched.
[0118] In the embodiment of the present disclosure, the specific method of determining the similarity vectors corresponding to the two APIs based on the semantic similarity between the short texts of the two APIs is described in the relevant content of step S30 in the above API matching model establishment method. The basic content is the same and will not be repeated here.
[0119] Step S80, inputting the similarity vectors corresponding to the two APIs to be matched into the API matching model, the output result of the API matching model is the matching result of the two APIs to be matched, wherein the API matching model is generated based on the API matching model establishment method as described in any of the above items.
[0120] The similarity vectors corresponding to the two APIs to be matched are used as feature data of the two APIs and input into the API matching model, and the API matching model outputs the result of whether the two APIs match.
[0121] The above API matching model can be selected as XGBoost model or LightGBM model.
[0122] By using machine learning methods to perform automated API matching, the cost issue of manual matching is solved. At the same time, in terms of feature extraction, the API description text similarity is used as a feature to convert the API description information into a similarity vector, which effectively improves the matching accuracy and ultimately achieves a highly accurate, efficient, and highly automated API matching solution.
[0123] Optionally, after step S50 and before step S60, the method further includes: identifying whether the description text of each API contains a short text of a geographic location qualifier; when the description text of any API contains a short text of a geographic location qualifier, removing the short text of the geographic location qualifier.
[0124] Remove the short text of the geographic location qualifier, and use the remaining short text as the short text for calculating the similarity in step S60. For the specific application scenario of API cross-city matching, the short texts of the geographic location qualifiers of APIs in different cities must be very different. If they are included in the similarity calculation and the construction of the similarity vector, it may interfere with the matching result prediction of the API matching model, resulting in a decrease in the prediction accuracy of the API matching model. Therefore, by removing the short text of the geographic location qualifier, the prediction accuracy of the API matching model can be improved. Specifically, by presetting the geographic location qualifier vocabulary, the description text of each API can be matched one by one with the words in the geographic location qualifier vocabulary, and the one that successfully matches is the geographic location qualifier.
[0125] The disclosed embodiment provides a cross-city government API matching method. The method can be executed by a processor in an electronic device, where the electronic device refers to a computer, a server, etc. Figure 6 As shown, it is a flow chart of a cross-city government affairs API matching method according to an embodiment of the present disclosure, and the API matching method includes:
[0126] Step S90: receiving a cross-city government affairs API matching query request, and obtaining a query API and a query scope based on the cross-city government affairs API matching query request.
[0127] The cross-city government API matching query request includes relevant information of the query API to be queried, and may also include the query scope, for example, the geographical scope of the query.
[0128] Step S100, traverse the preset government API database, and form the query API and each API within the query range in the preset government API database into an API pair to be matched, and determine whether the API pair to be matched matches based on the API matching method described above (steps S50-S80).
[0129] The preset government API database stores known API data. For example, for a specific application scenario such as cross-city matching, the description texts of all APIs can be obtained from the data open platforms of various local governments.
[0130] When the API matching query request contains a query range, the query API is paired one by one with all APIs within the query range in the preset government affairs API database to form API pairs to be matched.
[0131] Step S110, outputting all APIs in the preset government affairs API database that are within the query scope and match the query API.
[0132] Based on step S100, all API pairs to be matched are judged in turn whether they match, and finally all APIs matching the query API in the preset government API database are output. When the API matching query request includes a query range, all APIs matching the query API refer to all APIs matching the query API within the query range.
[0133] Through the above steps, automated API matching can be achieved. You only need to enter the query conditions (including query API and query range) to return all matching APIs, which greatly improves the query efficiency and API matching efficiency. The above API matching method can also ensure matching accuracy.
[0134] The present disclosure provides an implementation method, Figure 7 and Figure 8The API cross-city matching system shown, the above-mentioned cross-city government API matching method can be applied to the API cross-city matching system. The API cross-city matching system includes an API matching model, a matching mining engine and a government API database. Among them, the API cross-city matching system receives known API information and stores it in the government API database by city classification; the API matching model is constructed by the API matching model establishment method as described above, and the matching judgment model receives a pair of API description texts, automatically determines whether the two APIs match and outputs the result. After receiving the API matching query request, the matching mining engine determines the query API and the query scope, and pairs the query API with all APIs within the query scope in the government API database one by one, and inputs the API matching model in sequence. The matching mining engine retrieves all matching APIs from the government API database based on the judgment results of the API matching model and returns them to the query interface.
[0135] Another embodiment of the present disclosure provides an electronic device including a memory and a processor; the memory is used to store a computer program; the processor is used to implement the API matching model establishment method as described above, the API matching method as described above, or the cross-city government affairs API matching method as described above when executing the computer program.
[0136] Another embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the API matching model establishment method as described above or the API matching method as described above or the cross-city government affairs API matching method as described above are implemented.
[0137] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. In the present application, the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present invention. In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0138] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A method for establishing an API matching model. It is characterized in that include: Acquire training samples, wherein one of the training samples includes description texts of two APIs, and the description text of each API is composed of at least one short text; the description text includes a name short text, a keyword short text, and at least one return parameter name short text; Calculating the semantic similarity between the short texts of the two APIs in each of the training samples, including: Arrange and combine the short texts of the return parameter names of the two APIs in each of the training samples to obtain multiple short text pairs of the return parameter names; Calculate the similarity of all the return parameter name short text pairs; Calculate the similarity between the short texts of two API names and the short texts of keywords; Constructing a similarity vector corresponding to each training sample according to the semantic similarity between the short texts of the two APIs in each training sample; The step of calculating the semantic similarity between the short texts of the two APIs in each training sample further includes: The Jieba word segmentation algorithm is used to segment the short texts of the two APIs to obtain the word set after word segmentation. Using the FastText algorithm to map each word in the word set into a vector; Calculate the TextRank value of each word in the word set; According to the vector and TextRank value of each word in the word set, the sentence vector of each short text of the two APIs is obtained; Calculate the semantic similarity between the sentence vectors of the short texts of the two APIs, where the semantic similarity between the sentence vectors of the short texts of the two APIs is the semantic similarity between the short texts of the two APIs; The similarity vector is input into a preset model for training until the loss function of the preset model converges, and the preset model with converged loss function is used as the API matching model.
2. The API matching model establishment method according to claim 1, It is characterized in that The constructing a similarity vector corresponding to each training sample according to the semantic similarity between the short texts of the two APIs in each training sample comprises: From the similarities of all the returned parameter name short text pairs, select the similarities of a preset number of pairs with the largest similarities, where the preset number is recorded as N; The preset number of similarities are combined with the similarity of the name short text, the similarity of the keyword short text, and the training sample label to form a 1×M-dimensional similarity vector, where M=N+3.
3. The API matching model establishment method according to any one of claims 1 to 2, It is characterized in that The API matching model is an XGBoost model.
4. An API matching method, It is characterized in that include: Obtain description texts of two APIs to be matched, wherein the description text of each API consists of at least one short text; Calculate the semantic similarity between the short texts of the two APIs to be matched; Determine the similarity vectors corresponding to the two APIs to be matched according to the semantic similarity between the short texts of the two APIs to be matched; The similarity vectors corresponding to the two APIs to be matched are input into the API matching model, and the output result of the API matching model is the matching result of the two APIs to be matched, wherein the API matching model is generated based on the API matching model establishment method as described in any one of claims 1 to 3.
5. The API matching method according to claim 4, It is characterized in that After obtaining the description texts of the two APIs to be matched and before calculating the semantic similarity between the short texts of the two APIs to be matched, the method further includes: Identify whether the description text of each API contains a short text of a geographic location qualifier; When the description text of any API contains a short text of a geographic location qualifier, the short text of the geographic location qualifier is removed.
6. A cross-city government API matching method, It is characterized in that include: Receiving a cross-city government affairs API matching query request, and obtaining a query API and a query scope based on the cross-city government affairs API matching query request; Traversing the preset government affairs API database, respectively forming an API pair to be matched with the query API and each API within the query range in the preset government affairs API database, and judging whether the API pair to be matched matches based on the API matching method as described in claim 4 or 5; Output all APIs in the preset government affairs API database that match the query API within the query scope.
7. An electronic device, It is characterized in that including memory and processor; The memory is used to store computer programs; The processor is used to implement the API matching model establishment method as described in any one of claims 1 to 4, the API matching method as described in claim 4 or 5, or the cross-city government affairs API matching method as described in 6 when executing the computer program.
8. A computer-readable storage medium, It is characterized in that A computer program is stored on the storage medium. When the computer program is executed by the processor, the API matching model establishment method as described in any one of claims 1 to 3 or the API matching method as described in claim 4 or 5 or the cross-city government affairs API matching method as described in 6 is implemented.
