Identification method for use module in target source code and related equipment

Through fine-grained dependency analysis method, the target project source code is analyzed and the dependency package usage module is identified, which solves the problems of false alarms and missed reports in existing tools, and realizes more accurate identification of dependency package usage modules, improving analysis efficiency and performance .

CN119127688APending Publication Date: 2024-12-13CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411173940.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-24
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

Existing tools and libraries are prone to false positives and missed reports when identifying dependent package usage modules, and lack comprehensive dependent package usage module identification and association support.

Method used

The target project source code is analyzed using fine-grained dependency analysis method. By reading the package.json file, the usage module in each dependency is identified, and the dependency relationship is determined based on the import statement in the file content, and the dependency object is constructed to avoid errors. Report and missed report.

Benefits of technology

It provides a more accurate and reliable dependency package identification result using module, avoids false positives and missed reports, and improves analysis efficiency and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127688A_ABST
    Figure CN119127688A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of artificial intelligence and big data, is applied to the field of smart cities, and relates to a method for identifying a use module in a target source code, which comprises the following steps: acquiring a target project source code; carrying out refined analysis on the target project source code through a preset fine-grained dependency analysis method to obtain a dependency relationship between the structure and the code of the target project source code; and based on the dependency relationship between the target project source code structure and the code, determining a use module of a specific dependency packet in the target project source code. The invention further provides an identification device for the use module in the target source code, computer equipment and a storage medium. According to the method and the device, the problem that false alarm and missing alarm are easy to occur when an existing identification method identifies the dependent packet use module is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence and big data technology, and in particular to a method for identifying modules used in target source code and related equipment. Background Art

[0002] There are some tools and libraries in the industry for analyzing project source code and identifying modules used by dependent packages. However, in some requirements, in order to further analyze project dependencies, it is necessary to determine which modules are specifically used in the dependencies and which dependencies are introduced but not specifically used. Existing tools and libraries usually provide some static code analysis functions, and the analysis of dependencies is limited to package.json, but lack comprehensive support for module identification and association of dependent packages. Therefore, there is an urgent need for a method to identify modules used in the target source code to solve the problem that the existing identification methods are prone to false positives and false negatives in identifying modules used by dependent packages. Summary of the invention

[0003] The purpose of the embodiments of the present application is to propose a method for identifying modules used in target source code and related equipment to solve the problem that the existing identification methods are prone to false positives and false negatives in identifying modules used in dependent packages. Its main purpose is to provide more accurate and reliable identification results of modules used in dependent packages, avoiding false positives and false negatives.

[0004] In order to solve the above technical problems, the embodiment of the present application provides a method for identifying modules used in target source code, which adopts the following technical solution:

[0005] Get the target project source code;

[0006] Performing a detailed analysis on the target project source code by a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency;

[0007] Based on the target project source code structure and code dependencies, determine the usage modules of specific dependent packages in the target project source code.

[0008] Furthermore, the target project source code is analyzed in detail by a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency, including:

[0009] node.fs reads package.json in the target project source code through a preset fine-grained dependency analysis method, and passes the dependencies read from the package.json into the recognition function, where the dependencies include the used modules;

[0010] The identification function traverses and loops each dependency of the dependencies to obtain the used module in each dependency, and the object of the used module created in each dependency includes a version and an empty attribute;

[0011] Based on the used modules in each dependency, the source code structure and code dependency of the target project are obtained.

[0012] Furthermore, after obtaining the source code structure and code dependency of the target project based on the usage module in each dependency, the method further includes:

[0013] Get the directory where node.js is currently running, and fs.readdirSync reads all files in the current directory fileList;

[0014] Filter each file in all the files fileList to obtain the filtered file file.

[0015] Furthermore, after filtering each file in all the files fileList to obtain the filtered file file, the method further includes:

[0016] Performing character encoding processing on the file content of the file file by using a preset character encoder to obtain a file content character string;

[0017] Identify whether the content of "import*from*" is used in the file content string;

[0018] If the content using "import*from*" is identified, the dependency of the module used in the file file is determined, and the corresponding imported file content is obtained based on the dependency, wherein the file content after the from corresponds to a certain dependency, the content before the from is the file content introduced by the dependency, and the * is any file content.

[0019] Furthermore, after performing character encoding processing on the file content of the file file by a preset character encoder to obtain a file content character string, the method further includes:

[0020] Replace all file content strings mentioned with "|as|".

