Intelligent software code type inference method, system, device and storage medium

Through knowledge graph and graph neural network technology, the prediction of JavaScript function parameters and return value types is solved, and the problem of type vocabulary restriction and prediction in JavaScript type inference is improved, and the code security and quality are improved.

CN114528223BActive Publication Date: 2024-12-27INST FOR INTERDISCIPLINARY INFORMATION CORE TECH XIAN CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210182130.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-25
Publication Date
2024-12-27
Estimated Expiration
2042-02-25

AI Technical Summary

Technical Problem

JavaScript type inference has problems such as type vocabulary limitation, inconsistent prediction results, and insufficient type prediction accuracy, resulting in software code defects and insufficient security.

Method used

The knowledge graph is used to represent the function type information and abstract syntax tree structure in the JavaScript source code, and node message propagation and update through the graph neural network, predict function parameters and return value types, and improve code security and robustness.

Benefits of technology

Predict function parameters and return value types before source code execution, improve the security and quality of software code, and enhance the robustness and reliability of intelligent software.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114528223B_ABST
    Figure CN114528223B_ABST
Patent Text Reader

Abstract

The present invention provides a method, system, deployment method, device and storage medium for inferring the type of intelligent software code, including: obtaining intelligent software source code with JSDoc annotations, traversing the abstract syntax tree of the source code, extracting topic semantic information and AST structure information of function types in the source code, and forming a json file; representing with a knowledge graph structure, and constructing a knowledge graph; representing node features in the knowledge graph data structure as a triple form, selecting an appropriate knowledge graph representation algorithm, and performing representation learning of node information; obtaining the final node state vector; constructing a prediction layer of a graph neural network, and performing probability type prediction based on the node information after acquisition and propagation; and outputting JavaScript intelligent software source code with all inference types based on the probability type prediction. The present invention improves the security and robustness of software code, better improves software quality, and enables intelligent software to better serve users.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of intelligent software analysis, and in particular relates to an intelligent software code type inference method, system, device and storage medium. Background Art

[0002] As the application of intelligent software is also vigorously promoted in all walks of life, in order to make intelligent software better serve users, developers should continuously improve and enhance the performance of internal software models or different modules. At present, more and more intelligent software is developed internally using JavaScript language, and JavaScript is a dynamic type, weak type language, which does not use strict data types. If a potential bug is caused by unlabeled types, it will only be triggered at runtime, which will introduce program code defects, affect code security, and increase program vulnerability. Therefore, in order to enable developers to have a deep understanding of the software code structure, accurately explore program code vulnerabilities, and improve the security and robustness of JavaScript intelligent software code, type inference of JavaScript intelligent software code has become a key issue.

[0003] Currently, JavaScript type inference mainly has the following problems:

[0004] 1) Type vocabulary limitation. If inference is limited to the limited type dictionary observed during training, it will not be possible to predict any user-defined data types.

[0005] 2) Inconsistent prediction results: Different types are predicted for entities appearing in different positions.

[0006] 3) The accuracy of type prediction needs to be improved. Summary of the invention

[0007] The present invention proposes an intelligent software code type inference method, system, device and storage medium to solve the above technical problems. The method can predict function parameters and return value types before the source code is actually executed, improve the security and robustness of the software code, better improve the software quality, and enable intelligent software to better serve users.

[0008] In order to achieve the above object, the present invention adopts the following technical solutions:

[0009] An intelligent software code type inference method, comprising:

[0010] Get the JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file;

[0011] For the json file, the topic semantic information and AST structure information of the function type are represented by a knowledge graph structure to construct a knowledge graph;

[0012] The node features in the knowledge graph data structure are represented as triples, and an appropriate knowledge graph representation algorithm is selected to perform representation learning of the node information; after learning, feature vectors of the entity set and the relationship set are obtained, and the feature vectors are used as inputs of the graph neural network to perform node message propagation inside the graph neural network. The message propagation is divided into three stages: the message propagation stage, the aggregation stage, and the update stage, and the final node state vector is obtained;

[0013] Construct the prediction layer of the graph neural network and make probability type prediction based on the node information after propagation;

[0014] Output JavaScript intelligent software source code with all inference types according to the probability type prediction.

