API protocol conversion method and device, equipment and medium

By using the semantic encoding and decoding network of neural network models, abnormal or unconventional data structures in API protocol conversion are handled based on attention mechanism, the reliability of data format conversion is improved, and the problem of low reliability in the prior art is solved.

CN120499284AActive Publication Date: 2025-08-15THREE GORGES HI TECH INFORMATION TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202510653510.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-21
Publication Date
2025-08-15
Estimated Expiration
2045-05-21

AI Technical Summary

Technical Problem

The existing API protocol conversion methods are not reliable when handling exceptions or unconventional data structures, making it difficult to achieve effective data format conversion.

Method used

The semantic encoding and decoding network of the trained neural network model are used to mine the semantic information associated with local data in the source format request data through the attention mechanism, and encode and decode it to output the target format request data.

Benefits of technology

Improve the reliability of API protocol conversion, better understand and handle exceptions or unconventional data structures, and realize reliable data format conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120499284A_ABST
    Figure CN120499284A_ABST
Patent Text Reader

Abstract

The invention provides an API protocol conversion method and device, equipment and a medium, and relates to the technical field of computers. In the application, firstly, source API protocol request information is acquired, source format request data needing data format conversion is analyzed from the source API protocol request information, and a target data format for performing data format conversion on the source format request data is determined; secondly, encoding the source format request data and the target data format through a semantic encoding network in the target protocol conversion model, and outputting target request encoding features; and then, through a semantic decoding network, decoding the target request coding feature, and outputting target format request data. Based on the content, the problem that the reliability of API protocol conversion is relatively low in the prior art can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to an API protocol conversion method, apparatus, device, and medium. Background Art