[0021] Furthermore, if the content using "import*from*" is identified, the dependency relationship of the modules used in the file file is determined, and the corresponding imported file content is obtained based on the dependency relationship, the method further includes:

[0022] The content before the from is split into multiple parts according to the "," split character string, and the imported file content character string is determined;

[0023] Identify whether each imported file content string contains "{}" or "|as|";

[0024] If there is "{}", first remove the first end "{}" and the last end "{}", and extract the file content inside the curly brackets;

[0025] If there is "|as|", the first half of the "|as|" file content is collected;

[0026] If there is no "{}" or "|as|", the file content that needs to be imported is determined from all file contents;

[0027] Store the processed imported file content into the empty attribute of the dependency object of the currently used module and submit it to the backend database storage.

[0028] Furthermore, after determining the usage module of the specific dependent package in the target project source code based on the target project source code structure and the code dependency, the method further includes:

[0029] Visualize the dependencies of modules used in the target source code and the associations between modules used.

[0030] In order to solve the above technical problems, the present application also provides a device for identifying modules used in target source code, which adopts the following technical solution:

[0031] The first acquisition module is used to obtain the target project source code;

[0032] A refinement analysis module, used to perform refinement analysis on the target project source code by a preset fine-grained dependency analysis method to obtain the source code structure and code dependency of the target project;

[0033] The first determination module is used to determine the usage module of the specific dependent package in the target project source code based on the source code structure of the target project and the dependency relationship of the code.

[0034] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0035] The computer device includes a memory and a processor, the memory stores computer-readable instructions, and the processor implements the steps of the method for identifying modules used in the target source code described in any one of the embodiments of the present application when executing the computer-readable instructions.

[0036] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0037] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the method for identifying a module used in a target source code according to any one of the embodiments of the present invention are implemented.

[0038] Compared with the prior art, the embodiments of the present application have the following beneficial effects: a preset fine-grained dependency analysis method is used to perform a detailed analysis of the target project source code to obtain the target project source code structure and code dependency relationship, and based on the target project source code structure and code dependency relationship, the usage module of the specific dependency package in the target project source code is determined, thereby solving the problem that the existing identification method is prone to false positives and missed negatives in identifying the usage module of the dependency package. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0040] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0041] Figure 2 A flowchart of an embodiment of a method for identifying modules used in target source code according to the present application;

[0042] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S202;

[0043] Figure 4 is Figure 3 A flowchart of a specific implementation method after step S2023;

[0044] Figure 5 yes Figure 4 A flowchart of a specific implementation method after step S402;

[0045] Figure 6 yes Figure 5 A flowchart of a specific implementation method after step S503;

[0046] Figure 7 It is a visualization of the identification method of modules used in the target source code of this application;

[0047] Figure 8 yes Figure 7 A visualization diagram of a specific implementation method;

[0048] Fig. 9 is a structural schematic diagram of an embodiment of a device for identifying modules used in target source code according to the present application;

[0049] Fig.10 yes Fig. 9 A structural diagram of a specific implementation of the refinement analysis module 902;

[0050] Fig.11 yes Fig. 9 A schematic structural diagram of another specific implementation of a device 900 for identifying modules used in target source code;

[0051] Fig.12 yes Fig. 9 A schematic structural diagram of another specific implementation of a device 900 for identifying modules used in target source code;

[0052] Fig.13 yes Fig. 9 A schematic structural diagram of another specific implementation of a device 900 for identifying modules used in target source code;

[0053] Fig.14 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0054] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; 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. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0055] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0056] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0057] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0058] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0059] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV), laptop computers, desktop computers, etc.

[0060] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .

[0061] It should be noted that the method for identifying the used modules in the target source code provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the device for identifying the used modules in the target source code is generally set in the server / terminal device.

[0062] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0063] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for identifying a module used in a target source code according to the present application. The method for identifying a module used in a target source code comprises the following steps:

[0064] Step S201, obtaining the target project source code.