[0015] As a further improvement of the present invention, the extracting of topic semantic information and AST structure information related to type inference in the input program specifically includes:

[0016] For JavaScript intelligent software source code with JSDoc annotations, obtain the corresponding abstract syntax tree, use babel / parser to parse the source code syntax tree, and traverse the nodes of specific function types in its abstract syntax tree;

[0017] Extract the topic semantic information and AST structure information of the function type in the source code. The topic semantic information and AST structure information include the function name, parameter information, function-related comments, comments related to the function return value type, return value type and calling relationship. A json file is formed based on the topic semantic information and AST structure information of the function type.

[0018] As a further improvement of the present invention, the nodes in the directed graph of the knowledge graph data structure represent function entities, the other edges connected to the nodes represent function-related attributes, and there are directed edges with calling relationships or control flow relationships between nodes.

[0019] As a further improvement of the present invention, the node features in the knowledge graph data structure are represented as triples, specifically including:

[0020] According to the generated node information, the information is represented as a set of triples of (function, attribute, attribute value). According to the basic idea of ​​the TransE algorithm, the entities are mapped according to the relationships and the translation equation is constructed. The input parameters are the triple set S = {(h, l, t)}, the entity set E and the relationship set L, the range γ and the embedding dimension k.

[0021] For each entity, it is randomly initialized to a vector of specified dimension;

[0022] Randomly extract b vectors from the training triple set, and break each triple into pieces to generate negative examples;

[0023] Calculate the potential energy function and use the gradient descent algorithm to update h, l, t, and continuously optimize the vector representation of entities and relationships;

[0024] Get vector representations of entity sets and relationship sets.

[0025] As a further improvement of the present invention, the method of updating h, l, t by using a gradient descent algorithm to continuously optimize the vector representation of entities and relationships specifically includes:

[0026] The potential energy of this triple is expressed by the two-norm of the difference between the sum of h and l and t. The potential energy calculation is as follows:

[0027] f(h,l,t)=‖h+lt‖2

[0028] Among them, h represents the vector corresponding to the head entity, l represents the vector corresponding to the relationship, and t represents the vector corresponding to the tail entity. The two-norm calculation formula is:

[0029]

[0030] Determine whether it is the optimal vector representation based on the potential energy. If so, output it. If not, randomly select b vectors from the training triple set again.

[0031] As a further improvement of the present invention, the node message propagation is performed inside the graph neural network, the node feature embedding vector is used as the initial state of the node, and the edge embedding vector is used to transmit messages between related edges, which is divided into three stages, specifically including:

[0032] In the message passing phase, the function of the message function is to generate a message vector that transmits node u to neighbor node v. The node v encodes the type information in the node u; in the knowledge graph, the characteristics of the relationship are used as the embedding vector The relation feature vector is then embedded into the message vector via the following message function:

[0033]

[0034] in, is the learning parameter, represents the message vector at the Kth step, represents the state vector of node u at the K-1th step, e uv Represents the relation feature vector.

[0035] In the message aggregation phase, the message vector m is calculated for all nodes u∈N(v) uv Finally, the integration function integrates the message vector into a vector Assigned to node v, node v now carries the information contained in other nodes u, and the specific calculation used is as follows:

[0036]

[0037] in, represents the message vector at the Kth step, Represents the integrated vector of node v after integrating the information of other nodes at the Kth step.

[0038] In the message update phase, when inferring types, type information is propagated to multiple function nodes in multiple rounds of propagation. The gated recurrent unit is used as the update function. The specific calculation used is as follows:

[0039]

[0040] in, It represents the integrated vector after node v integrates the information of other nodes at the Kth step, represents the state vector of node v at step K-1, Represents the final state vector of node v at the Kth step.

[0041] As a further improvement of the present invention, the probability type prediction is performed based on the acquired propagated node information, specifically including:

[0042] According to the generated final node state vector, a fully connected layer and a softmax function are used to convert the final node state after K rounds of message propagation into a probability distribution over candidate types, and the most likely type is output as the inferred type of the node.

[0043] An intelligent software code type inference system, comprising:

[0044] The acquisition module is used to obtain JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file;

[0045] A construction module is used to represent the topic semantic information and AST structure information of the function type in the json file using a knowledge graph structure to construct a knowledge graph;

