Semantic-based code search method and device
By generating the program expression equivalence graph (E-PEG) in the code base and converting the user's search conditions into the E-PEG program expression graph, semantic code search is realized, solving the problem that code search depends on the existing technology Keyword issues improve search efficiency and scope.
Patent Information
- Application Number
- CN202110712983.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-25
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2041-06-25
AI Technical Summary
In the prior art, code search relies on keyword search and cannot search according to semantics, resulting in limited search results and lack of suitable semantic code search tools.
By performing operator node processing and data flow edge processing on the code in the target code base, a program expression equivalent graph (E-PEG) is generated; the user's search conditions are converted into E-PEG program expression graphs, and expressed in the program, etc. Search for E-PEG program expression diagram in the price chart to realize semantic code search.
It effectively expands the scope of code search, supports code search across development languages, and improves code search efficiency through cache, making development work more convenient.
Smart Images

Figure CN113434539B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of big data technology, and in particular to distributed system service calls, and specifically to a semantic-based code search method and device. Background Art
[0002] With the popularization of computer technology, the volume of code in software is getting larger and larger. As a result, it is a common and daunting task to find all logically similar codes in the code base during software development. For example, if a bug is found in a piece of idiomatic code, the developer needs to modify all programs containing this code. In addition, for the sake of efficiency and quality, developers often need to find and refer to existing code from the code base to write new code, or find some code that needs to be refactored. Traditional code search is helpful in locating such code, but it still misses some code that has changed and is not foreseen by the regular pattern (code keywords). With the rise of artificial intelligence technology, it can be foreseen that semantic code search will make code search more convenient.
[0003] Semantic code search is the task of retrieving relevant code given a query described in natural language. Although related to other information retrieval tasks, it requires bridging the gap between the language used in code (which is often abbreviated and highly technical) and natural language, which is more suitable for describing vague concepts and ideas.
[0004] In summary, in the prior art, code search uses keywords to search, but cannot be searched according to semantics, and the effect is relatively limited. Currently, there is no suitable semantic code search tool in the software development industry. Therefore, how to provide a new solution to solve the above problems is a technical problem that needs to be solved urgently in this field. Summary of the invention
[0005] The present invention belongs to the field of big data technology. The semantic-based code search method and device provided by the present invention can achieve the following technical effects: it can effectively expand the scope of code search, support code search across development languages, and apply high-speed cache to effectively improve code search efficiency; it can expand the configuration of grammar rules of multiple development languages to expand the scope of application.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] In a first aspect, the present invention provides a semantic-based code search method, comprising:
[0008] Perform operator node processing and data flow edge processing on the codes in the target code base to generate a program expression equivalence graph;
[0009] Convert the user's search criteria into an E-PEG program expression graph;
[0010] Search the E-PEG program expression graph in the program expression equivalence graph to query the target code.
[0011] In one embodiment, performing operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalence graph includes:
[0012] Generate a PEG program expression graph according to the codes in the target code library by using a program dependency graph method;
[0013] The De Morgan method is used to generate a program expression equivalence graph based on the PEG program expression graph.
[0014] In one embodiment, the semantic-based code search method further includes:
[0015] Receive the user's search criteria and search mode.
[0016] In one embodiment, converting the user's search conditions into an E-PEG program expression graph includes:
[0017] According to the programming language rules of the target code library, the search conditions and search patterns are converted into an E-PEG program expression graph.
[0018] In a second aspect, the present invention provides a semantic-based code search device, comprising:
[0019] The E-PEGs generation module is used to process the operator nodes and data flow edges of the codes in the target code base to generate a program expression equivalence graph;
[0020] The E-PEG generation module is used to convert the user's search conditions into an E-PEG program expression graph;
[0021] The target code query module is used to search the E-PEG program expression graph in the program expression equivalence graph to query the target code.
[0022] In one embodiment, the E-PEGs generation module includes:
[0023] A PEG generation unit, used to generate a PEG program expression graph according to the codes in the target code library by using a program dependency graph method;
[0024] The E-PEGs generation unit is used to generate a program expression equivalent graph according to the PEG program expression graph using the De Morgan method.
[0025] In one embodiment, the semantic-based code search device further includes:
[0026] The search mode receiving module is used to receive the user's search conditions and search mode.
[0027] In one embodiment, the E-PEG generation module includes:
[0028] The E-PEG generation unit is used to convert the search conditions and search patterns into an E-PEG program expression graph according to the programming language rules of the target code library.
[0029] In a third aspect, the present invention provides 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 a semantic-based code search method when executing the program.
[0030] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of a semantic-based code search method when executed by a processor.
[0031] From the above description, it can be seen that the semantic-based code search method and device provided by the embodiment of the present invention first performs operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalent graph; then, the user's search conditions are converted into an E-PEG program expression graph; finally, the E-PEG program expression graph is searched in the program expression equivalent graph to query the target code. The present invention is based on program dependence graphs (PDG) and program expression graphs (PEG), and identifies program expression equivalent graphs (Equivalent program expression graph, E-PEG) by using De Morgan's law (for example), combining programming language specific grammatical rules and the custom rules of the present invention. Developers only need to set query conditions (custom rules of the present invention) according to DSL (Domain Specific Language), and they can efficiently perform code search according to semantics and return search results, making development work more convenient. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 The flowchart of the semantic-based code search method in the embodiment of the present invention is as follows: Figure 1 ;
[0034] Figure 2 1 is a flow chart of step 100 in the semantic-based code search method in an embodiment of the present invention;
[0035] Figure 3 The PEG program expression in the embodiment of the present invention is Figure 1 ;
[0036] Figure 4 The flowchart of the semantic-based code search method in the embodiment of the present invention is as follows: Figure 2 ;
[0037] Figure 5 Schematic diagram of the process of step 200 in the semantic-based code search method in an embodiment of the present invention;
[0038] Figure 6 The PEG program expression in the embodiment of the present invention is Figure 2 ;
[0039] Figure 7 It is a structural diagram of a semantic-based code search system in a specific application example of the present invention;
[0040] Figure 8 It is a structural diagram of a system management device 1 in a specific application example of the present invention;
[0041] Fig. 9 It is a structural schematic diagram of a user search device 2 in a specific application example of the present invention;
[0042] Fig.10 It is a structural schematic diagram of a pattern recognition and matching device 3 in a specific application example of the present invention;
[0043] Fig.11 It is a structural schematic diagram of a code analysis and conversion device 4 in a specific application example of the present invention;
[0044] Fig.12 It is a flowchart of a semantic-based code search method in a specific application example of the present invention;
[0045] Fig.13 It is the expression diagram of E-PEG program in the specific application example of the present invention;
[0046] Fig.14 The structure of the semantic-based code search device in the embodiment of the present invention is shown in FIG. Figure 1 ;
[0047] Fig.15 Schematic diagram of the structure of the E-PEGs generation module 10 in an embodiment of the present invention;
[0048] Fig.16 The structure of the semantic-based code search device in the embodiment of the present invention is shown in FIG. Figure 2 ;
[0049] Fig.17 Schematic diagram of the structure of the E-PEG generation module 20 in an embodiment of the present invention;
[0050] Fig.18 It is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0052] 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.
[0053] It should be noted that the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or apparatuses.
[0054] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0055] The embodiment of the present invention provides a specific implementation of a semantic-based code search method, see Figure 1 , the method specifically includes the following contents:
[0056] Step 100: Perform operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalence graph.
[0057] Operator nodes, such as "addition", "subtraction", "multiplication", and "division", represent conditional expressions and loops; data flow edges represent the source of parameters of operator nodes. In addition, the program expression equivalent graph in step 100 is referred to as E-PEGs; Program Expression Graph (PEG).
[0058] Step 200: Convert the user's search conditions into an E-PEG program expression graph.
[0059] First, PEG is generated and then converted into E-PEG. In addition, it can be understood that the E-PEG program expression graph refers to the program expression equivalent graph (Equivalent program expression graph, E-PEG); program dependency graphs (programdependence graphs, PDG).
[0060] Step 300: Search the E-PEG program expression graph in the program expression equivalence graph to query the target code.
[0061] Specifically, find the E-PEG that meets the search pattern from the E-PEGs of all codes, and return the corresponding specific code.
[0062] From the above description, it can be seen that the semantic-based code search method provided by the embodiment of the present invention first performs operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalent graph; then, the user's search conditions are converted into an E-PEG program expression graph; finally, the E-PEG program expression graph is searched in the program expression equivalent graph to query the target code. The present invention is based on program dependence graphs (PDG) and program expression graphs (PEG), and identifies program expression equivalent graphs (Equivalent program expressiongraph, E-PEG) by using De Morgan's law (for example), combining programming language specific grammatical rules and the custom rules of the present invention. Developers only need to set query conditions (custom rules of the present invention) according to DSL (Domain Specific Language, domain specific language), and they can efficiently perform code search according to semantics and return search results, making development work more convenient.
[0063] In one embodiment, see Figure 2 , step 100 further comprises:
[0064] Step 101: Generate a PEG program expression graph according to the codes in the target code library by using a program dependency graph method;
[0065] Step 102: Using the De Morgan method, a program expression equivalence graph is generated according to the PEG program expression graph.
[0066] In step 101 and step 102, the system analyzes all the codes in the code base, generates PEGs, and then converts them into E-PEGs; the Program Expression Graph (PEG) consists of two parts: (1) operator nodes, such as "addition", "subtraction", "multiplication", "division", and representing conditional expressions and loops; (2) data flow edges, indicating the source of the parameters of the operator nodes. For example, the following code and the corresponding PEG (see Figure 3 ).
[0067] Code:
[0068] i:=0;
[0069] while(...){
[0070] use(i×5);
[0071] i:=i+1;
[0072] if(...){
[0073] i:=i+3;
[0074] }
[0075] }
[0076] exist Figure 3 In the code, node 1 represents i×5 in the loop, which is multiplied by node 2 (operation result) and 5 in the graph; node 2 (θ) represents the value of variable i in the loop, and θ is used to represent the value of the variable in the loop. The left child of the θ node represents the initial value of the variable, and the right child represents the value calculated in the current loop. In the graph, the left child of the θ node is 0, which means that i is initialized to 0 (i:=0). The right child of the θ node uses nodes 3, 4, and 5 to calculate the value of i in the current loop. Nodes 4 and 5 represent the increment of i in the loop, and the Φ node (node 3) represents the merge of the results of nodes 4 and 5. The Φ node is calculated as follows: the first child node (the leftmost child node) is a conditional selection, which is used to select one of the second and third parameters (child nodes) as the result of the Φ node.
[0077] In one embodiment, see Figure 4 ,Semantic-based code search methods also include:
[0078] Step 400: Receive the user's search conditions and search mode.
[0079] In one embodiment, see Figure 5 , step 200 further comprises:
[0080] Step 201: According to the programming language rules of the target code library, the search conditions and search patterns are converted into an E-PEG program expression graph.
[0081] For example, the code search pattern is: x<lo or x> =hi. Then the following PEG can be generated (see Figure 6 ).
[0082] If an equivalent triggering pattern is found in PEG, it will be converted to E-PEG. If no equivalent analysis is triggered, the PEG will be regarded as E-PEG.
[0083] To further illustrate the present solution, the present invention also provides a specific application example of the semantic-based code search method.
[0084] In this specific application example, a semantic-based code search system is also provided. Figure 7 The system includes: a system management device 1, a user search device 2, a pattern recognition and matching device 3, and a code analysis and conversion device 4.
[0085] The system management device 1 is connected to the code analysis conversion device 4; the user search device 2 is connected to the pattern matching device 3; the user search device 2 is connected to the code analysis conversion device 4; the pattern recognition matching device 3 is connected to the code analysis conversion device 4.
[0086] System management device 1: The system administrator uses this device to maintain the system's customized general rules and specific rule sets for multiple development languages. These rules are used when analyzing codes.
[0087] User search device 2: The user searches for codes through this device, inputs query conditions according to the system's custom rules, and specifies the code library. The system returns the query results after completing the search.
[0088] Code analysis and conversion device 3: This device analyzes the entire code base according to the general rules and language-specific rules maintained in the system, converts it into a series of PEGs, and then converts it into E-PEG according to De Morgan's law.
[0089] Pattern recognition and matching device 4: This device analyzes and generates E-PEG according to the query conditions input by the user, and then performs query matching in the results of the code analysis and conversion device 3 according to the E-PEG. After a successful match, the code corresponding to this E-PEG is obtained and the result is returned to the user search device.
[0090] Figure 8 is a schematic diagram of the internal structure of the system management device 1, such as Figure 8 As shown, the system management device 1 includes a custom general rule unit 11, a Java language rule unit 12, a Python language rule unit 13 and a language rule expansion unit 14, wherein:
[0091] Customized General Rules Unit 11: Configure system customized rules, such as customized query input rules and DeMorgan's law.
[0092] Java Language Rules Unit 12: Configure the grammar rules of the development language Java.
[0093] Python Language Rules Unit 13: Configure the grammar rules of the development language Python.
[0094] Language rule extension unit 14: The system supports the extension and configuration of grammar rules of other development languages.
[0095] Fig. 9 is a schematic diagram of the internal structure of the user search device 2, such as Fig. 9 As shown, the model device 2 includes a query input unit 21 and a query output unit 22, wherein:
[0096] Query input unit 21: provides a user query input interface, including common methods such as web services, APIs, CLIs, SDKs, etc., and checks whether the query input complies with the system custom rules.
[0097] Query output unit 22: returns the query results to the user client, including common methods such as web services, APIs, CLIs, SDKs, etc.
[0098] Fig.10 is a schematic diagram of the internal structure of the pattern recognition and matching device 3, such as Fig.10 As shown, the pattern recognition and matching device 3 includes a query conversion E-PEG unit 31, an E-PEG pattern matching unit 32 and a data cache unit 33. Among them:
[0099] Query conversion E-PEG unit 31: analyzes query input conditions, converts E-PEG according to rules, and stores it in cache.
[0100] E-PEG pattern matching unit 32: according to the E-PEG converted by the query, connect the code analysis conversion device to search and match the E-PEG, and obtain the corresponding code and store it in the cache after the match is successful.
[0101] Data cache unit 33: provides a high-speed cache for storing query input conditions, E-PEG, code query results and other data to improve system operation efficiency.
[0102] Fig.114 is a schematic diagram of the internal structure of the code analysis conversion device 4, such as Fig.11 As shown, the code analysis conversion device 4 includes a code conversion PEG unit 41, a PEG conversion E-PEG unit 42 and a data cache unit 43. Among them:
[0103] Code conversion PEG unit 41: analyzes all codes in the specified code base, generates a series of PEGs according to rule conversion, and stores them in the cache.
[0104] PEG conversion E-PEG unit 42: converts a series of PEGs into several E-PEGs according to the rules and stores them in the cache.
[0105] Data cache unit 43: provides a high-speed cache for storing data such as codes (indexes), PEG, E-PEG, etc., to improve system operation efficiency.
[0106] See also Fig.12 Based on the above semantic-based code search system, the semantic-based code search method provided in this specific application example specifically includes the following steps:
[0107] Step S101: The system starts to boot up.
[0108] System administrators maintain system-customized general rules, as well as specific rule sets for different development languages, such as Python, Java, etc.
[0109] Step S102: The administrator configures various rules in the system.
[0110] Step S103: calling the user search device, and the user inputs the code query condition to perform code search.
[0111] The user enters query conditions and searches, that is, specifies the code base and search mode;
[0112] Step S104: calling the code analysis and conversion device, analyzing the user-specified code base, and performing conversion to generate E-PEG.
[0113] Specifically, Equivalence PEG (E-PEG) divides the nodes of PEG into equivalence classes. Fig.13 , is the E-PEG of the above PEG. The dotted line in the figure represents the equivalent relationship between two nodes.
[0114] exist Fig.13 In , an equivalence analysis has two parts: a trigger for the equivalent representation pattern and a callback function that is called when the equivalent pattern is found.
[0115] The simplest equivalent analysis is, for example, a×0=0. The trigger mode is a×0, and the callback function is to add the equivalent expression a×0=0.
[0116] A complete equivalence analysis requires the following three basic rules:
[0117] (1) (a+b)×m=a×m+b×m
[0118] (2)θ(a,b)×m=θ(a×m,b×m)
[0119] (3)Φ(a,b,c)×m=Φ(a,b×m,c×m)
[0120] Specifically, using rule 2, edge A is added (adding nodes 6 and 7); rule 3 adds edge B (adding nodes 8, 9, and 11), rule 1 adds edge C (adding node 10), and rule 1 adds edge D (adding node 12). In addition, the constant operation is simplified to the result (dashed line), that is, 0×5=0, 3×5=15, and 1×5=5. Note that when using rule 1 to add node 12, the right child node θ(…)×5 of node 12 is not added because it already exists in the graph (node 1 or node 6).
[0121] It can be seen that there are 7 dotted lines in E-PEG, representing 7 equivalent relations. If program codes are used to implement the same logical relationship, there are a total of 2^7=128 program codes. Therefore, an E-PEG can efficiently represent multiple program codes to implement the same logic.
[0122] Step S105: Call the pattern recognition and matching device, analyze the user query conditions, convert and generate E-PEG, match the E-PEG generated by the code library, obtain the code that meets the query conditions, and return it to the user search device.
[0123] The system analyzes the search pattern, generates PEG, and then converts it into E-PEG; for example, the code search pattern is: x<lo orx> =hi. Then we can generate Figure 6 If an equivalent triggering pattern is found in the PEG, it is converted to E-PEG, referring to step S104. If no equivalent analysis is triggered, the PEG is regarded as E-PEG.
[0124] Step S106: calling the user search device, and the user obtains the code query result.
[0125] The system (pattern matching module) finds the E-PEG that matches the search pattern from all the E-PEGs of the code and returns the corresponding specific code.
[0126] Step S107: Based on the query results, the user can adjust the query conditions and search again.
[0127] From the above description, it can be seen that in order to solve the problems of low code search efficiency, limited query scope and accuracy in software development work, the present invention provides a semantic code search method based on natural language rules. Its beneficial effects are as follows:
[0128] 1. Enter the query conditions according to the system rules (semantic rules), analyze and convert the entire code base to generate E-PEG, which can effectively expand the code search scope, support code search across development languages, and apply high-speed cache to effectively improve code search efficiency;
[0129] 2. It can extend and configure multiple development language syntax rules to expand the scope of application.
[0130] Based on the same inventive concept, the embodiments of the present application also provide a semantic-based code search device, which can be used to implement the method described in the above embodiments, such as the following embodiments. Since the principle of solving the problem by the semantic-based code search device is similar to that of the semantic-based code search method, the implementation of the semantic-based code search device can refer to the implementation of the semantic-based code search method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements predetermined functions. Although the system described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.
[0131] The embodiment of the present invention provides a specific implementation of a semantic-based code search device capable of implementing a semantic-based code search method, see Fig.14 , the semantic-based code search device specifically includes the following contents:
[0132] An E-PEGs generation module 10 is used to perform operator node processing and data flow edge processing on the codes in the target code library to generate a program expression equivalence graph;
[0133] An E-PEG generation module 20, for converting the user's search conditions into an E-PEG program expression graph;
[0134] The target code query module 30 is used to search the E-PEG program expression graph in the program expression equivalence graph to query the target code.
[0135] In one embodiment, see Fig.15 , the E-PEGs generation module 10 comprises:
[0136] A PEG generation unit 101 is used to generate a PEG program expression graph according to the code in the target code library by using a program dependency graph method;
[0137] The E-PEGs generating unit 102 is used to generate a program expression equivalent graph according to the PEG program expression graph by using the De Morgan method.
[0138] In one embodiment, see Fig.16 , the semantic-based code search device also includes:
[0139] The search mode receiving module 40 is used to receive the user's search conditions and search mode.
[0140] In one embodiment, see Fig.17 , the E-PEG generation module 20 includes:
[0141] The E-PEG generation unit 201 is used to convert the search conditions and search patterns into an E-PEG program expression graph according to the programming language rules of the target code library.
[0142] From the above description, it can be seen that the semantic-based code search device provided by the embodiment of the present invention first performs operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalence graph; then, the user's search conditions are converted into an E-PEG program expression graph; finally, the E-PEG program expression graph is searched in the program expression equivalence graph to query the target code. The present invention is based on program dependence graphs (PDG) and program expression graphs (PEG), and identifies program expression equivalence graphs (Equivalent program expressiongraph, E-PEG) by using De Morgan's law (for example), combining programming language specific grammatical rules and the custom rules of the present invention. Developers only need to set query conditions (custom rules of the present invention) according to DSL (Domain Specific Language), and they can efficiently perform code search according to semantics and return search results, making development work more convenient.
[0143] Reference below Fig.18 , which shows a schematic structural diagram of an electronic device 600 suitable for implementing an embodiment of the present application.
[0144] like Fig.18As shown, electronic device 600 includes a central processing unit (CPU) 601, which can perform various appropriate operations and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage portion 608 into a random access memory (RAM) 603. In RAM 603, various programs and data required for the operation of system 600 are also stored. CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to bus 604.
[0145] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed as needed as the storage section 608.
[0146] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above-mentioned method for determining the distance between people in a data center scenario are implemented, and the steps include:
[0147] Step 100: Perform operator node processing and data flow edge processing on the code in the target code library to generate a program expression equivalence graph;
[0148] Step 200: converting the user's search conditions into an E-PEG program expression graph;
[0149] Step 300: Search the E-PEG program expression graph in the program expression equivalence graph to query the target code.
[0150] In such an embodiment, the computer program may be downloaded and installed from a network via the communication section 609 , and / or installed from the removable medium 611 .
[0151] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0152] 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.
[0153] 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 comprising 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.
[0154] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, commodity or device including the element.
[0155] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0156] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A semantic-based code search method, characterized in that: include: Perform operator node processing and data flow edge processing on the codes in the target code base to generate a program expression equivalence graph; Convert the user's search criteria into an E-PEG program expression graph; Searching the E-PEG program expression graph in the program expression equivalence graph to query the target code; The code in the target code library is processed by operator nodes and data flow edges to generate a program expression equivalence graph, including: Generate a PEG program expression graph according to the codes in the target code library by using a program dependency graph method; Using the De Morgan method, a program expression equivalent graph is generated according to the PEG program expression graph; specifically: The system analyzes all the code in the code base, generates PEGs, and then converts them into E-PEGs; PEGs consists of two parts: Operator nodes, including: "add", "subtract", "multiply", "divide", and represent conditional expressions and loops; Data flow edge, indicating the source of the operator node's parameters.
2. The semantic-based code search method according to claim 1, characterized in that: Also includes: Receive the user's search criteria and search mode.
3. The semantic-based code search method according to claim 2, characterized in that: The step of converting the user's search conditions into an E-PEG program expression graph comprises: According to the programming language rules of the target code library, the search conditions and search patterns are converted into an E-PEG program expression graph.
4. A semantic-based code search device, characterized in that: include: The E-PEGs generation module is used to process the operator nodes and data flow edges of the codes in the target code base to generate a program expression equivalence graph; The E-PEG generation module is used to convert the user's search conditions into an E-PEG program expression graph; A target code query module, used for searching the E-PEG program expression graph in the program expression equivalence graph to query the target code; The E-PEGs generation module comprises: A PEG generation unit, used to generate a PEG program expression graph according to the codes in the target code library by using a program dependency graph method; The E-PEGs generation unit is used to generate a program expression equivalent graph according to the PEG program expression graph using the De Morgan method; specifically: The system analyzes all the code in the code base, generates PEGs, and then converts them into E-PEGs; PEGs consists of two parts: Operator nodes, including: "add", "subtract", "multiply", "divide", and represent conditional expressions and loops; Data flow edge, indicating the source of the operator node's parameters.
5. The semantic-based code search device according to claim 4, characterized in that: Also includes: The search mode receiving module is used to receive the user's search conditions and search mode.
6. The semantic-based code search device according to claim 5, characterized in that: The E-PEG generation module includes: The E-PEG generation unit is used to convert the search conditions and search patterns into an E-PEG program expression graph according to the programming language rules of the target code library.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the semantic-based code search method according to any one of claims 1 to 3 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the semantic-based code search method according to any one of claims 1 to 3 are implemented.