[0065] In this embodiment, the target source code uses the module identification method to run on the electronic device (for example Figure 1 The server / terminal device shown in the figure can receive the identification request of the module used in the target source code of the terminal device through a wired connection method or a wireless connection method. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.

[0066] The above-mentioned terminal devices may be terminal devices equipped with remote interaction functions such as personal assistants and intelligent customer service.

[0067] The above-mentioned method for identifying modules used in the target source code can be applied to online file query, online file management and other businesses.

[0068] Specifically, the above-mentioned electronic device can be used for different industry types such as identification of modules used in medical target source codes, identification of modules used in insurance target source codes, identification of modules used in financial target source codes, and identification of modules used in store target source codes.

[0069] Specifically, the target project source code can be understood as the source code of the target project. The source code of the target project includes the directory structure and file organization, such as code files for different modules such as model building, training, and configuration.

[0070] It should be noted that the project source code may change with the update of the version.

[0071] Step S202: Perform a detailed analysis on the target project source code using a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency.

[0072] In this embodiment, the above-mentioned preset fine-grained dependency analysis method is a fine-grained dependency analysis method preset by the system and is based on static code analysis technology. The fine-grained dependency analysis method is a technology that can reveal small structural changes in source code, such as function calls, variable modifications, etc. By analyzing these small changes, it is possible to understand information such as the execution flow of the code and the dependencies between modules. Static code analysis technology is a technology that uses a code parser and related algorithms to build an abstract syntax tree (AST) of the code without actually executing the program, so as to better understand and analyze the code structure and dependencies.

[0073] The above detailed analysis can be understood as the process of comprehensive scanning and analysis of the project source code by the target.

[0074] The above target project source code structure and code dependencies can be understood as understanding and analyzing the connections and interactions between various elements in the source code.

[0075] Specifically, the structure of the target project source code and the dependencies of the code include determining the analysis target and scope, and analyzing the calling relationships between functions. Dependency refers to the dependence of one software component on another, which may be caused by functional requirements, data sharing, third-party libraries, etc.

[0076] Step S203: Based on the source code structure of the target project and the dependency relationship of the code, determine the usage module of the specific dependency package in the source code of the target project.

[0077] In this embodiment, after obtaining the target project source code structure and code dependency, the electronic device can determine the usage module of the specific dependency package in the target project source code according to the target project source code structure and code dependency.

[0078] In this embodiment, the present invention can provide more accurate and reliable dependent package usage module identification results through fine-grained dependency analysis and static code analysis technology, avoiding false positives and false negatives. The present invention optimizes the source code analysis of the project and improves the efficiency and performance of the processing. By adopting efficient algorithms and data structures, the dependent package usage modules can be quickly identified, reducing the analysis time and consumption of computing resources, and improving work efficiency.

[0079] The present application performs a refined analysis of the target project source code through a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency relationship, and determines the usage module of the specific dependency package in the target project source code based on the target project source code structure and code dependency relationship, thereby solving the problem that the existing identification methods are prone to false positives and missed negatives in identifying the usage modules of dependency packages.

[0080] Continue to refer Figure 3 , shown in Figure 2 Flow chart of a specific implementation of step S202 in FIG. Step S202 specifically includes the following steps:

[0081] Step S2021, node.fs reads package.json in the target project source code through a preset fine-grained dependency analysis method, and passes the dependencies read from package.json into the recognition function.

[0082] In this embodiment, the above dependencies include using modules. The dependencies attribute is an object that includes other npm packages that the package depends on and their version numbers.

[0083] The above node.fs can be understood as an instance of the fs module. In node.fs, the fs module can be understood as a file system module. The fs module is a module used to process file and directory operations. The fs module provides a preset fine-grained dependency analysis method for reading and identifying file contents, including encoding, file paths, etc. The fs module supports creating, deleting, and traversing directories.

[0084] The above-mentioned preset fine-grained dependency analysis method is a fine-grained dependency analysis method preset by the system and is based on static code analysis technology. The fine-grained dependency analysis method is a technology that can reveal small structural changes in source code, such as function calls, variable modifications, etc. Static code analysis technology uses a code parser and related algorithms to build an abstract syntax tree (AST) of the code without actually executing the program, so as to better understand and analyze the code structure and dependencies.

[0085] In node.fs, package.json is a JSON format file that describes the various dependencies required to make up the entire project. It contains information about the project name, version number, author, license information, and all required dependencies.

[0086] The recognition functions described above are used to recognize or detect specific patterns or features in the input data.

[0087] Furthermore, dependencies are read from the package.json file and then passed as parameters to the recognition function.

[0088] Step S2022: The identification function traverses each dependency in dependencies and obtains the used modules in each dependency.

[0089] In this embodiment, the object of the module created in each dependency contains a version and an empty attribute. The above version can be understood as the library or framework version number to which the module object belongs. For example, if the Spring framework is being used, the version number is the version number of the Spring framework. The above empty attribute can be understood as not being injected into a specific implementation class, and the empty attribute is injected according to the actual implementation class.

[0090] The above traversal loop can be understood as accessing each element in a data structure (such as a list, array, tree, etc.) in sequence and performing the same operation on each element.

[0091] The identification function checks each dependency in dependencies one by one. The identification function is implemented through a structure called an "iteration" or "loop", which allows a program to process the elements of a list, array, or other data structure one by one. In each iteration, the identification function finds and records the modules or libraries used by each dependency.

[0092] Step S2023: Based on the used modules in each dependency, the target project source code structure and code dependency are obtained.

[0093] In this embodiment, the electronic device can obtain the target project source code structure and code dependency by using the module in obtaining each dependency.

[0094] This application uses node.fs to read package.json in the target project source code through a preset fine-grained dependency analysis method, and passes the dependencies read from package.json into the recognition function. The recognition function traverses each dependency of the dependencies and obtains the used modules in each dependency. Based on the used modules in each dependency, the target project source code structure and code dependency are obtained for subsequent recording.

[0095] Continue to refer Figure 4 , showing that in Figure 3 After step S2023, the method for identifying modules used in the target source code further includes the following steps:

[0096] Step S401, obtain the directory where node.js is currently running, and fs.readdirSync reads all files fileList in the current directory.

[0097] In this embodiment, in node.js, the file system can be read and operated through the fs module. The above fs.readdirSync is a synchronous version of the file reading function, which is used to read all file names under a specified directory.

[0098] By calling the fs.readdirSync method and passing in the current directory path, you can synchronously read all files and folders in the directory and return an array containing all file names or folder names.

[0099] All the above files fileList contains a list of all file and folder names in the current directory.

[0100] Step S402: Filter each file in all files fileList to obtain filtered files file.

[0101] In this embodiment, after obtaining the fileList, the electronic device may filter each file in the fileList to obtain the filtered file file.

[0102] The above filtering process can be understood as a process of performing some operations or conditional judgments on each file in the fileList to filter out files that meet specific conditions.

[0103] This application obtains the directory where node.js is currently running, uses fs.readdirSync to read all files fileList in the current directory, and filters each file in fileList to obtain the filtered file file, which can filter out unnecessary files and improve work efficiency.

[0104] Continue to refer Figure 5 , showing Figure 4 A flowchart of a specific implementation method after step S402 in the target source code. After step S402, the method for identifying modules used in the target source code further includes the following steps:

[0105] Step S501, character encoding is performed on the file content of the file file by using a preset character encoder to obtain a file content character string.

[0106] In this embodiment, the preset character encoder is a character encoder preset by the system, specifically a UTF-8 encoder.

[0107] The text content in the file file is converted from the original byte sequence to the corresponding character sequence through the preset character encoder. After the character encoding process is completed, a string containing all characters is obtained. This string can be directly used for subsequent processing.

[0108] Step S502, identifying whether the content of "import*from*" is used in the file content character string.

[0109] In this embodiment, the above “import * from *” can be understood as an import method for importing all exported members (variables, functions, classes, etc.) from a module.

[0110] Step S503: If the content of "import*from*" is identified as being used, the dependency relationship of the modules used in the file file is determined, and the corresponding imported file content is obtained based on the dependency relationship.

[0111] In this embodiment, the file content after the above from corresponds to a certain dependency, the content before the above from is the file content introduced by the dependency, and the above * is any file content.

[0112] The above "import * from *" is a way to import a module, which means importing all public members (methods and properties) from a certain place to the current place.

[0113] In the file file, by identifying the places where "import * from *" is used, the modules that the file depends on can be inferred. For example, if there is "import * from 'math'" in file, then it can be inferred that file depends on the math module.

[0114] After determining the dependencies of the file, you also need to determine which files these dependencies import. For example, if the file depends on the math module, you need to find all the functions and variables defined in the math module and import them into the file.

[0115] The present application performs character encoding processing on the file content of file file through a preset character encoder to obtain a file content string, and identifies whether the content of "import*from*" is used in the file content string. If it is identified that the content of "import*from*" is used, the dependency of the modules used in file file is determined, and the corresponding imported file content is obtained based on the dependency, which can better understand the mutual dependency between files and help tasks such as code optimization and maintenance.

[0116] Optionally, after step S501, the process further includes replacing all file content strings with "|as|".

[0117] In this embodiment, all file contents can be replaced with comments / \ / \ / [^\r\n]* / g, line breaks and semicolons [\r|\n|;], and strings such as "*as*" with "|as|" to facilitate subsequent processing. Among them, * can be any content.

[0118] This application replaces comments / \ / \ / [^\r\n]* / g, line breaks and semicolons [\r|\n|;], and "*as*" strings with "|as|" in all file contents to facilitate subsequent processing.

[0119] Continue to refer Figure 6 , showing Figure 5 After step S503, the method for identifying modules used in the target source code further includes the following steps:

[0120] Step S601, the content before from is split into multiple parts according to the character string “,” to determine the imported file content character string.

[0121] In this embodiment, the file content before from is split according to commas, and then the split parts are processed as independent character strings, and the introduced code files, configuration files, etc. are determined.

[0122] Step S602, identifying whether each imported file content character string contains "{}" or "|as|".

[0123] Step S603, if there is "{}", first take out the first end "{}" and the last end "{}", and extract the file content in the braces.

[0124] In this embodiment, if an imported file content string contains "{}", the part between the "{}" at the beginning and the end of the string is first taken out to extract the file content in the curly brackets. Each imported file content string is looped through.

[0125] Step S604, if there is "|as|", collect the first half of the "|as|" file content.

[0126] In the embodiment of the present invention, if a certain imported file content character string contains "|as|", the first half of the "|as|" file content is collected.

[0127] Step S605: If there is no "{}" or "|as|", the file content that needs to be introduced is determined from all the file contents.

[0128] In the embodiment of the present invention, if there is no "{}" or "|as|", all file contents are traversed in a loop to determine the file content that needs to be introduced.

[0129] Step S606: store the processed imported file content into the empty attribute of the dependency object of the currently used module, and submit it to the backend database for storage.

[0130] In this embodiment, the imported file content that has been processed in a loop is traversed and stored in an empty attribute in the current dependent object, and all processed data is submitted to the backend database for storage for subsequent use or analysis.

[0131] The present application splits the content in front of from into multiple parts by splitting the string with "," to determine the imported file content string, and identifies whether each imported file content string contains "{}" or "|as|". If there is "{}", the first end "{}" and the last end "{}" are first taken out to extract the file content in the curly brackets. If there is "|as|", the first half of the "|as|" file content is collected. If there is no "{}" or "|as|", the file content to be imported is determined from all the file contents. Finally, the processed imported file content is stored in the empty attribute of the dependency object of the currently used module, and submitted to the back-end database for storage for subsequent use or analysis.

[0132] Optionally, after step S203, the method further includes: visually displaying the dependencies of the modules used in the target source code and the associations between the modules used.

[0133] In this embodiment, the above visualization can be understood as visually displaying various complex and changeable information through visualization tools, and the visualization can be a graphical display. The dependency relationship of the modules used in the target source code and the association between the modules used are displayed through the visualization results, so that developers can intuitively understand the use of modules by the dependent packages. By graphically displaying the association between the dependencies and the modules used, developers can easily locate unused dependent packages and make corresponding upgrade and removal decisions.

[0134] This application visualizes the dependencies of modules used in the target source code and the associations between the used modules, which can help developers intuitively understand the use of modules in dependent packages.

[0135] Continue to refer Figure 7 , shows a visualization diagram of the method for identifying modules used in the target source code of the present application. Specifically, Figure 7 As shown in the figure, the dependent package of the module icore_epa_web is ICORE-EPA3.6020220126. Through the visual display, developers can intuitively understand the use of modules by dependent packages. Figure 8 As shown, it is shown that according to Figure 7A visualization diagram of a specific implementation method. Specifically, the content on the left is the project name, the content in the middle is the name of the dependency package, and the content on the right is the method that references the specific dependency of the current dependency. The box in the figure is the method that references the specific dependency of the current dependency. For example, the dependency package of project ^1.0.4 (latest version 1.0.4) is @pafe / icon-vue2, which references the Vuelcon method; the dependency package of project ^1.0.34 (latest version 1.0.149) is @pafe / icon-icore-claim-portal, which references the IconRemindFont method and the IconDecisionCenterFont method; the dependency package of 0.2.14 (latest version 0.0.16-alpha) is @pafe / channel-route, which references the handleRoute method; ... When the latest version of project ^1.0.34 is 1.0.149, it is necessary to mark the project ^1.0.34 with red text and remind to upgrade; when the latest version of 0.2.14 is 0.0.16-alpha, it is necessary to mark the project 0.2.14 with red text and remind to upgrade; ... When the latest version appearing in the project version is different from the project, it is necessary to mark the project version with red text and remind to upgrade. The present invention displays the results through visualization so that developers can intuitively understand the use of modules in dependent packages. By graphically displaying the association between dependencies and used modules, developers can more easily locate unused dependent packages, make corresponding upgrade and removal decisions, and easily locate, upgrade and remove these useless dependencies, thereby improving the maintainability and performance of the project.

[0136] This embodiment can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0137] The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning. This application can be applied to the fields of artificial intelligence and big data, thereby promoting the construction of smart cities.

