Api protocol conversion method, apparatus, device, and medium
By using a semantic encoding and decoding network of a neural network model and employing an attention mechanism to process complex data structures in API protocol conversion, the problem of low conversion reliability in existing technologies is solved, and more efficient data format conversion is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- THREE GORGES HI TECH INFORMATION TECH CO LTD
- Filing Date
- 2025-05-21
- Publication Date
- 2026-07-31
AI Technical Summary
Existing API adapters struggle to effectively handle nested and recursive data structures, irregular keys, or dynamic fields when converting JSON to XML, resulting in low conversion reliability.
A semantic encoding and decoding network based on a trained neural network model is used to mine local data association semantic information in the source format request data using an attention mechanism, and data format conversion is achieved through encoding and decoding.
It improves the reliability of transformation of abnormal or unconventional data structures, ensuring effective understanding and efficient transformation of requested data.
Smart Images

Figure CN120499284B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to an API protocol conversion method, apparatus, device, and medium. Background Technology
[0002] An API adapter is a software component that acts as a "bridge" between different systems. Its main function is to convert API interfaces from different process platforms or services into a unified API interface specification. API adapters are commonly used in various system integration scenarios, especially in enterprise applications. Many systems or services may use different protocols, data formats, and even authentication mechanisms. The role of the API adapter is to unify these differences, enabling seamless integration between systems to achieve efficient communication and collaboration. However, the inventors have discovered that the API adapter conversion process involves data format conversion, such as converting JSON data to XML. In the JSON-to-XML conversion process, some abnormal or unconventional data structures are often encountered (such as nested and recursive data structures, irregular keys or dynamic fields, mixed data types, etc.). The complexity of these structures makes simple, rule-based conversion difficult or impossible to directly adapt, meaning that the API adapter cannot perform effective and reliable conversion. Summary of the Invention
[0003] In view of this, the purpose of this application is to provide an API protocol conversion method, apparatus, device and medium to improve the problem of relatively low reliability of API protocol conversion in the prior art.
[0004] To achieve the above objectives, this application adopts the following technical solution: An API protocol conversion method, comprising: Obtain source API protocol request information, parse the source format request data that needs to be converted from the source API protocol request information, and determine the target data format for converting the source format request data. The source format request data and the target data format are encoded by the semantic encoding network in the target protocol conversion model, and the corresponding target request encoding features are output. The target protocol conversion model is a trained neural network model. The target protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the source format request data during the encoding process. The semantic decoding network decodes the target request encoding features and outputs the corresponding target format request data, wherein the data format of the target format request data is the target data format.
[0005] In a preferred embodiment of this application, in the above-described API protocol conversion method, the step of encoding the source format request data and the target data format using a semantic coding network in the target protocol conversion model, and outputting the corresponding target request encoding features, includes: The source format request data is encoded by the first encoding sub-network included in the semantic encoding network of the target protocol conversion model to form the corresponding first request encoding feature. The first encoding sub-network uses an attention mechanism to mine the semantic information of the association between local data in the source format request data during the encoding process. The target data format is encoded through the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature; The first request encoding feature and the second request encoding feature are concatenated through the encoding splicing sub-network included in the semantic encoding network to form the corresponding target request encoding feature.
[0006] In a preferred embodiment of this application, in the above-described API protocol conversion method, the step of encoding the source format request data through a first encoding sub-network included in the semantic encoding network of the target protocol conversion model to form a corresponding first request encoding feature includes: The first coding subnetwork is included in the semantic coding network that loads the source format request data into the target protocol conversion model; The source format request data is embedded to form a first request embedding feature corresponding to the source format request data, wherein the first request embedding feature includes the embedding feature of each word in the source format request data; Based on the attention mechanism, the first associated semantic mining is performed on the first request embedded features to output the corresponding first request associated features; Based on the attention mechanism, the second association semantic mining is performed on the first request embedding features to output the corresponding second request association features. The second association semantic mining is different from the first association semantic mining in order to capture different association semantic information. The first request association feature and the second request association feature are aggregated to form the corresponding first request encoding feature.
[0007] In a preferred embodiment of this application, in the aforementioned API protocol conversion method, the step of performing first association semantic mining on the first request embedding features based on an attention mechanism and outputting the corresponding first request association features includes: The first request embedding feature is segmented using a sliding window to form a sliding window segmentation sequence corresponding to the first request embedding feature, wherein the sliding window segmentation sequence includes multiple sliding window segmentation features; For each sliding window segmentation feature in the sliding window segmentation sequence, when the sliding window segmentation feature belongs to the first sliding window segmentation feature, the sliding window segmentation feature is used as the corresponding mining output feature; and when the sliding window segmentation feature does not belong to the first sliding window segmentation feature, based on the attention mechanism, semantic information that is related to the mining output feature corresponding to the previous sliding window segmentation feature is mined from the sliding window segmentation feature to obtain the corresponding mining output feature. Based at least on the mining output features corresponding to the last sliding window segmentation feature, the corresponding first request association feature is determined.
[0008] In a preferred embodiment of this application, in the aforementioned API protocol conversion method, the step of performing second association semantic mining on the first request embedding features based on an attention mechanism and outputting the corresponding second request association features includes: Based on a predetermined first masking matrix and a second masking matrix, the first request embedding feature is masked to form a first request masking feature and a second request masking feature. The first masking matrix and the second masking matrix are network parameters in the first coding sub-network and are updated during the training of the first coding sub-network. Based on the attention mechanism, semantic information that is related to the second request occlusion feature is extracted from the first request occlusion feature to obtain the first occlusion association feature; Based on the attention mechanism, semantic information that is related to the first request masking feature is extracted from the second request masking feature to obtain the second masking related feature; Based on the first occlusion association feature and the second occlusion association feature, the corresponding second request association feature is determined.
[0009] In a preferred embodiment of this application, the step of encoding the target data format through the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature in the above API protocol conversion method includes: The target data format is loaded into the second coding subnetwork included in the semantic coding network; The target data format is embedded to form a second request embedding feature corresponding to the target data format, wherein the second request embedding feature includes the embedding feature of each word in the target data format; Based on the second request embedding feature, the corresponding second request encoding feature is determined.
[0010] In a preferred embodiment of this application, the API protocol conversion method described above further includes: Obtain sample API protocol request information, parse the sample format request data that needs to be converted from the sample API protocol request information, and determine the sample data format for converting the sample format request data. The sample format request data and the sample data format are encoded by the semantic encoding network in the candidate protocol conversion model, and the corresponding sample request encoding features are output. The candidate protocol conversion model is a neural network model to be trained. The candidate protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the sample format request data during the encoding process. The semantic decoding network decodes the sample request encoding features and outputs corresponding sample format request data, wherein the data format of the sample format request data is the sample data format. Based on the error between the sample format request data and the pre-determined request data labels, the parameters of the candidate protocol conversion model are updated to form the target protocol conversion model.
[0011] This application also provides an API protocol conversion device, including: The request data processing module is used to obtain source API protocol request information, parse the source format request data that needs to be converted from the source API protocol request information, and determine the target data format for converting the source format request data. The request data encoding module is used to encode the source format request data and the target data format through the semantic encoding network in the target protocol conversion model, and output the corresponding target request encoding features. The target protocol conversion model is a trained neural network model, and the target protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the source format request data during the encoding process. The request feature decoding module is used to decode the target request encoding features through the semantic decoding network and output the corresponding target format request data, wherein the data format of the target format request data is the target data format.
[0012] Based on the above, this application also provides an electronic device, including: Memory, used to store computer programs; A processor connected to the memory is used to execute the computer program stored in the memory to implement the API protocol conversion method described above.
[0013] Based on the above, this application also provides a computer-readable storage medium storing a computer program that, when executed, performs the various steps of the API protocol conversion method described above.
[0014] The API protocol conversion method, apparatus, device, and medium provided in this application first acquire source API protocol request information, parse the source format request data requiring data format conversion from the source API protocol request information, and determine the target data format for data format conversion of the source format request data. Second, the source format request data and the target data format are encoded using a semantic encoding network in the target protocol conversion model, outputting the target request encoding features. Then, the target request encoding features are decoded using a semantic decoding network, outputting the target format request data. Based on the above, since data format conversion is performed through a semantic encoding network and a semantic decoding network, the semantic information in the request data can be fully utilized. When converting abnormal or unconventional data structures, the latent semantic information can be utilized to better understand the request data, thereby achieving reliable conversion. Compared to existing technologies that use simple conversion rules such as API adapters, this method offers higher reliability for request data with low determinism, such as abnormal or unconventional data structures. Therefore, it can improve the relatively low reliability of API protocol conversion in existing technologies. Attached Figure Description
[0015] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings.
[0016] Figure 1 A structural block diagram of an electronic device provided in an embodiment of this application.
[0017] Figure 2 This is a flowchart illustrating the API protocol conversion method provided in an embodiment of this application.
[0018] Figure 3 This is a schematic diagram of the first association semantic mining provided in the embodiments of this application.
[0019] Figure 4 This is a schematic diagram of the second association semantic mining provided in the embodiments of this application.
[0020] Figure 5 This is a block diagram of an API protocol conversion device provided in an embodiment of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0022] like Figure 1 As shown in the illustration, this application provides an electronic device. The electronic device may include a memory, a processor, and an API protocol conversion device.
[0023] Specifically, the memory and the processor are electrically connected directly or indirectly to enable data transmission or interaction. For example, the memory and the processor can be electrically connected via one or more communication buses or signal lines. The API protocol conversion device includes at least one software functional module stored in the memory in the form of software or firmware. The processor is used to execute executable computer programs stored in the memory, such as the software functional modules included in the API protocol conversion device, to implement the API protocol conversion method provided in the embodiments of this application.
[0024] Optionally, the memory may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0025] Optionally, the processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a system on chip (SoC), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0026] Understandable. Figure 1 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown may include, for example, a communication unit for exchanging information with other devices.
[0027] Combination Figure 2 This application also provides an API protocol conversion method applicable to the aforementioned electronic device. The method steps defined in the API protocol conversion method can be implemented by the electronic device. The following will describe... Figure 2 The specific process shown will be explained in detail.
[0028] Step S110: Obtain source API protocol request information, parse the source format request data that needs to be converted from the source API protocol request information, and determine the target data format for converting the source format request data.
[0029] In this embodiment of the application, the electronic device can obtain source API protocol request information, and parse the source format request data (such as request data (request body), response data (response body), and certain request headers) that need to be converted from the source API protocol request information, and determine the target data format (such as JSON format, XML format) for converting the source format request data.
[0030] Step S120: Encode the source format request data and the target data format through the semantic coding network in the target protocol conversion model, and output the corresponding target request coding features.
[0031] In this embodiment, after determining the source format request data and the target data format, the electronic device can encode the source format request data and the target data format using the semantic encoding network in the target protocol conversion model, and output the corresponding target request encoding features. The target protocol conversion model is a trained neural network model, which also includes a semantic decoding network. During the encoding process, the semantic encoding network uses an attention mechanism to extract the semantic relationships between local data in the source format request data. Furthermore, in this embodiment, the extracted features can be represented as vectors or matrices, as detailed in the following description. Step S130: Decode the target request encoding features through the semantic decoding network and output the corresponding target format request data.
[0032] In this embodiment, after mining the target request encoding features, the electronic device can decode the target request encoding features through the semantic decoding network and output the corresponding target format request data. The data format of the target format request data is the target data format. It should be noted that protocol conversion (different services may use different protocols (such as REST, SOAP, GraphQL, etc.), an API adapter can convert an API request from one protocol to another to enable interoperability between different protocols) and security authentication (different systems may use different authentication methods (such as OAuth, API Key, JWT, etc.), the API adapter will perform corresponding authentication processing according to the requirements of the target system to ensure the security of the request) can also be achieved through a traditional API adapter. In addition, the semantic decoding network may include fully connected layers and a softmax function. Specifically, in the first time step, the target request encoding feature can be used as the input feature of the current time step. The target request encoding feature can be mapped to a fully connected feature through a fully connected layer. The size of the fully connected feature is the same as the number of words in the target vocabulary. Then, the softmax function can be used to map the fully connected feature to a probability distribution (without changing the size). Each probability value in the probability distribution is used to represent the probability of a corresponding word being selected. In this way, the word with the largest probability value can be used as the output of the first time step. In the second time step, the embedded features corresponding to the output (a word) of the previous time step (i.e., the first time step) can be fused with the input features of the previous time step to form the input features of the current time step. Then, a fully connected layer can be used to map the input features of the current time step into a fully connected feature. After that, a softmax function can be used to map the fully connected feature into a probability distribution. Thus, the word with the highest probability value can be used as the output of the current time step (the second time step). This process is repeated to obtain the output of each time step until an end marker (e.g., END) is output. Then, the outputs of each time step are arranged in order to form the corresponding target format request data. Alternatively, the aforementioned fusion can refer to concatenating the embedded features corresponding to the output of the previous time step with the input features of the previous time step, and then performing self-attention processing on the concatenated result to obtain the input features of the current time step; or, weighted summation can be performed on the embedded features corresponding to the output of the previous time step with the input features of the previous time step to obtain the input features of the current time step.
[0033] Based on the above, since data format conversion is performed through semantic encoding and semantic decoding networks, the semantic information in the request data can be fully utilized. When converting abnormal or unconventional data structures, the underlying semantic information can be used to better understand the request data, thereby achieving reliable conversion. Compared to the existing technology that uses simple conversion rules such as API adapters, this method has higher reliability for request data with low determinism, such as abnormal or unconventional data structures. Therefore, it can improve the problem of relatively low reliability of API protocol conversion in the existing technology.
[0034] It should be noted that for step S120, the specific method of encoding the source format request data and the target data format is not limited and can be selected according to actual needs.
[0035] For example, in an alternative implementation, the target data format can be directly concatenated to the beginning or end of the source format request data. Then, the semantic coding network can be used to perform semantic coding on the concatenated data to obtain the corresponding target request coding features.
[0036] For example, in another alternative implementation, in order to improve the accuracy of semantic encoding and make the semantic representation of the obtained target request encoding features reliable, the above step S120 may further include steps S121, S122 and S123, the specific contents of each step are as follows.
[0037] Step S121: The source format request data is encoded by the first encoding sub-network included in the semantic encoding network of the target protocol conversion model to form the corresponding first request encoding feature.
[0038] In this embodiment, the source format request data can be encoded using a first encoding sub-network within the semantic encoding network of the target protocol conversion model to form a corresponding first request encoding feature. During the encoding process, the first encoding sub-network uses an attention mechanism to extract the semantic relationships between local data within the source format request data.
[0039] Step S122: The target data format is encoded through the second encoding sub-network included in the semantic encoding network to form the corresponding second request encoding feature.
[0040] In this embodiment, the target data format can be encoded using the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature. That is, the source format request data and the target data format can be encoded using both the first encoding sub-network and the second encoding sub-network to ensure encoding accuracy.
[0041] Step S123: The first request encoding feature and the second request encoding feature are concatenated through the encoding splicing sub-network included in the semantic encoding network to form the corresponding target request encoding feature.
[0042] In this embodiment, after obtaining the first request encoding feature and the second request encoding feature, the first request encoding feature and the second request encoding feature can be concatenated using the encoding concatenation sub-network included in the semantic encoding network to form a corresponding target request encoding feature. For example, the concatenated feature can be directly used as the target request encoding feature; alternatively, the concatenated feature can undergo further self-attention processing, convolution processing, pooling processing, fully connected processing, etc., to further capture the deep semantic information it contains. The specific method can be determined according to actual needs.
[0043] It is understood that in step S121 above, the specific method by which the source format request data is encoded by the first encoding sub-network included in the semantic encoding network in the target protocol conversion model is not limited. For example, in an alternative implementation, in order to fully capture the associated semantic information in the source format request data, step S121 above may further include steps S121a, S121b, S121c, S121d and S121e, as follows.
[0044] Step S121a: Load the source format request data into the first coding sub-network of the semantic coding network in the target protocol conversion model.
[0045] In this embodiment of the application, the source format request data can be loaded into the first encoding sub-network of the semantic encoding network in the target protocol conversion model. In this way, subsequent specific encoding processing can be performed in the first encoding sub-network to obtain the corresponding semantic encoding features.
[0046] Step S121b: Embed the source format request data to form a first request embedding feature corresponding to the source format request data.
[0047] In this embodiment, the source format request data can be embedded to form a first request embedding feature corresponding to the source format request data. The first request embedding feature includes the embedding feature of each word in the source format request data. For example, the embedding features of each word can be concatenated to form the first request embedding feature. Alternatively, the embedding process can be implemented using a word embedding model. For example, if a portion of the source format request data is "location: New York", then through word segmentation and embedding, the following can be obtained: "location"~[0.45, -0.12, 0.22, 0.67, 0.81, -0.23, 0.31, 0.19, -0.41, 0.54, -0.33, ..., 0.05]; “:”~[-0.15, 0.12, 0.25, -0.48, 0.33, 0.10, -0.06, 0.21, -0.15, 0.44, 0.07, ..., -0.22]; "New"~[0.78, -0.19, 0.57, -0.26, 0.33, 0.11, 0.62, -0.17, 0.44, -0.36, 0.02, ..., 0.59]; "York" ~ [-0.52, 0.64, 0.12, 0.35, -0.49, 0.03, -0.24, 0.11, 0.12, -0.33, 0.65, ..., 0.18].
[0048] Thus, the first request embedding feature formed by splicing can be: [[0.45, -0.12, 0.22, 0.67, 0.81, -0.23, 0.31, 0.19, -0.41, 0.54, -0.33, ..., 0.05]; [-0.15, 0.12, 0.25, -0.48, 0.33, 0.10, -0.06, 0.21, -0.15, 0.44, 0.07, ..., -0.22]; [0. 78, -0.19, 0.57, -0.26, 0.33, 0.11, 0.62, -0.17, 0.44, -0.36, 0.02, ..., 0.59]; [-0.52, 0.64, 0.12, 0.35, -0.49, 0.03, -0.24, 0.11, 0.12, -0.33, 0.65, ..., 0.18], ...).
[0049] It should be noted that retaining punctuation marks allows them to be embedded in the semantic space of other words. This approach helps the model understand the role of punctuation marks in text, especially in source format request data with complex structures, where it plays a more important role.
[0050] Step S121c: Based on the attention mechanism, perform first association semantic mining on the first request embedded features and output the corresponding first request association features.
[0051] In this embodiment of the application, after obtaining the first request embedding feature, the first associated semantic mining can be performed on the first request embedding feature based on the attention mechanism to output the corresponding first request associated feature, that is, the association information between the semantics inside the first request embedding feature is mined through the attention mechanism.
[0052] Step S121d: Based on the attention mechanism, perform second association semantic mining on the first request embedding features and output the corresponding second request association features.
[0053] In this embodiment of the application, after obtaining the first request embedding feature, a second association semantic mining can be performed on the first request embedding feature based on an attention mechanism to output the corresponding second request association feature. The second association semantic mining differs from the first association semantic mining in that it captures different association semantic information.
[0054] Step S121e: Aggregate the first request association feature and the second request association feature to form a corresponding first request encoding feature.
[0055] In this embodiment, after obtaining the first request association feature and the second request association feature, the first request association feature and the second request association feature can be aggregated to form a corresponding first request encoding feature. That is, the association semantic information in the first request association feature can be captured or mined through two different methods. This allows for more comprehensive mining of the association semantic information, and further aggregation can improve the semantic representation capability of the formed first request encoding feature. Furthermore, the aggregation method can be mean calculation, or it can involve concatenation followed by downsampling or other processing.
[0056] It is understood that in step S121c above, the specific method of performing the first associated semantic mining on the first request embedded features is not limited. For example, in an alternative implementation, in order to sequentially fuse different associated semantic information during the process of capturing associated semantic information, step S121c above may further include the following (in conjunction with...). Figure 3 ): First, the first request embedding feature can be segmented by a sliding window to form a sliding window segmentation sequence corresponding to the first request embedding feature. The sliding window segmentation sequence includes multiple sliding window segmentation features. The step size (such as 1, 2, 3, etc.) and window size corresponding to the sliding window segmentation can be formed as network parameters of the first coding sub-network during training. Secondly, for each sliding window segmentation feature in the sliding window segmentation sequence, when the sliding window segmentation feature belongs to the first sliding window segmentation feature, the sliding window segmentation feature is used as the corresponding mining output feature. When the sliding window segmentation feature does not belong to the first sliding window segmentation feature, based on an attention mechanism, semantic information related to the mining output feature corresponding to the previous sliding window segmentation feature is mined from the sliding window segmentation feature to obtain the corresponding mining output feature. In other words, based on the mining output feature corresponding to the previous sliding window segmentation feature, cross-attention processing (where the query comes from the mining output feature corresponding to the previous sliding window segmentation feature, and the key and value come from the current sliding window segmentation feature) can be performed on the current sliding window segmentation feature to obtain the corresponding attention feature. Then, the mean of the attention feature and the current sliding window segmentation feature can be calculated to obtain the corresponding mining output feature. Finally, the corresponding first request association feature can be determined based at least on the mining output feature corresponding to the last sliding window segmentation feature; for example, the mining output feature corresponding to the last sliding window segmentation feature can be directly determined as the first request association feature.
[0057] It is understood that in step S121d above, the specific method of performing the second associated semantic mining on the first requested embedded features is not limited and can be selected according to actual needs. For example, in an alternative implementation, in order to focus on important semantic information as much as possible during the mining of associated semantic information, step S121d above can further include the following (in conjunction with...). Figure 4 ): First, the first request embedding feature can be masked based on a predetermined first masking matrix and a second masking matrix, forming a first request masking feature and a second request masking feature. The first and second masking matrices are network parameters in the first encoding sub-network and are updated during the training of the first encoding sub-network. Furthermore, the first and second masking matrices have the same size as the first request embedding feature, and the parameters in the first and second masking matrices consist of 1s and 0s. Thus, the first masking matrix and the first request embedding feature can be multiplied bitwise (i.e., parameters at corresponding positions are multiplied), so that the positions of parameters equal to 0 in the first masking matrix correspond to the corresponding parameters in the first request embedding feature, which are then masked. Similarly, the second masking matrix and the first request embedding feature can be multiplied bitwise, so that the positions of parameters equal to 0 in the second masking matrix correspond to the corresponding parameters in the first request embedding feature, which are then masked. In this way, parameters at different positions (or with varying degrees of importance) in the first request embedding feature can be masked or hidden using the two masking matrices. Secondly, based on the attention mechanism, semantic information that is related to the second request masking feature can be mined from the first request masking feature to obtain the first masking association feature; that is, based on the second request masking feature (i.e., the query comes from the second request masking feature), cross-attention processing can be performed on the first request masking feature (i.e., the key and value come from the first request masking feature), and then the average of the obtained attention feature and the first request masking feature can be calculated to obtain the first masking association feature. Then, based on the attention mechanism, semantic information that is related to the first request masking feature can be mined from the second request masking feature to obtain the second masking related feature; that is, based on the first request masking feature (i.e., the query comes from the first request masking feature), cross-attention processing can be performed on the second request masking feature (i.e., the key and value come from the second request masking feature), and then the mean of the obtained attention feature and the second request masking feature can be calculated to obtain the second masking related feature; Finally, based on the first occlusion association feature and the second occlusion association feature, the corresponding second request association feature can be determined; for example, the second request association feature can be obtained by averaging the first occlusion association feature and the second occlusion association feature.
[0058] It is understood that the specific method of encoding the target data format in step S122 above is not limited and can be selected according to actual needs. For example, in an alternative implementation, in order to improve the efficiency of encoding the target data format, step S122 above may further include the following: First, the target data format can be loaded into the second encoding sub-network included in the semantic encoding network, so that subsequent encoding processing can be performed in the second encoding sub-network; Secondly, the target data format can be embedded to form a second request embedding feature corresponding to the target data format. The second request embedding feature includes the embedding feature of each word in the target data format. The embedding process is as described above. Then, based on the second request embedding feature, the corresponding second request encoding feature can be determined. For example, considering that the semantic content of the target data format is relatively simple, the second request embedding feature can be directly used as the second request encoding feature.
[0059] Further explanation is needed regarding steps S120 and S130 above. To ensure the target protocol conversion model can reliably convert request data of different data formats, i.e., to guarantee the effective execution of steps S120 and S130, the API protocol conversion method may further include the following before steps S120 and S130: First, sample API protocol request information can be obtained, and sample format request data that needs to be converted can be parsed from the sample API protocol request information. Then, the sample data format for converting the sample format request data can be determined. For details, please refer to the relevant explanation of step S110 above. Secondly, the sample format request data and the sample data format can be encoded by the semantic encoding network in the candidate protocol conversion model, and the corresponding sample request encoding features can be output. The candidate protocol conversion model is a neural network model to be trained. The candidate protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the sample format request data during the encoding process. For details, please refer to the relevant explanation of step S120 above. Then, the semantic decoding network can be used to decode the sample request encoding features and output the corresponding sample format request data, wherein the data format of the sample format request data is the sample data format, which can be referred to the relevant explanation of step S130 above; Finally, the parameters of the candidate protocol conversion model can be updated based on the error between the sample format request data and the pre-determined request data tags (i.e., request data with the sample data format, which can be written by the corresponding developers) to form the target protocol conversion model. This can be achieved by updating the parameters in the direction of reducing the error until the error converges, thus forming the target protocol conversion model. Alternatively, the error can be calculated using mean squared error. Specifically, the output of the semantic decoding network can be the probability distribution at each time step (as described previously). The mean squared error between this probability distribution and the probability distribution of the corresponding words in the request data tags can be calculated. For example, for the first time step, the mean squared error can be calculated between the probability distribution output by the semantic decoding network and the probability distribution corresponding to the first word in the request data tags (in which only the probability of the first word is 1, and the probabilities of other words are 0). Based on this, after obtaining the mean squared error corresponding to the output of each time step, the sum of the mean squared errors can be calculated to obtain the final error. Alternatively, in other implementations, to encourage the model to output a high probability of correct words and penalize a high probability of incorrect words, cross-entropy error can be used. For example, the cross-entropy error for the output at a given time step could be: ; Where L represents the cross-entropy error, y i p represents the probability distribution corresponding to the label (1 for the actual word, 0 for other words). i The probability distribution of the decoding output of the semantic decoding network is represented by N, where N represents the size of the vocabulary (the number of words included).
[0060] In addition, in a specific application, the sample request data in JSON format can be: { "user": { "name": "John", "age": 30, "email": "john@example.com" } }
[0061] Accordingly, the XML format request data tags can be: <user> <name> John< / name> <age> 30< / age> <email> john@example.com< / email> < / user> .
[0062] Combination Figure 5This application also provides an API protocol conversion device applicable to the aforementioned electronic device. The API protocol conversion device may include a request data processing module, a request data encoding module, and a request feature decoding module.
[0063] The request data processing module is configured to acquire source API protocol request information, parse source format request data requiring data format conversion from the source API protocol request information, and determine the target data format for converting the source format request data. In this embodiment, the request data processing module can be used to execute... Figure 2 The relevant content regarding the request data processing module in step S110 shown can be found in the preceding description of step S110.
[0064] The request data encoding module is used to encode the source format request data and the target data format using a semantic encoding network in the target protocol conversion model, and output corresponding target request encoding features. The target protocol conversion model is a trained neural network model, which also includes a semantic decoding network. During the encoding process, the semantic encoding network uses an attention mechanism to extract the semantic relationships between local data in the source format request data. In this embodiment, the request data encoding module can be used to execute... Figure 2 The relevant content regarding the request data encoding module in step S120 shown can be found in the preceding description of step S120.
[0065] The request feature decoding module is used to decode the target request encoding features through the semantic decoding network and output corresponding target format request data, wherein the data format of the target format request data is the target data format. In this embodiment of the application, the request feature decoding module can be used to execute... Figure 2 The relevant content regarding the request feature decoding module in step S130 shown can be found in the preceding description of step S130.
[0066] In this embodiment of the application, corresponding to the above-described API protocol conversion method applied to the electronic device, a computer-readable storage medium is also provided, which stores a computer program that executes the various steps of the API protocol conversion method when the computer program is run.
[0067] The steps executed by the aforementioned computer program during runtime will not be described in detail here; please refer to the explanation of the API protocol conversion method above.
[0068] In summary, the API protocol conversion method, apparatus, device, and medium provided in this application first obtain source API protocol request information, parse the source format request data requiring data format conversion from the source API protocol request information, and determine the target data format for data format conversion of the source format request data; secondly, encode the source format request data and the target data format through a semantic encoding network in the target protocol conversion model, and output the target request encoding features; then, decode the target request encoding features through a semantic decoding network, and output the target format request data. Based on the above, since the data format conversion is performed through a semantic encoding network and a semantic decoding network, the semantic information in the request data can be fully utilized. When converting abnormal or unconventional data structures, the potential semantic information can be utilized to better understand the request data, thereby achieving reliable conversion. Compared with the existing technology that uses simple conversion rules such as API adapters to achieve conversion, this method has higher reliability for request data with low determinism, such as abnormal or unconventional data structures. Therefore, it can improve the problem of relatively low reliability of API protocol conversion in the prior art.
[0069] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus and method embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0070] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0071] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, electronic device, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks. It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. In the absence of further restrictions, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0072] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. An API protocol conversion method, characterized in that, include: Obtain source API protocol request information, parse the source format request data that needs to be converted from the source API protocol request information, and determine the target data format for converting the source format request data. The source format request data and the target data format are encoded by the semantic encoding network in the target protocol conversion model, and the corresponding target request encoding features are output. The target protocol conversion model is a trained neural network model. The target protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the source format request data during the encoding process. The semantic decoding network decodes the target request encoding features and outputs the corresponding target format request data, wherein the data format of the target format request data is the target data format.
2. The API protocol conversion method according to claim 1, characterized in that, The step of encoding the source format request data and the target data format through the semantic coding network in the target protocol conversion model, and outputting the corresponding target request encoding features, includes: The source format request data is encoded by the first encoding sub-network of the semantic encoding network in the target protocol conversion model to form the corresponding first request encoding feature. The first encoding sub-network uses an attention mechanism to mine the semantic information of the association between local data in the source format request data during the encoding process. The target data format is encoded through the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature; The first request encoding feature and the second request encoding feature are concatenated through the encoding splicing sub-network included in the semantic encoding network to form the corresponding target request encoding feature.
3. The API protocol conversion method according to claim 2, characterized in that, The step of encoding the source format request data to form corresponding first request encoding features through the first encoding sub-network of the semantic encoding network in the target protocol conversion model includes: The first coding subnetwork is included in the semantic coding network that loads the source format request data into the target protocol conversion model; The source format request data is embedded to form a first request embedding feature corresponding to the source format request data, wherein the first request embedding feature includes the embedding feature of each word in the source format request data; Based on the attention mechanism, the first associated semantic mining is performed on the first request embedded features to output the corresponding first request associated features; Based on the attention mechanism, the second association semantic mining is performed on the first request embedding features to output the corresponding second request association features. The second association semantic mining is different from the first association semantic mining in order to capture different association semantic information. The first request association feature and the second request association feature are aggregated to form the corresponding first request encoding feature.
4. The API protocol conversion method according to claim 3, characterized in that, The step of performing first association semantic mining on the first request embedded features based on the attention mechanism and outputting the corresponding first request association features includes: The first request embedding feature is segmented using a sliding window to form a sliding window segmentation sequence corresponding to the first request embedding feature, wherein the sliding window segmentation sequence includes multiple sliding window segmentation features; For each sliding window segmentation feature in the sliding window segmentation sequence, when the sliding window segmentation feature belongs to the first sliding window segmentation feature, the sliding window segmentation feature is used as the corresponding mining output feature; and when the sliding window segmentation feature does not belong to the first sliding window segmentation feature, based on the attention mechanism, semantic information that is related to the mining output feature corresponding to the previous sliding window segmentation feature is mined from the sliding window segmentation feature to obtain the corresponding mining output feature. Based at least on the mining output features corresponding to the last sliding window segmentation feature, the corresponding first request association feature is determined.
5. The API protocol conversion method according to claim 3, characterized in that, The step of performing second semantic mining on the first request embedding features based on the attention mechanism and outputting the corresponding second request association features includes: Based on a predetermined first masking matrix and a second masking matrix, the first request embedding feature is masked to form a first request masking feature and a second request masking feature. The first masking matrix and the second masking matrix are network parameters in the first coding sub-network and are updated during the training of the first coding sub-network. Based on the attention mechanism, semantic information that is related to the second request occlusion feature is extracted from the first request occlusion feature to obtain the first occlusion association feature; Based on the attention mechanism, semantic information that is related to the first request masking feature is extracted from the second request masking feature to obtain the second masking related feature; Based on the first occlusion association feature and the second occlusion association feature, the corresponding second request association feature is determined.
6. The API protocol conversion method according to claim 2, characterized in that, The step of encoding the target data format through the second encoding sub-network included in the semantic encoding network to form the corresponding second request encoding feature includes: The target data format is loaded into the second coding subnetwork included in the semantic coding network; The target data format is embedded to form a second request embedding feature corresponding to the target data format, wherein the second request embedding feature includes the embedding feature of each word in the target data format; Based on the second request embedding feature, the corresponding second request encoding feature is determined.
7. The API protocol conversion method according to any one of claims 1-6, characterized in that, Also includes: Obtain sample API protocol request information, parse the sample format request data that needs to be converted from the sample API protocol request information, and determine the sample data format for converting the sample format request data. The sample format request data and the sample data format are encoded by the semantic encoding network in the candidate protocol conversion model, and the corresponding sample request encoding features are output. The candidate protocol conversion model is a neural network model to be trained. The candidate protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the sample format request data during the encoding process. The semantic decoding network decodes the sample request encoding features and outputs the corresponding sample format request data, wherein the data format of the sample format request data is the sample data format. Based on the error between the sample format request data and the pre-determined request data labels, the parameters of the candidate protocol conversion model are updated to form the target protocol conversion model.
8. An API protocol conversion device, characterized in that, include: The request data processing module is used to obtain source API protocol request information, parse the source format request data that needs to be converted from the source API protocol request information, and determine the target data format for converting the source format request data. The request data encoding module is used to encode the source format request data and the target data format through the semantic encoding network in the target protocol conversion model, and output the corresponding target request encoding features. The target protocol conversion model is a trained neural network model, and the target protocol conversion model also includes a semantic decoding network. The semantic encoding network uses an attention mechanism to mine the semantic information of the correlation between local data in the source format request data during the encoding process. The request feature decoding module is used to decode the target request encoding features through the semantic decoding network and output the corresponding target format request data, wherein the data format of the target format request data is the target data format.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor connected to the memory is used to execute a computer program stored in the memory to implement the API protocol conversion method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed, performs the API protocol conversion method according to any one of claims 1-7.