[0046] A learning module is used to represent the node features in the knowledge graph data structure as triples, select an appropriate knowledge graph representation algorithm, and perform representation learning of node information; after learning, feature vectors of entity sets and relationship sets are obtained, and the feature vectors are used as inputs of the graph neural network to perform node message propagation inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage, and update stage, and the final node state vector is obtained;

[0047] The prediction module is used to build the prediction layer of the graph neural network and perform probability type prediction based on the node information after propagation.

[0048] The inference module is used to predict and output JavaScript intelligent software source code with all inference types according to the probability type.

[0049] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the intelligent software code type inference method when executing the computer program.

[0050] A computer-readable storage medium stores a computer program, which implements the steps of the intelligent software code type inference method when executed by a processor.

[0051] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0052] Aiming at the situation that potential bugs may occur in JavaScript intelligent software due to types, thus causing software defects, this method uses dependency extraction technology to construct a knowledge graph to represent the program, and a graph neural network to infer the function parameters and return value types. The node information in the graph is represented and learned, and then the graph neural network is used to propagate messages between nodes to predict the entity probability type. Through the above method, the function parameters and return value types can be predicted before the source code is actually executed, which improves the security and robustness of the software code, better improves the software quality, and enables intelligent software to better serve users.

[0053] The knowledge graph is further constructed by using a graph to represent the program. The nodes in the graph represent dependent extracted functions, and the node attributes include the topic semantic information of the function, AST structure information such as function-related comments, parameter information, etc. The present invention extracts natural language information in the source code and structural information in the AST to construct a knowledge graph, perform program representation, and infer information that is more intuitive and comprehensive. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 It is the overall flow chart of the method of the present invention;

[0055] Figure 2 A flow chart of the method for extracting node information from JavaScript source code according to the present invention;

[0056] Figure 3 A flow chart of a method for converting a feature triple into a feature vector according to the present invention;

[0057] Figure 4 This is a flow chart of the method for propagating messages within a neural network of the present invention;

[0058] Figure 5 A schematic diagram of the knowledge graph structure provided for a specific embodiment of the present invention;

[0059] Figure 6 Schematic diagram of a data supplementation system for calculating tags in a scenario where time series data is disconnected and retransmitted;

[0060] Figure 7 It is a schematic diagram of the structure of an electronic device according to a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0061] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.

[0062] The following detailed description is an exemplary description, which is intended to provide further detailed description of the present invention. Unless otherwise specified, all technical terms used in the present invention have the same meaning as those generally understood by those skilled in the art to which the present application belongs. The terms used in the present invention are only for describing specific embodiments, and are not intended to limit exemplary embodiments according to the present invention.

[0063] The present invention provides a method for inferring the type of intelligent software code. JavaScript intelligent software uses weakly typed and dynamically typed JavaScript as the main language, and does not use strict data types. The lack of type information may lead to potential bugs, which will be triggered only at runtime, resulting in software defects and increasing program vulnerability. Therefore, the present invention uses a knowledge graph to represent the program, and the nodes in the graph represent the function entities that depend on extraction. The node attributes contain the topic semantic information of the function, AST structure information such as function-related annotations, parameter information, etc. The directed edges between nodes are represented as call relationships or control flow relationships between functions, and the node information in the graph is represented and learned, and a graph neural network is used to propagate messages between nodes to predict the probability types of function parameters and return values. The goal of this method is to convert the given input source code containing JSDoc comments into a knowledge graph structure, and to infer the unannotated types of JavaScript functions on the graph structure data.

[0064] The specific implementation of the JavaScript intelligent software code type inference method based on the knowledge graph of the present invention is described in detail below with reference to the accompanying drawings.

[0065] Figure 1 This is an overall flow chart of the JavaScript intelligent software code type inference method based on the knowledge graph of the present invention;

[0066] The present invention discloses a JavaScript intelligent software code type inference method based on knowledge graph, comprising the following steps:

[0067] S1: Analyze and extract JavaScript intelligent software source code, focus on source code containing JSDoc comments, traverse the abstract syntax tree of the source code, extract topic semantic information and AST structure information of function types, such as function-related comments in text comments, parameter information, etc.