[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 typically used in a variety of different system integration scenarios, especially in enterprise-level 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 so that the various systems can seamlessly connect to achieve efficient communication and collaboration. However, the inventors have discovered that the API adapter involves data format conversion during the conversion process, such as converting JSON format data into XML format. In the JSON to XML conversion process, some abnormal or unconventional data structures (such as nested and recursive data structures, irregular keys or dynamic fields, mixed data types, etc.) are usually encountered. The complexity of these structures makes simple regular conversion difficult or impossible to adapt directly, that is, it is difficult to perform effective and reliable conversion through the API adapter. Summary of the Invention

[0003] In view of this, the purpose of this application is to provide an API protocol conversion method, device, equipment 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 solutions: An API protocol conversion method, comprising: Obtaining source API protocol request information, parsing source format request data that needs to be converted from the source API protocol request information, and determining a target data format for converting the source format request data; Encoding the source format request data and the target data format through a semantic encoding network in a target protocol conversion model, and outputting corresponding target request encoding features, wherein the target protocol conversion model is a trained neural network model, the target protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; The target request encoding feature is decoded through the semantic decoding network to output 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 the present application, in the above-mentioned API protocol conversion method, the step of encoding the source format request data and the target data format through the semantic encoding network in the target protocol conversion model and outputting the corresponding target request encoding features includes: The source format request data is encoded by a first encoding sub-network included in a semantic encoding network in a target protocol conversion model to form a corresponding first request encoding feature, wherein the first encoding sub-network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; Encoding the target data format through a second encoding subnetwork 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 spliced through the encoding splicing sub-network included in the semantic encoding network to form a corresponding target request encoding feature.

[0006] In a preferred embodiment of the present application, in the above-mentioned API protocol conversion method, the step of encoding the source format request data by the first encoding subnetwork included in the semantic encoding network in the target protocol conversion model to form a corresponding first request encoding feature includes: Loading the source format request data into a first encoding subnetwork included in a semantic encoding network in a target protocol conversion model; Performing embedding processing on the source format request data to form a first request embedding feature corresponding to the source format request data, wherein the first request embedding feature includes an embedding feature of each word in the source format request data; Based on the attention mechanism, performing first associated semantic mining on the first request embedding feature, and outputting the corresponding first request associated feature; Based on the attention mechanism, performing second association semantic mining on the first request embedding feature and outputting corresponding second request association features, wherein the second association semantic mining is different from the first association semantic mining to capture different association semantic information; Aggregate the first request correlation feature and the second request correlation feature to form a corresponding first request encoding feature.

[0007] In a preferred embodiment of the present application, in the above-mentioned API protocol conversion method, the step of performing first associated semantic mining on the first request embedding feature based on the attention mechanism and outputting the corresponding first request associated feature includes: Performing sliding window segmentation on the first request embedding feature to form a sliding window segmentation sequence corresponding to the first request embedding feature, wherein the sliding window segmentation sequence includes a plurality of 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, using the sliding window segmentation feature as the corresponding mining output feature; and when the sliding window segmentation feature does not belong to the first sliding window segmentation feature, mining semantic information having an associated relationship with the mining output feature corresponding to the previous sliding window segmentation feature from the sliding window segmentation feature based on an attention mechanism to obtain a corresponding mining output feature; Based on at least the mining output feature corresponding to the last sliding window segmentation feature, a corresponding first request association feature is determined.

[0008] In a preferred embodiment of the present application, in the above-mentioned API protocol conversion method, the step of performing second-related semantic mining on the first request embedding feature based on the attention mechanism and outputting the corresponding second request related feature includes: Based on a predetermined first masking matrix and a second masking matrix, masking the first request embedding feature to form a first request masked feature and a second request masked feature, respectively, wherein the first masking matrix and the second masking matrix are network parameters in the first encoding sub-network and are updated during the training of the first encoding sub-network; Based on the attention mechanism, semantic information associated with the second request masked feature is mined from the first request masked feature to obtain a first masked associated feature; Based on the attention mechanism, semantic information associated with the first request masked feature is mined from the second request masked feature to obtain a second masked associated feature; Based on the first mask-related feature and the second mask-related feature, a corresponding second request-related feature is determined.

[0009] In a preferred embodiment of the present application, in the above-mentioned API protocol conversion method, the step of encoding the target data format through the second encoding subnetwork included in the semantic encoding network to form a corresponding second request encoding feature includes: Loading the target data format into the second encoding subnetwork included in the semantic encoding network; Performing embedding processing on the target data format to form a second request embedding feature corresponding to the target data format, wherein the second request embedding feature includes an embedding feature of each word in the target data format; Based on the second request embedded feature, a corresponding second request encoding feature is determined.

[0010] In a preferred embodiment of the present application, the above API protocol conversion method further includes: Obtaining sample API protocol request information, parsing sample format request data that needs to be converted from the sample API protocol request information, and determining a sample data format for converting the sample format request data; Encoding the sample format request data and the sample data format through a semantic encoding network in a candidate protocol conversion model, and outputting corresponding sample request encoding features, wherein the candidate protocol conversion model is a neural network model to be trained, and the candidate protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the sample format request data based on an attention mechanism during the encoding process; Decoding the sample request encoding feature through the semantic decoding network and outputting 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 predetermined request data label, the parameters of the candidate protocol conversion model are updated to form a target protocol conversion model.

[0011] This application also provides an API protocol conversion device, including: a request data processing module, configured 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 a target data format for converting the source format request data; a request data encoding module, configured to encode the source format request data and the target data format through a semantic encoding network in a target protocol conversion model, and output corresponding target request encoding features, wherein the target protocol conversion model is a trained neural network model, the target protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; The request feature decoding module is used to decode the target request encoding feature 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, the present application further provides an electronic device, including: memory for storing computer programs; The processor connected to the memory is used to execute the computer program stored in the memory to implement the above-mentioned API protocol conversion method.

[0013] On the basis of the above, the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is run, the various steps of the above-mentioned API protocol conversion method are executed.

[0014] The API protocol conversion method, device, equipment and medium provided in the present application first obtain the source API protocol request information, and 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; secondly, the source format request data and the target data format are encoded through the semantic encoding network in the target protocol conversion model, and the target request encoding features are output; then, the target request encoding features are decoded through the semantic decoding network, and the target format request data is output. Based on the above content, since the data format is converted through the semantic encoding network and the 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 therein can be utilized, so that the request data can be better understood, thereby achieving reliable conversion. Compared with the solution of using a simple conversion rule such as an API adapter in the prior art to achieve conversion, it has higher reliability for request data with low certainty such as abnormal or unconventional data structures. Therefore, the problem of relatively low reliability of API protocol conversion in the prior art can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings.

[0016] Figure 1 This is a structural block diagram of the electronic device provided in an embodiment of the present application.

[0017] Figure 2 A flowchart of the API protocol conversion method provided in an embodiment of the present application.

[0018] Figure 3 A schematic diagram of the first association semantic mining provided in an embodiment of the present application.

[0019] Figure 4 A schematic diagram of the second association semantic mining provided in an embodiment of the present application.

[0020] Figure 5 A block diagram of the API protocol conversion device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application for which protection is claimed, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0022] like Figure 1 As shown, an embodiment of the present application provides an electronic device, wherein the electronic device may include a memory, a processor, and an API protocol conversion device.