[0138] This application belongs to the field of smart cities, and this solution can promote the construction of smart cities.

[0139] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0140] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0141] Further references Fig. 9 , as a response to the above Figure 2 The present application provides an embodiment of a device for identifying a module used in a target source code, and the embodiment of the device for identifying a module used in the target source code is similar to Figure 2 Corresponding to the embodiment of the method for identifying the used modules in the target source code shown, the device for identifying the used modules in the target source code can be specifically applied to various electronic devices.

[0142] like Fig. 9 As shown, the device 900 for identifying modules used in target source code according to this embodiment includes: a first acquisition module 901, a refinement analysis module 902 and a first determination module 903. Among them:

[0143] The first acquisition module 901 is used to acquire the target project source code;

[0144] A detailed analysis module 902 is used to perform detailed analysis on the target project source code by using a preset fine-grained dependency analysis method to obtain the source code structure and code dependency of the target project;

[0145] The first determination module 903 is used to determine the usage module of the specific dependent package in the target project source code based on the source code structure and code dependency of the target project.

[0146] In this embodiment, the target project source code is analyzed in detail through a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency relationship, and based on the target project source code structure and code dependency relationship, the usage module of the specific dependency package in the target project source code is determined, thereby solving the problem that the existing identification methods are prone to false positives and missed negatives in identifying the usage modules of dependency packages.