[0068] Figure 2 The present invention is a flow chart of the method for extracting node information in source code.

[0069] Specifically, it can be divided into the following steps:

[0070] S101: Input the program code containing JSDoc comments, obtain the corresponding abstract syntax tree, use babel / parser to parse the source code syntax tree, and traverse the nodes of specific function types in its abstract syntax tree.

[0071] S102: Extract the function name, parameter information (including parameter name, parameter-related comments, parameter type), function-related comments, function return value type-related comments, return value type, call relationship and other topic semantic information and AST structure information of the function, and output them as a json file.

[0072] S2: Define the knowledge graph data structure to represent the program. According to the entity information json file of step S1, the node represents the function entity, and the edge connected to the node represents the function-related attributes, such as name, comment, param, return type, etc. There are directed edges between function nodes with calling relationships or control flow relationships.

[0073] Specifically, the defined knowledge graph structure corresponds to the node output in the json file one by one. The attributes include the function-related comments, function names, function parameter sequences, function return values, metadata (row and column numbers, internal variables, node IDs, etc.) obtained from the syntax tree, etc. The parameter sequence includes parameter names, parameter-related comments, parameter types, etc. Among them, if the parameter type or return value type is not found in the JSDoc comment, the output is empty, which means that the part of the unknown type needs to be inferred using the known type.

[0074] Step S3: Represent the node features in the knowledge graph as triples, select an appropriate knowledge graph representation algorithm, and perform representation learning of the node information.

[0075] Figure 3 Flowchart of the method for converting knowledge graph feature triples into feature vectors in the present invention.

[0076] Specifically, it can be divided into the following steps:

[0077] S301: According to the node information generated in step S102, the information is represented as a set of triples of (function, attribute, attribute value). According to the basic idea of ​​the TransE algorithm, the entities are first mapped according to the relationship, and then the translation equation is constructed with the relationship. The input is a triple set S = {(h, l, t)}, an entity set E and a relationship set L, a range γ and an embedding dimension k.

[0078] S302: For each entity, first randomly initialize it to a vector of a specified dimension.

[0079] S303: randomly extract b vectors from the training triples, break each triple (randomly replace the head or tail, but not both) to generate negative examples.

[0080] S304: Calculate the potential energy function, use the gradient descent algorithm to update h, l, t, and continuously optimize the vector representation of entities and relationships. The potential energy of this triple is represented by the two-norm of the difference between the sum of h and l and t. For a correct triple, the potential energy is as low as possible, while for an incorrect triple, the potential energy is as high as possible. The potential energy calculation formula is as follows:

[0081] f(h,l,t)=‖h+lt‖2

[0082] Among them, h represents the vector corresponding to the head entity, l represents the vector corresponding to the relationship, and t represents the vector corresponding to the tail entity. The two-norm calculation formula is:

[0083]

[0084] Step S4: After learning, the feature vector representation of the entity set and the relationship set is obtained, which is used as the input of the graph neural network. Node message propagation is performed inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage and update stage to obtain the final state of the node.

[0085] Figure 4 This is a flow chart of the method for message propagation within a neural network according to the present invention.

[0086] Specifically, it can be divided into the following steps:

[0087] S401: Message propagation phase. The function of the message function is to generate a message vector that transmits node u to neighbor node v. The node v encodes the type information in u. In the knowledge graph, the features of the relationship are used as embedding vectors The relation feature vector is then embedded into the message vector via the following message function:

[0088]

[0089] in, is the learning parameter, represents the message vector at the Kth step, represents the state vector of node u at the K-1th step, e uv Represents the relation feature vector.

[0090] S402: Message aggregation phase. Calculate the message vector m for all nodes u∈N(v) uv Finally, the integration function integrates the message vector into a vector Assigned to node v, the specific calculation formula used is as follows:

[0091]

[0092] in, represents the message vector at the Kth step, Represents the integrated vector of node v after integrating the information of other nodes at the Kth step.

[0093] S403: Message update phase. During type inference, type information may be propagated to multiple function nodes in multiple rounds of propagation. A gated recurrent unit is used as the update function, and the specific calculation formula used is as follows:

[0094]