[0023] In detail, the memory and the processor are electrically connected directly or indirectly to realize data transmission or interaction. For example, the memory and the processor can be electrically connected through one or more communication buses or signal lines. The API protocol conversion device includes at least one software function module stored in the memory in the form of software or firmware. The processor is used to execute the executable computer program stored in the memory, for example, the software function module included in the API protocol conversion device, etc., to realize the API protocol conversion method provided in the embodiment of the present 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, discrete hardware components.

[0026] I understand. Figure 1 The structure shown is only for illustration, and the electronic device may also include Figure 1 More or fewer components than shown, or with Figure 1 The different configurations shown may, for example, further include a communication unit for exchanging information with other devices.

[0027] Combine Figure 2 , the embodiment of the present application also provides an API protocol conversion method applicable to the above electronic device. Among them, the method steps defined in the process related to the API protocol conversion method can be implemented by the electronic device. Figure 2 The specific process shown is explained in detail.

[0028] Step S110 , obtaining source API protocol request information, parsing source format request data that needs to be converted from the source API protocol request information, and determining a target data format for converting the source format request data.

[0029] In an embodiment of the present application, the electronic device can obtain source API protocol request information, and parse the source format request data that needs to be converted into data format (such as request data (request body), response data (response body), and certain request headers (Headers)) 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 into data format.

[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 corresponding target request coding features.

[0031] In an embodiment of the present application, 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 through the semantic coding network in the target protocol conversion model, and output the corresponding target request coding features. Wherein, the target protocol conversion model is a trained neural network model, and the target protocol conversion model also includes a semantic decoding network, and the semantic coding network mines the associated semantic information between the local data in the source format request data based on the attention mechanism during the encoding process. In addition, in an embodiment of the present application, the expression form of each feature mined can be a vector or a matrix, and the details can be referred to the relevant description below. Step S130: Decode the target request encoding feature through the semantic decoding network and output corresponding target format request data.

[0032] In an embodiment of the present application, 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 for protocol conversion (different services may use different protocols (such as REST, SOAP, GraphQL, etc.), the API adapter can convert the API request of one protocol into another protocol so that different protocols can interoperate) 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), it can also be achieved through traditional API adapters. In addition, the semantic decoding network may include a fully connected layer and a softmax function. Specifically, at the first time step, the target request encoding feature can be used as the input feature of the current time step, and the target request encoding feature can be mapped to a fully connected feature through the fully connected layer. The size of the fully connected feature is the same as the number of words in the target vocabulary. Then, the fully connected feature can be mapped to a probability distribution (size unchanged) through the softmax function. 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. At 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. The input features of the current time step can then be mapped into a fully connected feature using a fully connected layer. The fully connected features can then be mapped into a probability distribution using a softmax function. Thus, the word with the largest probability value can be used as the output of the current time step (the second time step). This cycle can be repeated to obtain the output of each time step until an end marker (e.g., or END) is output. The outputs of each time step are then arranged in sequence to form the corresponding target format request data. Furthermore, 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, then performing self-attention processing on the concatenated result to obtain the input features of the current time step, or performing a weighted sum calculation 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 content, since the data format conversion is performed through the semantic encoding network and the 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, so that the request data can be better understood, thereby achieving reliable conversion. Compared with the existing technology that uses simple conversion rules such as API adapters to achieve conversion, it has higher reliability for request data with low certainty such as abnormal or unconventional data structures. Therefore, the problem of relatively low reliability of API protocol conversion in the existing technology can be improved.