[0147] See also Fig.10 ,for Fig. 9 The structural diagram of a specific implementation of the refinement analysis module 902 is shown in FIG. 9 , wherein the refinement analysis module 902 includes a read module read submodule 9021, a traversal loop submodule 9022, and a creation submodule 9023. Among them:

[0148] The reading submodule 9021 is used for node.fs to read package.json in the target project source code through a preset fine-grained dependency analysis method, and pass the dependencies read from the package.json into the recognition function, wherein the dependencies include the use module;

[0149] A traversal loop submodule 9022 is used for the identification function to traverse each dependency of the dependencies to obtain the use module in each dependency, and the object of the use module created in each dependency includes a version and an empty attribute;

[0150] A submodule 9023 is created to obtain the source code structure and code dependency of the target project based on the used modules in each dependency.

[0151] In this embodiment, package.json is read through node.fs, and the dependencies read from package.json are passed into the identification function. The identification function traverses each dependency of the dependencies and obtains the used modules in each dependency. For each used module in each dependency, an object of the used module in each dependency is created, including the version and empty attributes, for subsequent recording.

[0152] See also Fig.11 ,for Fig. 9 The structure diagram of a specific implementation of the device 900 for identifying modules used in the target source code is shown in FIG. 9 . The device 900 for identifying modules used in the target source code further includes a second acquisition module 904 and a filtering processing module 905. Among them:

[0153] The second acquisition module 904 is used to obtain the directory where node.js is currently running, and fs.readdirSync reads all files fileList in the current directory;

[0154] The filtering processing module 905 is used to filter each file in all the files fileList to obtain the filtered file file.

[0155] In this embodiment, by obtaining the directory where node.js is currently running .js, fs.readdirSync reads all files fileList in the current directory, and filters each file in all files fileList to obtain the filtered file file, which can filter out unnecessary files and improve work efficiency.

[0156] See also Fig.12 ,for Fig. 9 The structure diagram of a specific implementation of a device 900 for identifying modules used in a target source code is shown in FIG. 9 . The device 900 for identifying modules used in a target source code further includes a character encoding processing module 906 , a first identification module 907 and a second determination module 908 .

[0157] The character encoding processing module 906 is used to perform character encoding processing on the file content of the file file by using a preset character encoder to obtain a file content character string;

[0158] A first identification module 907, used to identify whether the content of "import*from*" is used in the file content string;

[0159] The second determination module 908 is used to determine the dependency of the module used in the file file if the content using "import*from*" is identified, and obtain the corresponding imported file content based on the dependency, wherein the file content after the from corresponds to a certain dependency, the content before the from is the file content imported by the dependency, and the * is any file content.

[0160] The file content of file is encoded by a preset character encoder to obtain a file content string, and whether the "import*from*" content is used in the file content string is identified. If the "import*from*" content is identified, the dependency of the modules used in file file is determined, and the corresponding imported file content is obtained based on the dependency, so as to better understand the mutual dependency between files and help tasks such as code optimization and maintenance.