[0095] in, It represents the integrated vector after node v integrates the information of other nodes at the Kth step, represents the state vector of node v at step K-1, Represents the final state vector of node v at the Kth step.

[0096] Step S5: Construct the prediction layer of the graph neural network, obtain the node information after propagation, and perform probabilistic type prediction. Furthermore, in step S5, a fully connected layer and a softmax function are used to convert the final node state after K rounds of message propagation into a probability distribution on candidate types, and the most likely type is output as the inferred type of the node.

[0097] A further improvement of the present invention is that in step S1, babel / parser is used to extract function entity information on the syntax tree of the source code containing JSDoc comments, and the extracted complete information provides data support for the subsequent knowledge graph construction.

[0098] A further improvement of the present invention is that in step S2, the program is represented by a knowledge graph structure so that the nodes carry the corresponding semantic or structural information more comprehensively in the form of attributes or relationships, and the information is clear and intuitive.

[0099] In order to make the purpose, features and advantages of the present invention more obvious and understandable, the specific implementation methods of the present invention are described in detail below in conjunction with specific embodiments.

[0100] An intelligent software code type inference method comprises the following steps:

[0101] Take for example a snippet of JavaScript source code containing JSDoc comments:

[0102]

[0103]

[0104] S1: Analyze and extract JavaScript intelligent software source code, pay attention to the source code containing JSDoc comments, and output it as a file containing function-related attributes, such as function name, parameter information (including parameter name, parameter-related comments, parameter type), function-related comments, function return value type-related comments, return value type, metadata (row and column number, internal variables, node id, etc.). The output file structure is organized in the following form:

[0105]

[0106] S2: Define the knowledge graph data structure representation program. According to the entity information json file of step S1, the node represents the function entity, and the edge connected to the node represents the function-related attributes, such as name, comment, param, return type, etc. There are directed edges between function nodes that have call relationships or control flow relationships. The knowledge graph structure is as follows: Figure 5 Organized in the form shown.

[0107] Step S3: Represent the node features in the knowledge graph as triples, and select the TransE algorithm to learn the representation of node information. Preprocess the knowledge graph information into a triple set file train.txt, and preprocess the entity set and relationship set mapping files into entity2id.txt and relation2id.txt, which are used as input for the TransE algorithm. Here, the WN18 public dataset is used as an example of TransE input, and the file structure is organized in the following form:

[0108]

[0109] train.txt

[0110]

[0111] Set the input parameters, range to 1.0, embedding dimension to 50, learning rate to 0.01, and use the two norm as follows:

[0112] transE=TransE(entity_set,relation_set,triple_list,embedding_dim=50,,lr=0.01,margin=1.0,norm=2)

[0113] Step S4: After learning, the feature vector representation of the entity set and the relationship set is obtained, and the entity vector representation and relationship vector representation files are output as shown below:

[0114] entity_embedding.txt:

[0115]

[0116] relation_embedding.txt:

[0117]

[0118] The knowledge graph information is organized in the above way, and the vector representation files of the output entity sets and relationship sets are used as the input of the graph neural network. Node message propagation is performed inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage and update stage to obtain the final state of the node.

[0119] Step S5: Construct the prediction layer of the graph neural network, obtain the node information after propagation, and perform probabilistic type prediction. Furthermore, in step S5, a fully connected layer and a softmax function are used to convert the final node state after K rounds of message propagation into a probability distribution on candidate types, and the most likely type is output as the inferred type of the node.

[0120] Assuming that the candidate type is T = {number, boolean, string, array}, based on the probability distribution of the candidate type is [0.3, 0.7, 0.2, 0.1], it is inferred that the most likely type is boolean.

[0121] After training, the final output contains source code files of known types and inferred types.

[0122] In summary, the method of the present invention can automatically analyze and infer types for function parameters and return values ​​in JavaScript intelligent software, which improves efficiency and accuracy compared to manual type annotation. Therefore, the present invention provides an idea for JavaScript type inference, that is, using the natural language information in the source code and the structural information in the AST to construct a knowledge graph, and then using graph neural network technology on the knowledge graph to perform type inference, which is the application of emerging artificial intelligence technology in the field of intelligent software analysis.

[0123] like Figure 6 As shown, the present invention also provides an intelligent software code type inference system, comprising:

[0124] The acquisition module is used to obtain JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file;

[0125] A construction module is used to represent the topic semantic information and AST structure information of the function type in the json file using a knowledge graph structure to construct a knowledge graph;

[0126] A learning module is used to represent the node features in the knowledge graph data structure as triples, select an appropriate knowledge graph representation algorithm, and perform representation learning of node information; after learning, feature vectors of entity sets and relationship sets are obtained, and the feature vectors are used as inputs of the graph neural network to perform node message propagation inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage, and update stage, and the final node state vector is obtained;

[0127] The prediction module is used to build the prediction layer of the graph neural network and perform probability type prediction based on the node information after propagation.

[0128] The inference module is used to predict and output JavaScript intelligent software source code with all inference types according to the probability type.

[0129] like Figure 7As shown, the third object of the present invention is to provide an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the intelligent software code type inference method when executing the computer program.

[0130] The intelligent software code type inference method comprises:

[0131] Get the JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file;

[0132] For the json file, the topic semantic information and AST structure information of the function type are represented by a knowledge graph structure to construct a knowledge graph;

[0133] The node features in the knowledge graph data structure are represented as triples, and an appropriate knowledge graph representation algorithm is selected to perform representation learning of the node information; after learning, feature vectors of the entity set and the relationship set are obtained, and the feature vectors are used as inputs of the graph neural network to perform node message propagation inside the graph neural network. The message propagation is divided into three stages: the message propagation stage, the aggregation stage, and the update stage, and the final node state vector is obtained;

[0134] Construct the prediction layer of the graph neural network and make probability type prediction based on the node information after propagation;

[0135] Output JavaScript intelligent software source code with all inference types according to the probability type prediction.

[0136] A fourth object of the present invention is to provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the intelligent software code type inference method are implemented.

[0137] The intelligent software code type inference method comprises:

[0138] Get the JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file;

[0139] For the json file, the topic semantic information and AST structure information of the function type are represented by a knowledge graph structure to construct a knowledge graph;

[0140] The node features in the knowledge graph data structure are represented as triples, and an appropriate knowledge graph representation algorithm is selected to perform representation learning of the node information; after learning, feature vectors of the entity set and the relationship set are obtained, and the feature vectors are used as inputs of the graph neural network to perform node message propagation inside the graph neural network. The message propagation is divided into three stages: the message propagation stage, the aggregation stage, and the update stage, and the final node state vector is obtained;

[0141] Construct the prediction layer of the graph neural network and make probability type prediction based on the node information after propagation;

[0142] Output JavaScript intelligent software source code with all inference types according to the probability type prediction.

[0143] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0144] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0145] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0146] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. An intelligent software code type inference method, characterized in that: include: Get the JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file; For the json file, the topic semantic information and AST structure information of the function type are represented by a knowledge graph structure to construct a knowledge graph; Representing node features in the knowledge graph data structure as triples, selecting an appropriate knowledge graph representation algorithm, and performing representation learning of node information; After learning, the feature vectors of the entity set and the relationship set are obtained. The feature vectors are used as the input of the graph neural network. Node message propagation is performed inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage and update stage, and the final node state vector is obtained. Construct the prediction layer of the graph neural network and make probability type prediction based on the node information after propagation; Outputting JavaScript intelligent software source code with all inference types according to the probability type prediction; The step of expressing the node features in the knowledge graph data structure as triples specifically includes: According to the generated node information, the information is represented as a set of triples of (function, attribute, attribute value). According to the basic idea of ​​the TransE algorithm, the entities are mapped according to the relationships and the translation equation is constructed. The input parameters are the triple set S={(h,l,t)}, the entity set E and the relationship set L, the range γ and the embedding dimension k. For each entity, it is randomly initialized to a vector of specified dimension; Randomly extract b vectors from the training triple set, and break each triple into pieces to generate negative examples; Calculate the potential energy function and use the gradient descent algorithm to update h, l, t, and continuously optimize the vector representation of entities and relationships; Obtain vector representations of entity sets and relationship sets; The method of updating h, l, t by using the gradient descent algorithm to continuously optimize the vector representation of entities and relationships specifically includes: The potential energy of this triple is expressed by the two-norm of the difference between the sum of h and l and t. The potential energy calculation is as follows: Among them, h represents the vector corresponding to the head entity, l represents the vector corresponding to the relationship, and t represents the vector corresponding to the tail entity. The two-norm calculation formula is: ; Determine whether it is the optimal vector representation based on the potential energy. If so, output it. If not, randomly select b vectors from the training triple set again.