[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 embodiment, the target data format can be directly spliced to the beginning or end of the source format request data, and then the spliced data can be semantically encoded through the semantic encoding network to obtain the corresponding target request encoding features.

[0036] For example, in another alternative embodiment, in order to improve the accuracy of semantic encoding and make the semantic representation of the target request encoding feature more reliable, the above-mentioned step S120 may further include step S121, step S122 and step S123, and the specific content of each step is described as follows.

[0037] Step S121 : Encode the source format request data through the first encoding sub-network included in the semantic encoding network in the target protocol conversion model to form a corresponding first request encoding feature.

[0038] In an embodiment of the present application, the source format request data can be encoded by a first encoding subnetwork included in a semantic encoding network in a target protocol conversion model to form a corresponding first request encoding feature. During the encoding process, the first encoding subnetwork mines the associated semantic information between local data in the source format request data based on an attention mechanism.

[0039] Step S122: Encode the target data format through the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature.

[0040] In this embodiment of the present application, the target data format can be encoded by the second encoding subnetwork included in the semantic encoding network to form a corresponding second request encoding feature. In other words, the source format request data and the target data format can be encoded by the first encoding subnetwork and the second encoding subnetwork, respectively, to ensure encoding accuracy.

[0041] Step S123: splicing the first request encoding feature and the second request encoding feature through the encoding splicing sub-network included in the semantic encoding network to form a corresponding target request encoding feature.

[0042] In an embodiment of the present application, 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 spliced together through the encoding splicing subnetwork included in the semantic encoding network to form a corresponding target request encoding feature. For example, the spliced features can be directly used as the target request encoding features, or the spliced features can be further processed by self-attention, convolution, pooling, full connection, etc. to further capture the deep semantic information contained therein. The specific process can be determined according to actual needs.

[0043] It can be understood that, in the above-mentioned step S121, the specific manner of encoding the source format request data 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 embodiment, in order to fully capture the associated semantic information in the source format request data, the above-mentioned step S121 may further include step S121a, step S121b, step S121c, step S121d and step S121e, as follows.

[0044] Step S121a: Load the source format request data into the first encoding sub-network included in the semantic encoding network in the target protocol conversion model.

[0045] In an embodiment of the present application, the source format request data can be loaded into the first encoding subnetwork included in the semantic encoding network in the target protocol conversion model. In this way, subsequent specific encoding processing can be performed in the first encoding subnetwork to obtain corresponding semantic encoding features.

[0046] Step S121b: embedding the source format request data to form a first request embedding feature corresponding to the source format request data.

[0047] In an embodiment of the present application, 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 spliced to form the first request embedding feature. In addition, the embedding process can be implemented by a word embedding model. For example, the local content of the source format request data can be "location: New York". In this way, through word segmentation embedding process, 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] In this way, 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 processing method helps the model understand the role of punctuation marks in text, especially in source format request data with complex structures.

[0050] Step S121c: Based on the attention mechanism, perform first associated semantic mining on the first request embedding feature and output the corresponding first request associated feature.