[0161] Optionally, the module identification device used in the target source code is also used to replace all the file content strings with "|as|".

[0162] In this embodiment, comments / \ / \ / [^\r\n]* / g, line breaks and semicolons [\r|\n|;], and strings such as "*as*" are replaced with "|as|" in all file contents to facilitate subsequent processing.

[0163] See also Fig.13 ,for Fig. 9 The structure diagram of a specific implementation of the device 900 for identifying modules used in the target source code, the device 900 for identifying modules used in the target source code further includes a segmentation module 909, a second identification module 910, an extraction module 911, a collection module 912, a third determination module 913 and a submission module 914. Among them:

[0164] The segmentation module 909 is used to segment the content before the from character string according to the character "," into multiple characters, and determine the imported file content character string;

[0165] The second identification module 910 is used to identify whether each imported file content string contains "{}" or "|as|";

[0166] Extraction module 911, for each imported file content string, if there is "{}", first remove the first end "{}" and the last end "{}", and extract the file content in the curly brackets;

[0167] The collection module 912 is used to collect the first half of the content of the "|as|" file if there is "|as|";

[0168] The third determination module 913 is used to determine the file content to be introduced from all the file contents if there is no "{}" or "|as|";

[0169] The submission module 914 is used to store the processed imported file content into the empty attribute of the dependency object of the currently used module, and submit it to the backend database for storage.

[0170] In this embodiment, the content before from is split into multiple parts by splitting the string according to "," to determine the imported file content string, and identify whether "{}" or "|as|" exists in each imported file content string. If there is "{}", the first end "{}" and the last end "{}" are first taken out to extract the file content in the curly brackets. If there is "|as|", the first half of the "|as|" file content is collected. If there is no "{}" or "|as|", the file content to be imported is determined from all file contents. Finally, the processed imported file content is stored in the empty attribute of the dependency object of the currently used module, and submitted to the back-end database for storage for subsequent use or analysis.

[0171] Optionally, the device 900 for identifying used modules in the target source code is further used to display the dependency relationship of used modules and the association between used modules in the target source code through visualization.

[0172] In this embodiment, by visually displaying the dependency relationship of the modules used in the target source code and the association between the modules used, developers can intuitively understand the use of modules in the dependent packages.

[0173] To solve the above technical problems, the present application also provides a computer device. Fig.14 , Fig.14 This is a basic structural block diagram of the computer device in this embodiment.

[0174] The computer device 14 includes a memory 141, a processor 142, and a network interface 143 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 14 with components 141-143, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASIC), programmable gate arrays (FPGA), digital processors (DSP), embedded devices, etc.

[0175] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0176] The memory 141 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc.

[0177] In some embodiments, the memory 141 may be an internal storage unit of the computer device 14, such as a hard disk or memory of the computer device 14. In other embodiments, the memory 141 may also be an external storage device of the computer device 14, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 14. Of course, the memory 141 may also include both the internal storage unit of the computer device 14 and its external storage device. In this embodiment, the memory 141 is generally used to store the operating system and various application software installed on the computer device 14, such as computer-readable instructions of the identification method of the module used in the target source code. In addition, the memory 141 may also be used to temporarily store various types of data that have been output or are to be output. In some embodiments, the processor 142 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 142 is generally used to control the overall operation of the computer device 14. In this embodiment, the processor 142 is used to execute computer-readable instructions or process data stored in the memory 141, such as computer-readable instructions for executing a method for identifying a module used in the target source code.

[0178] The network interface 143 may include a wireless network interface or a wired network interface. The network interface 143 is generally used to establish a communication connection between the computer device 14 and other electronic devices.

[0179] In this embodiment, the impact data of the system in the knowledge base can be used to generate an identification of the modules used in the target source code that are affected by the target system to be tested for the user, so that the user can intuitively obtain the impact scope of the target system to be tested. According to the impact scope of the target system to be tested, the impact of the change can be evaluated more accurately and quickly, irrelevant interference points can be eliminated, and regression use cases can be streamlined to avoid missing impact points in the early stage of the evaluation, resulting in the subsequent development of various systems. When they are jointly debugged, it is found that some associations have not been processed. In the mildest case, it will take up development time to supplement the logic. In the most serious case, the solution design may need to be overturned and redone, thereby improving the efficiency of project development.

