A software information organization method, device and computer readable medium
Patent Information
- Application Number
- CN202080103659.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-01
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2040-09-01
AI Technical Summary
[0030] When determining the similarity between software, several optional implementation methods are provided. A specified software can be compared with a knowledge graph to identify software similar to that specified software among those marked by the knowledge graph. Alternatively, key information can be specified to search for software in the knowledge graph that matches that information. This offers greater flexibility and results that better meet user needs.
Smart Images

Figure CN116113939B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software analysis technology, and in particular to a software information organization method, apparatus and computer-readable medium. Background Technology
[0002] Software typically includes the following components:
[0003] 1) Code: A file written in a programming language, containing computer-readable instructions for performing a series of steps to achieve a pre-defined function.
[0004] 2) Data: Data required during code execution, which may include input data, output data, and temporary data generated during code execution.
[0005] 3) Resources: This includes information about resources used during software execution, such as dialog boxes, menu bars, and string tables.
[0006] 4) Documentation: This may include user documentation, development documentation, and management documentation. User documentation may include user manuals and operation manuals; development documentation may include software requirements specifications, data requirements specifications, and preliminary design specifications; management documentation may include project development plans, test reports, and development progress reports.
[0007] The various components of the software contain a large amount of information that needs to be effectively organized in order to enable functions such as automatic code generation, system refactoring, and code quality inspection. Summary of the Invention
[0008] This invention provides a software information organization method, apparatus, and computer-readable medium to generate a knowledge graph of software, enabling the effective organization of rich information contained in the software and determining the similarity between software based on the knowledge graph.
[0009] In a first aspect, a method for organizing software information is provided. The method may include: loading first software, the first software including code, data, resources, and documents; obtaining first information from the code of the first software and generating a first knowledge graph based on the first information; obtaining second information from the data, resources, and documents of the first software and generating a second knowledge graph based on the second information; and merging the first knowledge graph and the second knowledge graph into a third knowledge graph.
[0010] In a second aspect, a software information organization apparatus is provided, the apparatus comprising:
[0011] - A software loading module is configured to load first software, which includes code, data, resources, and documentation;
[0012] - The first information acquisition module is configured to acquire first information from the code of the first software and generate a first knowledge graph based on the first information;
[0013] - The second information acquisition module is configured to acquire second information from the data, resources and documents of the first software, and generate a second knowledge graph based on the second information;
[0014] - The knowledge collection module is configured to merge the first knowledge graph and the second knowledge graph into the third knowledge graph.
[0015] Thirdly, a software information organization apparatus is provided, comprising: at least one memory configured to store computer-readable code; and at least one processor configured to invoke the computer-readable code to perform the steps provided in the first aspect.
[0016] Fourthly, a computer-readable medium storing computer-readable instructions that, when executed by a processor, cause the processor to perform the steps provided in the first aspect.
[0017] When generating the knowledge graph for the software, considering that both code and non-code data contain software-related information, and that the characteristics of code and non-code data differ, different methods are chosen for information extraction to generate separate knowledge graphs. This maximizes and accurately extracts information and generates the knowledge graph. Furthermore, merging information from various software programs to generate a single knowledge graph allows for the combination of similar or identical structures and content across different software programs, reducing redundant information in the overall knowledge graph and improving search efficiency when looking for similar software later.
[0018] Optionally, for any of the above aspects, the first information includes at least one of the following: static code information, abstract syntax tree (AST) data, control flow information, and data flow information.
[0019] If the first information includes the static code information, when obtaining the first information from the code of the first software and generating the first knowledge graph based on the first information, a static analysis method can be used to obtain at least two static code information items from the code of the first software, as well as the relationship between the at least two static code information items, and the first knowledge graph can be generated based on the at least two static code information items and the relationship between the at least two static code information items.
[0020] If the first information includes the AST data, when obtaining the first information from the code of the first software and generating the first knowledge graph based on the first information, the AST tool can be used to generate the AST data based on the code of the first software, and the first knowledge graph can be generated based on the relationships between AST nodes in the AST data, the relationships between class nodes and method nodes in the AST nodes, and the values of the AST nodes.
[0021] If the first information includes the control flow information, when obtaining the first information from the code of the first software and generating the first knowledge graph based on the first information, the AST tool can be used to generate the AST data based on the code of the first software, and the control flow information can be determined based on the call relationship between AST nodes in the AST data and the method marked as the starting method; the first knowledge graph can be generated based on the control flow information.
[0022] If the first information includes the data flow information, when obtaining the first information from the code of the first software and generating the first knowledge graph based on the first information, data calculation points can be added in each execution scenario in the code of the first software; the data flow information can be obtained according to each data calculation point; and the first knowledge graph can be generated based on the data flow information.
[0023] When extracting primary information, different methods can be used to extract various types of information from the code, such as data flow information, control flow information, AST data, and static code information. Based on the provided information, a knowledge graph can be generated. The generated knowledge graph can effectively organize and present this rich information, and has the advantages of good visibility and easy search.
[0024] Optionally, when obtaining the second information from the data, resources, and documents of the first software, the second information can be obtained using predefined rules for the semi-structured content among the three items of the data, resources, and documents of the first software; while the second information can be obtained using natural language processing methods for the unstructured content among the three items of the data, resources, and documents of the first software.
[0025] Different methods are used to extract information based on the different characteristics of semi-structured and unstructured content.
[0026] For any of the above, alternatively, similar software can be obtained using the following methods:
[0027] Load a second software, which includes code, data, resources, and documentation; obtain third information from the code of the second software and generate a fourth knowledge graph based on the third information; obtain fourth information from the data, resources, and documentation of the second software and generate a fifth knowledge graph based on the fourth information; compare the fourth and fifth knowledge graphs with the third knowledge graph to determine software similar to the second software.
[0028] Alternatively, a third software may be loaded, the third software including code, data, resources, and documentation; third information may be obtained from the code of the third software and / or fourth information may be obtained from the data, resources, and documentation of the third software; first key information used for software similarity comparison may be determined from the obtained information; and software matching the key information may be searched in the third knowledge graph based on the first key information.
[0029] Alternatively, a second key piece of information is determined to describe the characteristics of the software; based on the second key piece of information, a search is conducted in the third knowledge graph to identify software that matches the second key piece of information.
[0030] When determining the similarity between software, several optional implementation methods are provided. A specified software can be compared with a knowledge graph to identify software similar to that specified software among those marked by the knowledge graph. Alternatively, key information can be specified to search for software in the knowledge graph that matches that information. This offers greater flexibility and results that better meet user needs. Attached Figure Description
[0031] Figure 1 This is a schematic diagram of the structure of a software information organization device provided in an embodiment of the present invention.
[0032] Figure 2 A flowchart of a software information organization method provided in an embodiment of the present invention.
[0033] Figure 3 This is a schematic diagram of another structure of the software information organization device provided in an embodiment of the present invention.
[0034] Figure 4 This is another flowchart of the software information organization method provided in the embodiments of the present invention.
[0035] Figure 5 This is a schematic diagram of a knowledge graph obtained based on static code analysis.
[0036] Figure 6 This is a schematic diagram of a knowledge graph obtained based on AST data.
[0037] List of reference numerals in the attached diagram:
[0038] Detailed Implementation
[0039] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed merely to enable those skilled in the art to better understand and implement the subject matter described herein, and are not intended to limit the scope, applicability, or examples set forth in the claims. The function and arrangement of the elements discussed may be changed without departing from the scope of the embodiments of the invention. Various processes or components may be omitted, substituted, or added as needed in the various examples. For example, the described methods may be performed in a different order than described, and steps may be added, omitted, or combined. Furthermore, features described in some examples may be combined in other examples.
[0040] As used herein, the term "comprising" and its variations are open terms meaning "including but not limited to". The term "based on" means "at least partially based on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc., may refer to different or the same objects. Other definitions, whether explicit or implicit, may be included below. Unless explicitly indicated by the context, the definition of a term shall remain consistent throughout the specification.
[0041] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0042] Figure 1 A schematic diagram of the structure of the software information organization device 10 is shown.
[0043] The software information organization device 10 provided in this embodiment of the invention can be implemented as a network of computer processors to execute the software information organization method 200 in this embodiment of the invention. The software information organization device 10 can also be as follows: Figure 1The illustrated single-unit computer includes at least one memory 101, which includes a computer-readable medium, such as random access memory (RAM). The device 10 also includes at least one processor 102 coupled to the at least one memory 101. Computer-executable instructions are stored in the at least one memory 101 and, when executed by the at least one processor 102, can cause the at least one processor 102 to perform the steps described herein. The at least one processor 102 may include a microprocessor, an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a central processing unit (CPU), a graphics processing unit (GPU), a state machine, etc. Embodiments of computer-readable media include, but are not limited to, floppy disks, CD-ROMs, magnetic disks, memory chips, ROMs, RAMs, ASICs, configured processors, all-optical media, all magnetic tapes or other magnetic media, or any other medium from which a computer processor can read instructions. Furthermore, various other forms of computer-readable media can send or carry instructions to a computer, including routers, private or public networks, or other wired and wireless transmission devices or channels. Instructions may include code in any computer programming language, including C, C++, C++, Visual Basic, Java, and JavaScript.
[0044] When executed by at least one processor 102 Figure 1 At least one memory 101 shown may contain a software information organization program 20, causing at least one processor 102 to execute the software information organization method 200 described in this embodiment of the invention. The software information organization program 20 may include:
[0045] - Software loading module 201 is configured to load first software 31, which includes code, data, resources and documents;
[0046] - The first information acquisition module 202 is configured to acquire first information from the code of the first software 31 and generate a first knowledge graph based on the first information;
[0047] - The second information acquisition module 203 is configured to acquire second information from the data, resources and documents of the first software 31, and generate a second knowledge graph based on the second information;
[0048] -Knowledge collection module 204 is configured to merge the first knowledge graph and the second knowledge graph into the third knowledge graph.
[0049] Optionally, the device 10 may further include a software similarity comparison module 205, configured to compare the similarity between a first software and another software or to search for software that matches key information from a third knowledge graph.
[0050] It should be mentioned that embodiments of the present invention may include those having different characteristics from those of other inventions. Figure 1 The apparatus shown is an example. The architecture described above is merely exemplary and used to explain the method 200 provided in the embodiments of the present invention. For example, apparatus 10 can also be implemented as... Figure 3 The structure shown.
[0051] In addition, the above modules can also be regarded as functional modules implemented by hardware, used to implement various functions involved in the execution of the software information organization method by the software information organization device 10. For example, the control logic of each process involved in the method can be pre-burned into a chip such as a field-programmable gate array (FPGA) or a complex programmable logic device (CPLD), and these chips or devices can execute the functions of the above modules. The specific implementation method can be determined according to engineering practice.
[0052] like Figure 2 As shown, an exemplary method 200 according to an embodiment of the present invention includes the following steps:
[0053] -S201: Load the first software 31, which includes code, data, resources and documentation;
[0054] -S202: Obtain first information from the code of the first software 31, and generate a first knowledge graph based on the first information;
[0055] -S203: Obtain second information from the data, resources and documents of the first software 31, and generate a second knowledge graph based on the second information;
[0056] -S204: Merge the first and second knowledge graphs into the third knowledge graph.
[0057] The first information may include at least one of the following:
[0058] -Static code information;
[0059] - Abstract Syntax Tree (AST) data;
[0060] -Control flow information;
[0061] - Data flow information.
[0062] For example, if the first information includes static code information, then, in step S202, when obtaining the first information from the code of the first software 31 and generating the first knowledge graph based on the first information, specifically, as follows: Figure 2As shown, the executable sub-step S2021 involves using a static analysis method to obtain at least two pieces of static code information from the code, obtaining the relationship between the at least two pieces of static code information, and generating a first knowledge graph based on the at least two pieces of static code information and the relationship between the at least two pieces of static code information.
[0063] Static code analysis collects characteristic data about software by scanning its source code. This characteristic data can include program name, program description, code file names, package structure, and the number of lines of code in each file. In addition, static code analysis can be used to create an index of the source code, which can be used to assist in data flow and control flow analysis.
[0064] A knowledge graph is a network of entities, their semantic types, attributes, and relationships. It uses a graph structure to represent knowledge and store entities and their relationships. In a knowledge graph, entities are represented by nodes, and relationships between entities are represented by edges between nodes. Figure 5 The knowledge graph obtained based on static code analysis is shown. Nodes 52 "NGINX" and 53 "KAFKA" are both programs, therefore they are both connected to node 51 "Program". Edge 501 from node 52 to node 51 is "a type", and edge 502 from node 53 to node 51 is also "a type", indicating that nodes 52 and 53 are both instances of node 51. Node 52 "NGINX" "includes" node 503 "NGINX Project Information", node 54 "NGINX Project Information" includes node 504 "Root Directory", and node 55 "Root Directory" includes subdirectories 505 and 506, which are respectively node 56 "Subdirectory src" and node 57 "Subdirectory conf". Node 56 "Subdirectory src" further includes subdirectory 508 and node 58 "Subdirectory core". Node 58, “subdirectory core”, includes subfile 509, “subfile nginx.c”, while node 57, “subdirectory conf”, includes subfile 508 and node 59, “subfile fastcgi.c”.
[0065] During the generation of a knowledge graph, the knowledge graph is stored in a knowledge graph library and may be transferred between different devices, apparatuses, or modules as needed. In this embodiment of the invention, the JavaScript ObjectNotation format can be used as an intermediate data format to represent the knowledge graph, and its definition can be as follows:
[0066]
[0067] Where node represents a node in the knowledge graph, link represents an edge in the knowledge graph, source represents the starting node of an edge in the knowledge graph, target represents the ending node of an edge in the knowledge graph, weight represents the weight of the edge, and group represents the node type.
[0068] For example, if the first information includes AST data, then when executing step S202 to obtain the first information from the code of the first software 31 and generate the first knowledge graph based on the first information, specifically, as follows: Figure 2 As shown, the executable sub-step S2022 uses an AST tool to generate AST data based on the code of the first software 31, and generates a first knowledge graph based on the relationships between AST nodes in the AST data, the relationships between class nodes and method nodes in the AST nodes, and the values of the AST nodes.
[0069] An Abstract Syntax Tree (AST) represents the abstract syntactic structure of source code written in a programming language in a tree structure. Each node in the tree represents a structure that appears in the source code. The AST data structure does not consider the programming language used when representing the abstract syntactic structure of the source code. Program elements are represented as package definitions or imports, variable assignments, conditions, logical branches, etc. Knowledge generated based on ASTs can be used for software code similarity matching. Because AST data is an abstraction of the logic or syntax of the source code, it is almost unaffected by code fuzzing. Figure 6 The knowledge graph obtained based on AST data is shown.
[0070] In this context, nodes 72 "NGINX", 73 "BinaryC", and 74 "KAFKA" are all examples of node 71 "Program", therefore, edges 701, 702, and 703 from them to node 74 are all "A type". Node 73 "BinaryC" includes node 75 "AST", and edge 704 from node 73 to node 75 is "Includes". Node 75 "AST" is connected to nodes 76 "Package", 80 "Type", and 77 "Import", and edges 705, 706, and 707 with these nodes are all "Includes". Node 76 "Package" is connected to nodes 78 "astsample" and 79 "com.sie", and edges 708 and 709 with these two nodes are all "Includes". Node 80 "Type" is connected to node 81 "Type Definition", and edge 710 is "Includes". Node 81 "Type Definition" is connected to node 82 "Binary Code", and edge 711 is "Includes". Node 81 "Type Definition" is also connected to node 83 "Program Body Definition", with edge 712 being "Include". Node 83 "Program Body Definition" is connected to nodes 84 "Binary File" and 85 "Main Program Body", with edges 713 and 714 both being "Include Method". Node 84 "Binary File" is connected to nodes 86 "String", 88 "Block", 89 "Static", and 87 "Common", with edges 715, 716, 717, and 718 being "Return Value Type", "Program Body", "Modifier", and "Modifier", respectively. Node 85 "Main Program Body" is connected to nodes 87 "Common", 89 "Static", 90 "Block", and 91 "No Type", with edges 719, 720, 721, and 722 being "Modifier", "Modifier", "Program Body", and "Return Value Type", respectively. Node 88, "Block", is connected to nodes 92, "Variable", 93, "Expression", and 94, "Return Value". Edges 723, 724, and 725 are all "Declarations". Node 92, "Variable", is connected to node 93, "Expression", with edge 728 indicating "Next Step in Program Body". Node 93, "Expression", is connected to node 94, "Return Value", with edge 727 indicating "Next Step in Program Body". Node 90, "Block", is connected to node 95, "Regarding State", with edge 726 indicating "Declaration".
[0071] In short, software consists of code, and each code file has its corresponding AST node. AST nodes define child nodes such as PACKAGE, TYPES, and IMPORTS. The AST node "Type" defines class-level attributes and has child nodes defining each method. The AST nodes corresponding to classes and methods are connected via an "INCLUDE_METHOD" relationship. Code-specific values are also included in the knowledge graph described above.
[0072] For example, if the first information includes control flow information, then when executing step S202 to obtain the first information from the code of the first software 31 and generate the first knowledge graph based on the first information, specifically, as follows: Figure 2 As shown, in sub-step S2023, an AST tool is used to generate AST data based on the code of the first software 31 (here, if AST data has already been generated in previous steps, control flow information can be determined directly based on the generated AST data). Based on the call relationships between AST nodes in the AST data, and the methods marked as start methods, control flow information is determined, and a first knowledge graph is generated based on the control flow information. For example, in sub-step S2023, call relationships between AST nodes can be collected to enrich the knowledge graph. Based on the AST data, the AST nodes corresponding to the methods have call relationships. In addition, start methods are usually marked with "Start_Method". With control flow information, the software execution flow and call relationships can be established.
[0073] For example, if the first information includes data flow information, then when executing step S202 to obtain the first information from the code of the first software 31 and generate the first knowledge graph based on the first information, specifically, as follows: Figure 2 As shown, the executable sub-step S2024 adds data calculation points to each execution scenario in the code of the first software 31, obtains data flow information based on each data calculation point, and generates a first knowledge graph based on the data flow information. Here, an execution scenario is a task with a start point and an end point, such as uploading data to a database. Through sub-step S2024, various program execution declaration data can be added to the knowledge graph.
[0074] Optionally, when obtaining the second information from the data, resources, and documents of the first software 31 in step S203, specifically, semi-structured content and structured content can be distinguished and processed separately. For example, for the semi-structured content among the data, resources, and documents of the first software 31, predefined rules are used to obtain the second information; while for the unstructured content among the data, resources, and documents of the first software 31, natural language processing methods are used to obtain the second information, wherein a document understanding algorithm can be used to understand the content of the document; then, a natural language processing algorithm can be used to analyze, understand, and derive entities and relationships.
[0075] In step S204, the first and second knowledge graphs of the first software 31 are merged into a single overall knowledge graph. This allows for continuous expansion and enrichment of the knowledge points and relationships within the third knowledge graph when new software is introduced, enabling in-depth exploration of these knowledge points. Each component of the third knowledge graph is marked with a corresponding software identifier, allowing for the identification of similar software when determining the similarity between a new software and known software. Compared to generating separate knowledge graphs for each software, generating a single overall knowledge graph with rich information and knowledge point relationships facilitates in-depth exploration of the relationships and connections between software, resulting in a more complete knowledge graph system.
[0076] The steps S201–S204 above generate and refine the third knowledge graph. In the following steps, the similarity between software programs can also be determined based on the knowledge graph. This can be achieved in various ways, including but not limited to:
[0077] Method 1: Input the software to be compared, generate knowledge graphs based on both code and non-code information, and search for similar software in a third knowledge graph based on the generated knowledge graphs.
[0078] Method 2: Input the software to be compared, obtain information from both code and non-code information, determine key information for software similarity comparison based on the obtained information, and search for software that matches the key information in the third knowledge graph.
[0079] Method 3: Operator 41 configures key information, or other methods are used to determine key information, such as using big data analysis to predict the key information of the software that operator 41 wants to find based on operator 41's previous operations. Then, software matching this key information is searched in the third knowledge graph.
[0080] For method one, specifically, method 200 may further include the following steps:
[0081] -S205: Load the second software 32, which includes code, data, resources, and documentation;
[0082] -S206: Obtain third information from the code of the second software 32, and generate a fourth knowledge graph based on the third information;
[0083] -S207: Obtain fourth information from the data, resources and documents of the second software 32, and generate a fifth knowledge graph based on the fourth information;
[0084] -S208: Compare the fourth and fifth knowledge graphs with the aforementioned total third knowledge graph to identify software similar to the second software 32.
[0085] For method two, specifically, method 200 may also include the following steps:
[0086] -S209: Load third-party software 33, which includes code, data, resources, and documentation;
[0087] -S210: Obtain third information from the code of third software 33;
[0088] -S211: Obtain fourth information from the data, resources, and documentation of the third software 33;
[0089] Among them, steps S210 and S211 can be performed by one or both of them, depending on the software's search requirements.
[0090] -S212: Determine the first key information used for software similarity comparison from the information obtained above. For example, a dialog box can be popped up for operator 41 to select; or predefined rules can be used to select the required information from the many pieces of information obtained; or the many pieces of information obtained can be combined to form the search conditions, i.e., the first key information.
[0091] -S213: Search for software that matches the first key information in the third knowledge graph.
[0092] For method three, specifically, method 200 may further include the following steps:
[0093] -S214: Determine the second key information used to describe the software features;
[0094] -S215: Search the third knowledge graph based on the second key information to identify software that matches the second key information.
[0095] In the process described above, when searching for software with key information in the third knowledge graph, the key information can be matched based on the information of each node in the knowledge graph and the edges between nodes to find the target software. Since the software identifiers corresponding to each component are marked when the third knowledge graph is generated, the corresponding software can be found by matching key information.
[0096] Figure 3 This illustration shows yet another structure of the software information organization apparatus 10 provided in an embodiment of the present invention. This structure can be considered as... Figure 1 Further refinement of the structure shown.
[0097] like Figure 3As shown, the software loading module 201 loads the first software 31. As previously mentioned, the first software may include code 311, data 312, resources 313, and documents 314. On one hand, the software loading module 201 sends the code 311 to the first information acquisition module 202. The static code analyzer 2021 in the first information acquisition module 202 performs static analysis based on the code 311 to obtain static code information; the AST builder 2022 in the first information acquisition module 202 generates AST data based on the code 311; the control flow analyzer 2023 in the first information acquisition module 202 determines control flow information based on the AST data; and the data flow analyzer 2024 in the first information acquisition module 202 obtains data flow information based on the code 311. The first information acquisition module 202 generates a first knowledge graph based on this information and sends it to the knowledge collection module 204. On the other hand, the software loading module 201 sends data 312, resources 313, and documents 314 to the second information acquisition module 203. The second information acquisition module 203 obtains second information from these data, generates a second knowledge graph based on the second information, and sends it to the knowledge collection module 204. Specifically, the second information acquisition module 203 can use predefined rules to obtain the second information from the semi-structured content of data 312, resources 313, and documents 314 in the first software 31, while it can use natural language processing methods to obtain the second information from the unstructured content of data 312, resources 313, and documents 314 in the first software 31.
[0098] The knowledge collector 2041 in the knowledge collection module 204 receives the first knowledge graph and the second knowledge graph, merges the first and second knowledge graphs into the third knowledge graph, and stores it in the knowledge graph library 2042. The device 10 also provides a query / configuration API 2045 as an interface with the operator 41, allowing the operator 41 to configure rules and perform software similarity queries. The configured rules can be used to generate a knowledge graph of the software and to compare the similarity of the software. The query / configuration API 2045 receives commands from the operator 41 and sends them to the rule manager 2044, which configures the first information acquisition module 202, the second information acquisition module 203, and the knowledge manager 2043 respectively.
[0099] For example, operator 41 can configure the first information acquisition module 202 to change its behavior in acquiring the first information from code 311. Furthermore, operator 41 can configure the first information acquisition module 202 to use different methods to acquire the first information. As another example, operator 41 can configure the rules for the second information acquisition module 203 to acquire the second information from the document, as well as the parameters of the natural language processing algorithm it uses. And as yet another example, operator 41 can configure the rule manager 2044 to change the algorithm used to determine software similarity.
[0100] Below, in conjunction with Figure 4 illustrate Figure 3 The apparatus shown generates a knowledge graph and identifies similar software in process 400. For example... Figure 4 As shown, the process may include the following steps:
[0101] S401: Operator 41 loads the first software 31 into the software loading module 201.
[0102] S402: The software loading module 201 standardizes and preprocesses the received first software 31.
[0103] S403: The software loading module 201 sends the data 312, resources 313 and documents 314 in the first software 31 to the second information acquisition module 203.
[0104] S404: The second information acquisition module 203 extracts information based on the received data 312, resources 313, and documents 314, generates a second knowledge graph, and sends it to the knowledge collector 2041. For specific implementation details, please refer to the aforementioned step S203.
[0105] S405: Knowledge collector 2041 stores the second knowledge graph into knowledge graph library 2042.
[0106] S406: The software loading module 201 sends the code 311 in the first software 31 to the first information acquisition module 202.
[0107] S407~S410: The first information acquisition module 202 extracts information based on the received code 311 and generates the first knowledge graph.
[0108] In step S407, the static code analyzer 2021 in the first information acquisition module 202 uses static analysis to obtain static code information from code 31 and obtain the relationship between the static code information. Based on these two items, a first knowledge graph is generated. For details, please refer to the aforementioned step S2021.
[0109] In step S408, the AST builder 2022 in the first information acquisition module 202 uses the AST tool to generate AST data based on code 311, and generates the first knowledge graph based on the relationship between AST nodes in the AST data, the relationship between class nodes and method nodes in the AST nodes, and the value of the AST nodes. For details, please refer to the aforementioned step S2022.
[0110] In step S409, the control flow analyzer 2023 in the first information acquisition module 202 can use the AST tool to generate AST data based on code 311, and determine control flow information based on the call relationship between AST nodes in the AST data and the method marked as the starting method, and generate a first knowledge graph based on the control flow information. For details, please refer to the aforementioned step S2023.
[0111] In step S410, the data flow analyzer 2024 in the first information acquisition module 202 can add data calculation points in each execution scenario in code 311, acquire data flow information based on each data calculation point, and generate a first knowledge graph based on the data flow information. For details, please refer to the aforementioned step S2024.
[0112] Among them, the static code analyzer 2021, AST builder 2022, control flow analyzer 2023, and data flow analyzer 2024 can each generate knowledge graphs based on code 311, and then finally synthesize the first knowledge graph. Alternatively, the knowledge graphs generated by each can be sent to the knowledge collector 2041, and the knowledge collector 2041 or subsequent devices can complete the knowledge graph synthesis operation.
[0113] S411: The first information acquisition module 202 sends the first knowledge graph to the knowledge collector 2041.
[0114] S412: Knowledge collector 2041 stores the first knowledge graph into knowledge graph library 2042.
[0115] S413: The software loading module 201 sends a message to the knowledge manager 2043, triggering the knowledge manager 2043 to load the first and second knowledge graphs from the knowledge graph library 2042, and merge the first and second knowledge graphs into the third knowledge graph. The merging of knowledge graphs can combine knowledge with the same or similar methods or classes together. Merging the same or similar methods from different software into the same nodes can improve the performance and accuracy of software similarity judgment.
[0116] S414: Knowledge Manager 2043 sends a message to Knowledge Graph Library 2042 to retrieve the first knowledge graph and the second knowledge graph from Knowledge Graph Library 2042.
[0117] S415: Knowledge graph library 2042 responds to the message sent by knowledge manager 2043 and returns the first knowledge graph and the second knowledge graph to knowledge manager 2043.
[0118] S416: Knowledge Manager 2043 merges the first knowledge graph and the second knowledge graph into the third knowledge graph library 2042.
[0119] S417: Knowledge Graph Base 2042 stores the merged third knowledge graph in Knowledge Graph Base 2042.
[0120] Operator 41 can configure the rules for software information acquisition, knowledge graph generation, and knowledge graph merging through the following steps S418 to S426, specifically:
[0121] S418: Operator 41 sends a command to the query / configuration API 2045 to request the configuration of the second information acquisition module 203.
[0122] S419: The query / configuration API 2045 forwards an instruction to the rule manager 2044, requesting the configuration of the second information acquisition module 203.
[0123] S420: Rule manager 2044 generates rules according to instructions and configures the rules used by second information acquisition module 203 when acquiring second information, such as: natural language processing algorithm parameters (used to acquire the aforementioned second information from the unstructured content of software documents, data, and resources) and document information acquisition rules (used to acquire the aforementioned second information from the semi-structured content of software documents, data, and resources).
[0124] S421: Operator 41 sends a command to the query / configuration API 2045 to request the configuration of the first information acquisition module 202.
[0125] S422: The query / configuration API 2045 forwards instructions to the rule manager 2044, requesting the configuration of the first information acquisition module 202.
[0126] S423: Rule manager 2044 generates rules according to instructions, and configures the rules used by first information acquisition module 202 when acquiring first information from software code, so as to control the behavior and process of first information acquisition module 202 acquiring information from code.
[0127] S424: Operator 41 sends a command to query / configure API 2045 to request configuration of Knowledge Manager 2043.
[0128] S425: Query / Configuration API 2045 forwards instructions to Rule Manager 2044, requesting configuration of Knowledge Manager 2043.
[0129] S426: Rule Manager 2044 generates rules according to instructions and configures the rules used by Knowledge Manager 2043 when performing software similarity comparison, such as algorithm parameters.
[0130] Steps S418 to S426 can be executed before step S401, during the execution of steps S401 to S417, or after step S417, so as to flexibly modify the rules.
[0131] In the following steps S427 to S438, user 42 uses the software information organization device 10 provided in this embodiment of the invention to query software similar to the second software 42. The following steps employ the aforementioned method one for determining the similarity between software.
[0132] S427: User 42 sends a command to query / configuration API 2045 to request a query for software similar to the second software 32.
[0133] S428: The query / configuration API 2045 forwards an instruction to the software similarity comparison module 205, requesting a query for software similar to the second software 32.
[0134] S429: The software similarity comparison module 205 sends the second software 32 to the second information acquisition module 203, or it may send only the data, resources and documents in the second software 32.
[0135] S430: The second information acquisition module 203 extracts the fourth information from the data, resources and documents received from the second software 32, generates the fifth knowledge graph based on the fourth information (the process is the same as the information acquisition or knowledge graph generation process of the first software 31, and will not be described again here), and returns it to the software similarity comparison module 205.
[0136] S431: The software similarity comparison module 205 sends the second software 32 to the first information acquisition module 202, or it may send only the code in the second software 32.
[0137] S432: The first information acquisition module 202 extracts the third information from the code received from the second software 32, generates the fourth knowledge graph based on the third information (the process is the same as the information acquisition or knowledge graph generation process of the first software 31, and will not be described again here), and returns it to the software similarity comparison module 205.
[0138] S433: The software similarity comparison module 205 sends a message to the knowledge manager 2043, requesting to obtain the third knowledge graph, that is, the synthesized total knowledge graph stored in the knowledge graph library 2042.
[0139] S434: Knowledge Manager 2043 sends a message to Knowledge Graph Library 2042, requesting to obtain the third knowledge graph.
[0140] S435: Knowledge graph library 2042 responds to the message and returns the third knowledge graph to knowledge manager 2043.
[0141] S436: Knowledge Manager 2043 returns the third knowledge graph to Software Similarity Comparison Module 205.
[0142] S437: The software similarity comparison module 205 compares the fourth and fifth knowledge graphs with the third knowledge graph to identify software similar to the second software 32 (e.g., software with a similarity greater than a preset similarity threshold). The similar software identified by the software similarity comparison module 205, or information about that software, is returned to the query / configuration API 2045.
[0143] S438: Query / Configure API 2045 returns similar software or software information to user 42.
[0144] Furthermore, embodiments of the present invention also provide a computer-readable medium storing computer-readable instructions. When executed by a processor, the computer-readable instructions cause the processor to perform the aforementioned software information organization method. Embodiments of the computer-readable medium include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the computer-readable instructions can be downloaded from a server computer or the cloud via a communication network.
[0145] In summary, the embodiments of the present invention provide a software information organization method, apparatus, and computer-readable medium that generate a knowledge graph of software, enabling the effective organization of the rich information contained in the software, and allowing the determination of the similarity between software based on the knowledge graph.
[0146] When generating the knowledge graph for the software, we choose to merge the information of each software into a single knowledge graph and mark the corresponding parts of the knowledge graph with software identifiers. This not only merges the same or similar structures and content between different software, reducing redundant information in the entire knowledge graph, but also marks the software identifiers in the knowledge graph, making it easier to find similar software in the future. Furthermore, it makes the calculation of software similarity more efficient (redundant information in the knowledge graph is removed, and the search is only conducted in one knowledge graph, resulting in higher search efficiency).
[0147] When determining the similarity between software, several optional implementation methods are provided. A specified software can be compared with a knowledge graph to identify software similar to that specified software among those marked by the knowledge graph. Alternatively, key information can be specified to search for software in the knowledge graph that matches that information. This offers greater flexibility and results that better meet user needs.
[0148] It should be noted that not all steps and modules in the above processes and system structure diagrams are mandatory; some steps or modules can be omitted as needed. The execution order of each step is not fixed and can be adjusted as required. The system structure described in the above embodiments can be a physical structure or a logical structure. That is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or they may be jointly implemented by certain components in multiple independent devices.
Claims
1. A method (200) of organizing software information, characterized by, include: - Load (S201) the first software (31), the first software (31) including code, data, resources and documents; - Obtain (S202) first information from the code of the first software (31), and generate a first knowledge graph based on the first information; - Obtain (S203) second information from the data, resources and documents of the first software (31), and generate a second knowledge graph based on the second information; wherein for the semi-structured content of the data, resources and documents of the first software (31), the second information is obtained by using predefined rules; for the unstructured content of the data, resources and documents of the first software (31), the second information is obtained by using natural language processing methods; - Merge the first knowledge graph and the second knowledge graph into the third knowledge graph (S204); The third knowledge graph is stored in a knowledge graph database; Receive user commands to search for software similar to the second software; Load (S205) the second software (32), the second software (32) including code, data, resources and documents; (S206) Third information is obtained from the code of the second software (32), and a fourth knowledge graph is generated based on the third information; (S207) Fourth information is obtained from the data, resources and documents of the second software (32), and a fifth knowledge graph is generated based on the fourth information; wherein, for the semi-structured content in the data, resources and documents of the second software (32), the fourth information is obtained using predefined rules; for the unstructured content in the data, resources and documents of the second software (32), the fourth information is obtained using natural language processing methods; The fourth and fifth knowledge graphs are compared with one or more knowledge graphs stored in the knowledge graph library (S208) to determine software similar to the second software (32); The first information includes at least one of the following: - Static code information; - Abstract Syntax Tree (AST) data; - Control flow information; - Data flow information; Wherein, the first information includes the code static information, obtaining (S202) the first information from the code of the first software (31), and generating a first knowledge graph based on the first information, including: - At least two pieces of static code information are obtained from the code of the first software (31) using static analysis methods (S2021), and - Obtain the relationship between the at least two pieces of static code information, and generate the first knowledge graph based on the at least two pieces of static code information and the relationship between the at least two pieces of static code information.
2. The method of claim 1, wherein, The first information includes the AST data. The first information is obtained (S202) from the code of the first software (31), and a first knowledge graph is generated based on the first information, including: - Use the AST tool to generate (S2022) the AST data based on the code of the first software (31), and - The first knowledge graph is generated based on the relationships between AST nodes in the AST data, the relationships between class nodes and method nodes in the AST nodes, and the values of the AST nodes.
3. The method of claim 1, wherein, The first information includes the control flow information. The first information is obtained (S202) from the code of the first software (31), and a first knowledge graph is generated based on the first information, including: - The AST data is generated (S2023) using the AST tool based on the code of the first software (31), and - Based on the call relationships between AST nodes in the AST data, and the methods marked as starting methods, determine the control flow information; - Generate the first knowledge graph based on the control flow information.
4. The method of claim 1, wherein, The first information includes the data stream information. The first information is obtained (S202) from the code of the first software (31), and a first knowledge graph is generated based on the first information, including: - Add (S2024) data calculation points in each execution scenario of the code of the first software (31); - Obtain the data stream information based on each data calculation point; - Generate the first knowledge graph based on the data flow information.
5. The method as described in claim 1, characterized in that, Also includes: - Load (S209) third software (33), the third software (33) including code, data, resources and documents; - Obtain third information (S210) from the code of the third software (33) and / or obtain fourth information (S211) from the data, resources and documents of the third software (33); - Determine (S212) the first key information used for software similarity comparison from the acquired information; - Search the third knowledge graph based on the first key information (S213) to confirm the software that matches the key information.
6. The method as described in claim 1, characterized in that, Also includes: - Determine (S214) the second key information used to describe the software features; - Search the third knowledge graph based on the second key information (S215) to identify software that matches the second key information.
7. A software information organization device (10), characterized in that, include: - A software loading module (201) is configured to load a first software (31), the first software (31) including code, data, resources and documentation; - The first information acquisition module (202) is configured to acquire first information from the code of the first software (31) and generate a first knowledge graph based on the first information; - The second information acquisition module (203) is configured to acquire second information from the data, resources and documents of the first software (31) and generate a second knowledge graph based on the second information; wherein for the semi-structured content of the data, resources and documents of the first software (31), the second information is acquired using predefined rules; for the unstructured content of the data, resources and documents of the first software (31), the second information is acquired using natural language processing methods. - The knowledge collection module (204) is configured to merge the first knowledge graph and the second knowledge graph into the third knowledge graph; The third knowledge graph is stored in a knowledge graph library; the user's instruction to search for software similar to the second software is received; the second software (32) is loaded, the second software (32) including code, data, resources and documents; The third information is obtained from the code of the second software (32), and a fourth knowledge graph is generated based on the third information; the fourth information is obtained from the data, resources and documents of the second software (32), and a fifth knowledge graph is generated based on the fourth information; wherein, for the semi-structured content in the data, resources and documents of the second software (32), the fourth information is obtained using predefined rules; for the unstructured content in the data, resources and documents of the second software (32), the fourth information is obtained using natural language processing methods; the fourth knowledge graph and the fifth knowledge graph are compared with one or more knowledge graphs stored in the knowledge graph library to determine software similar to the second software (32); The first information includes at least one of the following: - Static code information; - Abstract Syntax Tree (AST) data; - Control flow information; - Data flow information; The first information acquisition module (202) is further configured as follows: - At least two pieces of static code information are obtained from the code of the first software (31) using static analysis methods (S2021), and - Obtain the relationship between the at least two pieces of static code information, and generate the first knowledge graph based on the at least two pieces of static code information and the relationship between the at least two pieces of static code information.
8. A software information organization device (10), characterized in that, include: At least one memory (101) is configured to store computer-readable code; At least one processor (102) is configured to invoke the computer-readable code to perform the method as described in any one of claims 1 to 6.
9. A computer-readable medium, characterized in that, The computer-readable medium stores computer-readable instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Knowledge graph ontology model construction method and device thereof
CN111191050A