[0051] In an embodiment of the present application, after obtaining the first request embedded feature, the first associated semantic mining can be performed on the first request embedded feature based on the attention mechanism, and the corresponding first request associated feature can be output, that is, the association information between the internal semantics of the first request embedded feature is mined through the attention mechanism.

[0052] Step S121d: Based on the attention mechanism, perform second associated semantic mining on the first request embedding feature and output the corresponding second request associated feature.

[0053] In an embodiment of the present application, after obtaining the first request embedding feature, a second associated semantic mining can be performed on the first request embedding feature based on an attention mechanism to output a corresponding second request associated feature. The second associated semantic mining is different from the first associated semantic mining to capture different associated semantic information.

[0054] Step S121e: Aggregate the first request association feature and the second request association feature to form a corresponding first request coding feature.

[0055] In an embodiment of the present application, 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 coding feature. In other words, the associated semantic information in the first request association feature can be captured or mined in two different ways. In this way, the mined associated semantic information can be more comprehensive, and therefore, through further aggregation, the semantic representation ability of the formed first request coding feature can be improved. In addition, the aggregation method can be mean calculation, or it can be splicing first, and then downsampling and other processing.

[0056] It is understandable that, in the above step S121c, the specific manner of performing the first associated semantic mining on the first request embedded feature is not limited. For example, in an alternative embodiment, in order to be able to sequentially fuse different associated semantic information in the process of capturing associated semantic information, the above step S121c may further include the following contents (combined with Figure 3 ): First, a sliding window segmentation can be performed on the first request embedding feature 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, wherein 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 encoding sub-network during the training process; 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, and when the sliding window segmentation feature does not belong to the first sliding window segmentation feature, based on the attention mechanism, semantic information having an associated relationship with 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; that is, based on the mining output feature corresponding to the previous sliding window segmentation feature, a cross-attention process (Cross-Attention, wherein the query (Query) comes from the mining output feature corresponding to the previous sliding window segmentation feature, and the key (Key) and value (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, and then the attention feature and the current sliding window segmentation feature can be averaged to obtain the corresponding mining output feature; Finally, the corresponding first request-related feature can be determined based on at least the mining output feature corresponding to the last sliding window segmentation feature; illustratively, the mining output feature corresponding to the last sliding window segmentation feature can be directly determined as the first request-related feature.

[0057] It is understandable that, in the above step S121d, the specific method of performing the second associated semantic mining on the first request embedded feature is not limited and can be selected according to actual needs. For example, in an alternative embodiment, in order to pay attention to important semantic information as much as possible in the process of mining associated semantic information, the above step S121d can further include the following content (combined with Figure 4 ): First, based on a predetermined first masking matrix and a second masking matrix, the first request embedding feature can be masked to form a first request masking feature and a second request masking feature, respectively. The first masking matrix and the second masking matrix belong to network parameters in the first encoding sub-network and are updated and formed during the training of the first encoding sub-network. In addition, the first masking matrix and the second masking matrix have the same size as the first request embedding feature, and the parameters in the first masking matrix and the second masking matrix are composed of 1 and 0. In this way, the first masking matrix and the first request embedding feature can be bit-wise multiplied (i.e., the parameters at corresponding positions are multiplied) so that the positions of the parameters equal to 0 in the first masking matrix correspond to the corresponding parameters in the first request embedding feature and are masked. In addition, the second masking matrix and the first request embedding feature can be bit-wise multiplied so that the positions of the parameters equal to 0 in the second masking matrix correspond to the corresponding parameters in the first request embedding feature and are masked. In this way, the two masking matrices can be used to mask and hide parameters at different positions (or importance) in the first request embedding feature. Secondly, based on the attention mechanism, semantic information associated with the second request masked feature can be mined from the first request masked feature to obtain the first masked associated feature. In other words, based on the second request masked feature (i.e., the query (Query) comes from the second request masked feature), a cross-attention process can be performed on the first request masked feature (i.e., the key (Key) and value (Value) come from the first request masked feature). The obtained attention feature is then averaged with the first request masked feature to obtain the first masked associated feature. Then, based on the attention mechanism, semantic information associated with the first request masked feature can be mined from the second request masked feature to obtain a second masked associated feature. In other words, based on the first request masked feature (i.e., the query (Query) comes from the first request masked feature), a cross-attention process can be performed on the second request masked feature (i.e., the key (Key) and value (Value) come from the second request masked feature). The obtained attention feature is then averaged with the second request masked feature to obtain the second masked associated feature. Finally, the corresponding second request association feature can be determined based on the first mask association feature and the second mask association feature. Exemplarily, the first mask association feature and the second mask association feature can be averaged to obtain the second request association feature.

[0058] It is understood that, in the above step S122, the specific method of encoding the target data format is not limited and can be selected according to actual needs. For example, in an alternative embodiment, in order to improve the efficiency of encoding the target data format, the above step S122 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, embedding processing can be performed on the target data format 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. The embedding processing process is as described above. Then, based on the second request embedded 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 embedded feature can be directly used as the second request encoding feature.

[0059] It is necessary to further explain the above steps S120 and S130 that, in order to enable the target protocol conversion model to reliably convert request data of different data formats, that is, to ensure the effective execution of steps S120 and S130, before the above steps S120 and S130, the API protocol conversion method may further include the following: First, a sample API protocol request message may be obtained, and sample format request data requiring data format conversion may be parsed from the sample API protocol request message, and a sample data format for converting the sample format request data may be determined. For details, please refer to the explanation of step S110 above. Secondly, the sample format request data and the sample data format can be encoded using a semantic encoding network in the candidate protocol conversion model, and corresponding sample request encoding features can be output. The candidate protocol conversion model is a neural network model to be trained, and the candidate protocol conversion model also includes a semantic decoding network. During the encoding process, the semantic encoding network mines associated semantic information between local data in the sample format request data based on an attention mechanism. For details, please refer to the relevant explanation of step S120 above. Then, the sample request encoding feature may be decoded by the semantic decoding network to output corresponding sample format request data, wherein the data format of the sample format request data is the sample data format, and reference may be made to the relevant explanation of step S130 above. Finally, based on the error between the sample format request data and the predetermined request data label (i.e., the request data in the sample data format, which may be written by the corresponding developer), the parameters of the candidate protocol conversion model can be updated to form a target protocol conversion model. For example, the parameters can be updated in a direction that reduces the error until the error converges, thereby forming the target protocol conversion model. Furthermore, the error can be calculated as a mean square error. Specifically, the output of the semantic decoding network can be a probability distribution for each time step (as described above). Thus, the mean square error between this probability distribution and the probability distribution of the corresponding words in the request data label can be calculated. For example, for the first time step, the mean square 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 label (in this probability distribution, only the probability corresponding to the first word is 1, and the probability corresponding to other words is 0). Based on this, after obtaining the mean square error corresponding to the output of each time step, the sum of the mean square errors can be calculated to obtain the final error. Alternatively, in other embodiments, in order to encourage the model to output a high probability of correct words and penalize a high probability of incorrect words, a cross entropy error may be used. For example, for the output of one time step, the cross entropy error may be: ; Among them, L represents the cross entropy error, y i represents the probability distribution corresponding to the label (the actual word is 1, and the other words are 0), p i represents the probability distribution of the decoding output of the semantic decoding network, and N represents the size of the vocabulary (the number of words included).

[0060] In addition, in a specific application, the sample format request data in JSON format may be: { "user": { "name": "John", "age": 30, "email": "john@example.com" } }.

[0061] Accordingly, the request data tag in XML format can be: <user> <name> John< / name> <age> 30< / age> <email> john@example.com< / email> < / user> .

[0062] Combine Figure 5The embodiment of the present application further provides an API protocol conversion device applicable to the above 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 used to obtain the source API protocol request information, and 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. Figure 2 As shown in step S110, for the relevant content of the request data processing module, reference can be made to the above description of step S110.

[0064] 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, wherein the target protocol conversion model is a trained neural network model, and the target protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines the associated semantic information between the local data in the source format request data based on the attention mechanism during the encoding process. In the embodiment of the present application, the request data encoding module can be used to perform Figure 2 As shown in step S120, for the relevant content of the request data encoding module, reference can be made to the above description of step S120.

[0065] The request feature decoding module is used to decode the target request encoding feature 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. In the embodiment of the present application, the request feature decoding module can be used to perform Figure 2 As shown in step S130, for the relevant content of the request feature decoding module, reference can be made to the above description of step S130.

[0066] In an embodiment of the present application, corresponding to the above-mentioned API protocol conversion method applied to the electronic device, a computer-readable storage medium is also provided, in which a computer program is stored. When the computer program is run, the various steps of the API protocol conversion method are executed.

[0067] Among them, the steps executed when the aforementioned computer program is running will not be described here one by one, and reference can be made to the explanation of the API protocol conversion method mentioned above.

[0068] In summary, the API protocol conversion method, device, equipment and medium provided by the present application first obtain the source API protocol request information, and 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; secondly, the source format request data and the target data format are encoded through the semantic encoding network in the target protocol conversion model, and the target request encoding features are output; then, the target request encoding features are decoded through the semantic decoding network, and the target format request data is output. Based on the above content, since the data format conversion is performed through the semantic encoding network and the 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 therein can be utilized, so that the request data can be better understood, thereby achieving reliable conversion. Compared with the existing technology that uses a simple conversion rule such as an API adapter to achieve conversion, it has higher reliability for request data with low certainty such as abnormal or unconventional data structures. Therefore, the problem of relatively low reliability of API protocol conversion in the existing technology can be improved.

[0069] In the several embodiments provided in the embodiments of the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device and method embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0070] In addition, the functional modules in each embodiment of the present 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 functions are implemented in the form of software 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 the present application, or the portion that contributes to the prior art, or the portion 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 for causing a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. It should be noted that, in this document, the terms "comprise," "include," or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article, or device. Without further constraints, an element defined by the phrase "comprises a..." does not preclude the existence of additional identical elements in the process, method, article or apparatus that includes the element.

[0072] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.

Claims

1. An API protocol conversion method, characterized in that: include: Obtaining source API protocol request information, parsing source format request data that needs to be converted from the source API protocol request information, and determining a target data format for converting the source format request data; Encoding the source format request data and the target data format through a semantic encoding network in a target protocol conversion model, and outputting corresponding target request encoding features, wherein the target protocol conversion model is a trained neural network model, the target protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; The target request encoding feature is decoded through the semantic decoding network to output 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 corresponding target request coding features includes: The source format request data is encoded by a first encoding sub-network included in a semantic encoding network in a target protocol conversion model to form a corresponding first request encoding feature, wherein the first encoding sub-network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; Encoding the target data format through a second encoding subnetwork 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 spliced through the encoding splicing sub-network included in the semantic encoding network to form a 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 through the first encoding sub-network included in the semantic encoding network in the target protocol conversion model to form a corresponding first request encoding feature includes: Loading the source format request data into a first encoding subnetwork included in a semantic encoding network in a target protocol conversion model; Performing embedding processing on the source format request data to form a first request embedding feature corresponding to the source format request data, wherein the first request embedding feature includes an embedding feature of each word in the source format request data; Based on the attention mechanism, performing first associated semantic mining on the first request embedding feature, and outputting the corresponding first request associated feature; Based on the attention mechanism, performing second association semantic mining on the first request embedding feature and outputting corresponding second request association features, wherein the second association semantic mining is different from the first association semantic mining to capture different association semantic information; Aggregate the first request correlation feature and the second request correlation feature to form a corresponding first request encoding feature.

4. The API protocol conversion method according to claim 3, characterized in that: The step of performing first associated semantic mining on the first request embedding feature based on the attention mechanism and outputting the corresponding first request associated feature includes: Performing sliding window segmentation on the first request embedding feature to form a sliding window segmentation sequence corresponding to the first request embedding feature, wherein the sliding window segmentation sequence includes a plurality of 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, using the sliding window segmentation feature as the corresponding mining output feature; and when the sliding window segmentation feature does not belong to the first sliding window segmentation feature, mining semantic information having an associated relationship with the mining output feature corresponding to the previous sliding window segmentation feature from the sliding window segmentation feature based on an attention mechanism to obtain a corresponding mining output feature; Based on at least the mining output feature corresponding to the last sliding window segmentation feature, a 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 associated semantic mining on the first request embedding feature based on the attention mechanism and outputting the corresponding second request associated feature includes: Based on a predetermined first masking matrix and a second masking matrix, masking the first request embedding feature to form a first request masked feature and a second request masked feature, respectively, wherein the first masking matrix and the second masking matrix are network parameters in the first encoding sub-network and are updated during the training of the first encoding sub-network; Based on the attention mechanism, semantic information associated with the second request masked feature is mined from the first request masked feature to obtain a first masked associated feature; Based on the attention mechanism, semantic information associated with the first request masked feature is mined from the second request masked feature to obtain a second masked associated feature; Based on the first mask-related feature and the second mask-related feature, a corresponding second request-related feature is determined.

6. The API protocol conversion method according to claim 2, characterized in that: The step of encoding the target data format by the second encoding sub-network included in the semantic encoding network to form a corresponding second request encoding feature includes: Loading the target data format into the second encoding subnetwork included in the semantic encoding network; Performing embedding processing on the target data format to form a second request embedding feature corresponding to the target data format, wherein the second request embedding feature includes an embedding feature of each word in the target data format; Based on the second request embedded feature, a corresponding second request encoding feature is determined.

7. The API protocol conversion method according to any one of claims 1 to 6, characterized in that: Also includes: Obtaining sample API protocol request information, parsing sample format request data that needs to be converted from the sample API protocol request information, and determining a sample data format for converting the sample format request data; Encoding the sample format request data and the sample data format through a semantic encoding network in a candidate protocol conversion model, and outputting corresponding sample request encoding features, wherein the candidate protocol conversion model is a neural network model to be trained, and the candidate protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the sample format request data based on an attention mechanism during the encoding process; Decoding the sample request encoding feature through the semantic decoding network and outputting 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 predetermined request data label, the parameters of the candidate protocol conversion model are updated to form a target protocol conversion model.

8. An API protocol conversion device, characterized in that: include: a request data processing module, configured 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 a target data format for converting the source format request data; a request data encoding module, configured to encode the source format request data and the target data format through a semantic encoding network in a target protocol conversion model, and output corresponding target request encoding features, wherein the target protocol conversion model is a trained neural network model, the target protocol conversion model also includes a semantic decoding network, and the semantic encoding network mines associated semantic information between local data in the source format request data based on an attention mechanism during the encoding process; The request feature decoding module is used to decode the target request encoding feature 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 for storing computer programs; A processor connected to the memory, used to execute the computer program stored in the memory to implement the API protocol conversion method described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when running, executes the API protocol conversion method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Clinical manifestation information extracting method of Chinese electronic medical record data and equipment

    CN110223742A

  • Virtual power plant multi-protocol adaptive access device

    CN117749915A

  • Method and device for automatically converting cross-format document into Markdown document and form enhancement method and system

    CN119598980A

  • Natural language to API conversion

    CN119668575A

  • Multi-platform store normalization method

    CN119807399A