[0180] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the method for identifying modules used in the target source code as described above.

[0181] In this embodiment, the impact data of the system in the knowledge base can be used to generate an identification of the modules used in the target source code that are affected by the target system to be tested for the user, so that the user can intuitively obtain the impact scope of the target system to be tested. According to the impact scope of the target system to be tested, the impact of the change can be evaluated more accurately and quickly, irrelevant interference points can be eliminated, and regression use cases can be streamlined to avoid missing impact points in the early stage of the evaluation, resulting in the subsequent development of various systems. When they are jointly debugged, it is found that some associations have not been processed. In the mildest case, it will take up development time to supplement the logic. In the most serious case, the solution design may need to be overturned and redone, thereby improving the efficiency of project development.

[0182] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0183] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A method for identifying modules used in target source code, characterized in that: The steps include: Get the target project source code; Performing a detailed analysis on the target project source code by a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency; Based on the target project source code structure and code dependencies, determine the usage modules of specific dependent packages in the target project source code.

2. The method for identifying modules used in target source code according to claim 1, characterized in that: The target project source code is analyzed in detail by a preset fine-grained dependency analysis method to obtain the target project source code structure and code dependency, including: node.fs reads package.json in the target project source code through a preset fine-grained dependency analysis method, and passes the dependencies read from the package.json into the recognition function, where the dependencies include the used modules; The identification function traverses and loops each dependency of the dependencies to obtain the used module in each dependency, and the object of the used module created in each dependency includes a version and an empty attribute; Based on the used modules in each dependency, the source code structure and code dependency of the target project are obtained.

3. The method for identifying modules used in target source code according to claim 2, characterized in that: After obtaining the target project source code structure and code dependency based on the usage module in each dependency, the method further includes: Get the directory where node.js is currently running, and fs.readdirSync reads all files in the current directory fileList; Filter each file in all the files fileList to obtain the filtered file file.

4. The method for identifying modules used in target source code according to claim 3, characterized in that: After filtering each file in all the files fileList to obtain the filtered file file, the method further includes: Performing character encoding processing on the file content of the file file by using a preset character encoder to obtain a file content character string; Identify whether the content of "import*from*" is used in the file content string; If the content using "import*from*" is identified, the dependency of the module used in the file file is determined, and the corresponding imported file content is obtained based on the dependency, wherein the file content after the from corresponds to a certain dependency, the content before the from is the file content imported by the dependency, and the * is any file content.

5. The method for identifying used modules in target source code according to claim 4, characterized in that: After performing character encoding processing on the file content of the file file by a preset character encoder to obtain a file content character string, the method further includes: Replace all file content strings mentioned with "|as|".

6. The method for identifying used modules in target source code according to claim 5, characterized in that: After the method of determining the dependency of the modules used in the file file if the content using "import*from*" is identified, and obtaining the corresponding imported file content based on the dependency, the method further includes: The content before the from is split into multiple parts according to the "," split string, and the imported file content string is determined; Identify whether each imported file content string contains "{}" or "|as|"; If there is "{}", first take out the first end "{}" and the last end "{}", and extract the file content in the curly brackets; If there is "|as|", the first half of the "|as|" file content is collected; If there is no "{}" or "|as|", the file content that needs to be imported is determined from all file contents; Store the processed imported file content into the empty attribute of the dependency object of the currently used module and submit it to the backend database storage.

7. The method for identifying modules used in target source code according to any one of claims 1 to 6, characterized in that: After determining the usage module of the specific dependent package in the target project source code based on the target project source code structure and the code dependency, the method further includes: Visualize the dependencies of modules used in the target source code and the associations between modules used.

8. A device for identifying modules used in target source code, characterized in that: include: The first acquisition module is used to obtain the target project source code; A refinement analysis module, used to perform refinement analysis on the target project source code by a preset fine-grained dependency analysis method to obtain the source code structure and code dependency of the target project; The first determination module is used to determine the usage module of the specific dependent package in the target project source code based on the source code structure of the target project and the dependency relationship of the code.

9. A computer device comprising a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the method for identifying modules used in the target source code according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the method for identifying a module used in a target source code according to any one of claims 1 to 7.