2. The intelligent software code type inference method according to claim 1, characterized in that: The topic semantic information and AST structure information of the function type extracted in the source code specifically include: For JavaScript intelligent software source code with JSDoc annotations, obtain the corresponding abstract syntax tree, use babel / parser to parse the source code syntax tree, and traverse the nodes of specific function types in its abstract syntax tree; Extract the topic semantic information and AST structure information of the function type in the source code. The topic semantic information and AST structure information include the function name, parameter information, function-related comments, comments related to the function return value type, return value type and calling relationship. A json file is formed based on the topic semantic information and AST structure information of the function type.

3. The intelligent software code type inference method according to claim 1, characterized in that: In the directed graph of the knowledge graph data structure, the nodes represent function entities, and the other edges connected to the nodes represent function-related attributes. There are directed edges with call relationships or control flow relationships between nodes.

4. The intelligent software code type inference method according to claim 1, characterized in that: The node message propagation is performed inside the graph neural network. The node feature embedding vector is used as the initial state of the node, and the edge embedding vector is used to transmit messages between related edges. It is divided into three stages, including: In the message passing phase, the function of the message function is to generate a passing node To neighbor node Message vector , where the node Encoding Node Type information; in the knowledge graph, the characteristics of the relationship are used as embedding vectors , and then embed the relation feature vector into the message vector through the following message function: , ∈V, ∈ N ( ), in, ∈ , ∈ , ∈ , ∈ is the learning parameter, represents the message vector at the Kth step, represents the state vector of node u at the K-1th step, represents the relation feature vector; Message aggregation phase, for all nodes ∈N ( ) After calculating the message vector Finally, the integration function integrates the message vector into a vector ∈ Assign to node , at this time node Carrying other nodes The specific calculations used are as follows: , ∈V, in, represents the message vector at the Kth step, Representation Node The integrated vector after integrating other node information at the Kth step; In the message update phase, when inferring types, type information is propagated to multiple function nodes in multiple rounds of propagation. The gated recurrent unit is used as the update function. The specific calculation used is as follows: , ∈V; in, Representation Node The integrated vector after integrating other node information at the Kth step, Representation Node The state vector at step K-1 is Representation Node The final state vector at step K.

5. The intelligent software code type inference method according to claim 1, characterized in that: The method of performing probability type prediction based on the acquired propagated node information specifically includes: According to the generated final node state vector, a fully connected layer and a softmax function are used to convert the final node state after K rounds of message propagation into a probability distribution over candidate types, and the most likely type is output as the inferred type of the node.

6. An intelligent software code type inference system, based on the intelligent software code type inference method according to any one of claims 1 to 5, characterized in that: include: The acquisition module is used to obtain JavaScript intelligent software source code with JSDoc annotations, traverse the abstract syntax tree of the source code, extract the topic semantic information and AST structure information of the function type in the source code, and form a json file; A construction module is used to represent the topic semantic information and AST structure information of the function type in the json file using a knowledge graph structure to construct a knowledge graph; A learning module, used to represent node features in the knowledge graph data structure as triples, select an appropriate knowledge graph representation algorithm, and perform representation learning of node information; After learning, the feature vectors of the entity set and the relationship set are obtained. The feature vectors are used as the input of the graph neural network. Node message propagation is performed inside the graph neural network. The message propagation is divided into three stages: message propagation stage, aggregation stage and update stage, and the final node state vector is obtained. The prediction module is used to build the prediction layer of the graph neural network and perform probability type prediction based on the node information after propagation. The inference module is used to predict and output JavaScript intelligent software source code with all inference types according to the probability type.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the intelligent software code type inference method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the intelligent software code type inference method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Code recommendation method based on tree neural network

    CN111459491A

  • Medical knowledge graph construction method

    CN111639190A

  • Persistent annotation of syntax graphs for code optimization

    US20200364036A1