A method, apparatus, electronic device, and storage medium for managing code files.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2026-08-14
AI Technical Summary
[0005]本发明提供了一种代码文件的管理方法、装置、电子设备及存储介质,以解决代码文件分类存储结果误差较大的问题
[0027] The technical solution of this invention compares the acquired feature element set of the code file with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under multiple label dimensions. When no other code file with matching label information exists in the database, the code file is stored in the database. This not only achieves standardized labeling of label information, but also accurately classifies the code file based on the labeling results under multiple label dimensions, improving the management efficiency of code files. At the same time, it provides a textual basis for technical resource exchange among developers and establishes an efficient development model based on information sharing.
Smart Images

Figure CN118151901B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of file management technology, and in particular to a method, apparatus, electronic device, and storage medium for managing code files. Background Technology
[0002] With the continuous development of Internet technology, various functional software are emerging one after another. During the development of each software, a large number of code files are generated, which puts forward higher requirements for the effective management of code files.
[0003] In existing technologies, when developers upload code files to a file management system, they usually set tag information for the file to indicate the basic information of the code file. This facilitates the storage of the file and makes it easier for other developers to find it, so as to exchange and share technical resources and information, and achieve the effect of efficient development and information exchange.
[0004] However, this method of setting label information often results in annotation results that are related to personal annotation habits, are not standardized, and are highly subjective, which often leads to significant deviations in the annotation results and makes it inconvenient to manage code files. Summary of the Invention
[0005] This invention provides a method, apparatus, electronic device, and storage medium for managing code files, in order to solve the problem of large errors in the classification and storage results of code files.
[0006] According to one aspect of the present invention, a method for managing code files is provided, comprising:
[0007] In response to obtaining the code file to be stored, obtain the set of feature elements of the code file;
[0008] The set of feature elements is compared with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions;
[0009] Based on the tag information, determine whether a target code file matching the code file exists in the database;
[0010] If the target code file does not exist, the code file will be stored in the database.
[0011] The process of obtaining the feature element set of the code file includes: obtaining the code attribute map of the code file, and obtaining the feature element set of the code file based on the code attribute map. The feature element set obtained through CPG reflects not only the data composition of the code file, but also its syntactic structure and semantic information, providing a complete description of the code file's specific content and improving the accuracy and effectiveness of feature element acquisition.
[0012] The step of obtaining the feature element set of the code file based on the code attribute graph includes: sequentially forming feature elements from adjacent nodes and directed edges between adjacent nodes in the code attribute graph to construct the feature element set of the code file. By forming feature elements from adjacent nodes and directed edges between adjacent nodes, each feature element in the feature element set not only reflects the data composition of the two adjacent nodes individually, but also reflects the syntactic structure and semantic information between the two adjacent nodes. Therefore, the feature element set more accurately reflects the code coherence in the code file.
[0013] The step of comparing the set of feature elements with each feature set under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions includes: comparing the set of feature elements with each feature set under multiple label dimensions to obtain the hit result of the set of feature elements under each feature set; wherein, the hit result includes the number of hits and the hit percentage; and obtaining the label information of the code file based on the hit result of the set of feature elements under each feature set. When the number of dimensional features in different feature sets under a label dimension is different, the label under that label dimension can be obtained through the hit result, avoiding obtaining incorrect label information based on a single hit condition when the number of dimensional features in different feature sets under a label dimension is different, and further improving the classification accuracy of the code file.
[0014] After determining whether a target code file matching the code file exists in the database based on the tag information, the method further includes: if a target code file exists, extracting a set of key feature elements from the feature element set using word frequency and inverse text frequency; comparing the key feature element set of the code file with the key feature element set of the target code file; if the similarity comparison result is greater than or equal to a first preset threshold, replacing the target code file with the current code file; if the similarity comparison result is less than the first preset threshold, storing the code file in the database, and continuing to save the target code file in the database. When a target code file exists, the code content of the target code file and the current code file is compared again based on the key feature element set, and the target code file is replaced with the current code file, or both code files are saved simultaneously. This achieves simultaneous saving of different code content, ensuring the integrity of code information storage, and avoids redundant storage of identical code content, ensuring the accuracy of code information storage.
[0015] The step of comparing the set of feature elements with feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions includes: comparing the set of feature elements with feature sets of each dimension under multiple label dimensions to obtain the first label information of the set of feature elements under a first type of label dimension and the second label information under a second type of label dimension; the step of determining whether a target code file matching the code file exists in the database based on the label information includes: determining whether a target code file matching the code file exists in the database based on the first label information; if a target code file exists, determining whether the second label information of the code file matches the second label information of the target code file; if the second label information of the code file matches the second label information of the target code file, replacing the target code file with the code file; if the second label information of the code file does not match the second label information of the target code file, storing the code file in the database and continuing to save the target code file in the database. If a target code file exists, the target code file is replaced with the current code file based on the comparison result of the second tag information, or both code files are saved at the same time. This achieves the simultaneous saving of different code files, ensuring the integrity of code information storage, and avoids redundant storage of the same code file, ensuring the accuracy of code information storage.
[0016] The code file management method further includes: in response to obtaining query conditions under at least one tag dimension through the code file query interface, configuring optional query conditions under other tag dimensions based on the query conditions under the at least one tag dimension. This achieves precise configuration of various types of code files under each tag dimension, allowing users to directly obtain the relevant types of code files stored in the database through the configured optional query conditions, thus avoiding the occurrence of no search results.
[0017] According to another aspect of the present invention, a code file management device is provided, comprising:
[0018] The feature element set acquisition module is used to acquire the feature element set of the code file in response to acquiring the code file to be stored.
[0019] The tag information acquisition module is used to compare the feature element set with the feature sets of each dimension under multiple tag dimensions to obtain the tag information of the code file under the multiple tag dimensions.
[0020] The matching and judgment execution module is used to determine, based on the tag information, whether there is a target code file in the database that matches the code file;
[0021] The storage execution module is used to store the target code file in the database if the target code file does not exist.
[0022] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0023] At least one processor; and
[0024] A memory communicatively connected to the at least one processor; wherein,
[0025] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the code file management method described in any embodiment of the present invention.
[0026] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions, the computer instructions being configured to cause a processor to execute and implement the code file management method described in any embodiment of the present invention.
[0027] The technical solution of this invention compares the acquired feature element set of the code file with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under multiple label dimensions. When no other code file with matching label information exists in the database, the code file is stored in the database. This not only achieves standardized labeling of label information, but also accurately classifies the code file based on the labeling results under multiple label dimensions, improving the management efficiency of code files. At the same time, it provides a textual basis for technical resource exchange among developers and establishes an efficient development model based on information sharing.
[0028] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0029] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0030] Figure 1 This is a flowchart of a code file management method provided in Embodiment 1 of the present invention;
[0031] Figure 2 This is a flowchart of a code file management method provided in Embodiment 2 of the present invention;
[0032] Figure 3 This is a flowchart of a code file management method provided in Embodiment 3 of the present invention;
[0033] Figure 4 This is a schematic diagram of the structure of a code file management device according to Embodiment 4 of the present invention;
[0034] Figure 5 This is a schematic diagram of the structure of an electronic device that implements the code file management method of the present invention. Detailed Implementation
[0035] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0036] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0037] Example 1
[0038] Figure 1 This is a flowchart illustrating a code file management method according to Embodiment 1 of the present invention. This embodiment is applicable to managing user-uploaded code files. The method can be executed by a code file management device, which can be implemented in hardware and / or software and is configured in an electronic device such as a terminal device. Figure 1 As shown, the method includes:
[0039] S101. In response to obtaining the code file to be stored, obtain the set of feature elements of the code file.
[0040] Feature elements characterize the data composition, syntactic structure, or semantic information of a code file, reflecting its data dependency characteristics, syntactic features, or control dependency characteristics. Feature elements can be obtained through methods such as Abstract Syntax Tree (AST), Control Flow Graph (CFG), Data Flow Diagram (DFD), or Program Dependence Graph (PDG). Alternatively, a pre-configured set of invalid characters can be used to filter invalid characters (e.g., single characters "x" or "y") and invalid strings (e.g., strings like "if" and "else") from the current code file. Each string after invalid character filtering is then used as a feature element, and these feature elements are combined to form a feature element set.
[0041] Optionally, in this embodiment of the invention, obtaining the feature element set of the code file includes: obtaining the code property graph of the code file, and obtaining the feature element set of the code file based on the code property graph. A code property graph (CPG) integrates multiple program representations, including AST, CFG, and PDG, into a single data structure graph. Specifically, it can be obtained using a CPG generation tool, such as the llvm2cpg conversion tool. Specifically, firstly, the code file is converted to Bitcode format using a Low Level Virtual Machine (LLVM); then, the CPG is generated based on the Bitcode format file using the llvm2cpg conversion tool; finally, the CPG is loaded into the code analysis tool Joern, thereby obtaining the various feature elements in the code file. The feature element set obtained through the CPG reflects not only the data composition of the code file but also its syntactic structure and semantic information, comprehensively describing the specific content of the code file and improving the accuracy and effectiveness of feature element acquisition.
[0042] Specifically, a CPG consists of nodes, node types, directed edges, directed edge labels, and node key-value pairs. Node key-value pairs include node key names and node key values. Nodes can also include information such as functions, variables, and control structures. All of the above information in the CPG can be used as feature elements to increase the coverage of feature elements, or only some of the information can be extracted as feature elements to reduce the number of feature elements and improve the accuracy of feature element acquisition.
[0043] Optionally, in this embodiment of the invention, obtaining the feature element set of the code file based on the code attribute graph includes: sequentially forming feature elements from adjacent nodes and directed edges between adjacent nodes in the code attribute graph to construct the feature element set of the code file. A directed edge is an edge with a direction between nodes, reflecting the association between nodes. Two adjacent nodes may have one or more directed edges, or they may not have directed edges. In this embodiment of the invention, adjacent nodes with one or more directed edges, along with the directed edges between these adjacent nodes, are combined to form feature elements. For example, a feature element may be composed of "node 1 + directed edge 1 + node 2". By forming feature elements from adjacent nodes and the directed edges between them, each feature element in the feature element set not only reflects the data composition of the two adjacent nodes but also reflects the syntactic structure and semantic information between the two adjacent nodes. Therefore, the feature element set more accurately reflects the code coherence in the code file.
[0044] S102. Compare the set of feature elements with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions.
[0045] Tag dimensions are descriptive information about code files from different perspectives. For example, the purpose of the file can be a tag dimension, including operations, management, testing, etc., to describe the applicable scope of the code file; the language type can also be a tag dimension, including C, Java, C++, etc., to describe the programming language used to write the code file; the file's requester can also be a tag dimension, including requester A, requester B, requester C, etc. Based on the code characteristics under different tag dimensions, a preset number of dimension features are pre-configured to form the dimensional feature set for each tag dimension.
[0046] The feature element set of the current code file is compared with the dimensional feature sets under each tag dimension. For each tag under a tag dimension, the tag of the current code file under the current tag dimension is determined if the feature element set hits the most dimensional features in a certain dimensional feature set, or if the dimensional feature hit rate in that dimensional feature set is the highest. The tags of the code file under each tag dimension constitute the tag information of the code file. For example, the tag information of a code file includes "Operations and Maintenance", "C Language", and "Customer A"; that is, the code file is an operations and maintenance file written in C language provided for Customer A.
[0047] Optionally, in this embodiment of the invention, comparing the set of feature elements with each feature set under multiple tag dimensions to obtain the tag information of the code file under the multiple tag dimensions includes: comparing the set of feature elements with each feature set under multiple tag dimensions to obtain the hit result of the set of feature elements under each feature set; wherein the hit result includes the number of hits and the hit percentage; and obtaining the tag information of the code file based on the hit result of the set of feature elements under each feature set.
[0048] Specifically, within a single label dimension, the number of dimensional features may differ across different feature sets. This can lead to a situation where the current code file has a higher hit rate in one feature set and a lower hit rate in another, resulting in different matching results based on either the hit rate or the hit count. Therefore, different weights are pre-configured for the hit count and hit rate. The sum of the product of the hit count and its corresponding weight, and the product of the hit rate and its corresponding weight, represents the hit result of the feature set within that feature set. Thus, when the number of dimensional features differs across different feature sets within a single label dimension, the label for that dimension can be obtained through the hit result. This avoids obtaining incorrect label information based on a single hit condition when the number of dimensional features differs across different feature sets within a single label dimension, further improving the classification accuracy of the code file.
[0049] S103. Based on the tag information, determine whether there is a target code file in the database that matches the code file.
[0050] S104. If the target code file does not exist, the code file is stored in the database.
[0051] If there are many tag dimensions, then for each tag information, only one code file may be allowed to be stored. For example, for a requester (dimension), there may be only one code file for a functional requirement (dimension) written in a programming language under a certain purpose (dimension), and this code file has already covered all the content under that tag information. In this case, if there is already a stored file with the same tag information as the current code file, then the current code file and the target code file are considered to be essentially the same file, and the current code file is the latest uploaded version. In this case, the target code file can be directly replaced with the current code file.
[0052] Meanwhile, if there are fewer tag dimensions, multiple code files may be allowed to be stored for a single tag. For example, for a single requirement (dimension), a code file written in a single programming language for a single purpose (dimension) can only cover one functional requirement. Multiple such code files are needed to satisfy different functional requirements. Therefore, multiple code files can be stored under a single tag, and these multiple files together form a complete code file set. In this case, if a stored file with the same tag information as the current code file already exists, the current code file and the target code file are considered to be essentially different files. The target code file is stored while the current code file is stored, and their tag information remains identical. Alternatively, if the target code file does not exist, regardless of whether multiple code files are allowed to be stored under a single tag, the current code file is obviously the only file under that tag. Therefore, the code file can be directly stored in the database.
[0053] Optionally, in this embodiment of the invention, the code file management method further includes: in response to obtaining query conditions under at least one tag dimension through the code file query interface, configuring optional query conditions under other tag dimensions based on the query conditions under the at least one tag dimension. Specifically, since there is no correlation between different tag dimensions, it cannot be guaranteed that code files are stored under each tag information in the database. Therefore, when obtaining query conditions under one or more tag dimensions that the user has selected, it is necessary to configure optional query conditions under unselected tag dimensions based on the selected query conditions to achieve accurate configuration of various types of code files under each tag dimension. Thus, the user can directly obtain the relevant types of code files stored in the database through the configured optional query conditions, avoiding the occurrence of no search results.
[0054] The technical solution of this invention compares the acquired feature element set of the code file with the feature sets of each dimension under multiple tag dimensions to obtain the tag information of the code file under multiple tag dimensions. When no other code file with matching tag information exists in the database, the code file is stored in the database. This not only achieves standardized labeling of tag information, but also accurately classifies the code file based on the labeling results under multiple tag dimensions, improving the management efficiency of code files. At the same time, it provides a textual basis for the exchange of technical resources among developers and establishes an efficient development model based on information sharing.
[0055] Example 2
[0056] Figure 2 This is a flowchart of a code file management method provided in Embodiment 2 of the present invention. The relationship between this embodiment and the above embodiments is that, after determining that a target code file exists in the database based on tag information, the code similarity between the target code file and the target code file is obtained based on a set of key feature elements. Figure 2 As shown, the method includes:
[0057] S201. In response to obtaining the code file to be stored, obtain the set of feature elements of the code file; execute S202.
[0058] S202. Compare the set of feature elements with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions; execute S203.
[0059] S203. Based on the tag information, determine whether a target code file matching the code file exists in the database; if not, proceed to S204; if yes, proceed to S205.
[0060] S204. Store the code file in the database.
[0061] S205. Extract the set of key feature elements from the set of feature elements by word frequency and inverse text frequency; execute S206.
[0062] As described in the above technical solution, if the label dimensions are few, multiple code files can be stored for a single label information, and only these multiple code files can form a complete code file set. Therefore, if the label information of the current code file and the target code file is the same, the key feature element set of the current code file is further extracted from the feature element set. Among them, Term Frequency (TF) represents the frequency of occurrence of a code element in the current code file; Inverse Document Frequency (IDF) is a measure of the general importance of a code element. The fewer code files containing the element, the larger the IDF, indicating that the element has a better distinguishing feature. The number of key feature elements in the key feature element set can be set as needed. By obtaining the key feature element set through Term Frequency and Inverse Document Frequency, a further set of key feature elements representing data characteristics and structural features is extracted from the feature element set, reducing the number of feature elements to be compared and improving the efficiency and accuracy of code similarity comparison between the code file and the target code file.
[0063] S206. Compare the set of key feature elements of the code file with the set of key feature elements of the target code file; if the similarity comparison result is less than a first preset threshold, then execute S207; if the similarity comparison result is greater than or equal to the first preset threshold, then execute S208.
[0064] S207. Store the code file in the database, and continue to save the target code file in the database.
[0065] If the similarity comparison result between the key feature element set of the current code file and the key feature element set of the target code file is less than the first preset threshold, then the code content of the current code file and the target code file are considered to be different, that is, the current code file and the target code file are actually different files. While storing the current code file, the target code file is also saved, and the tag information of the two remains the same.
[0066] S208. Replace the target code file with the code file.
[0067] If the similarity comparison result between the key feature element set of the current code file and the key feature element set of the target code file is greater than or equal to the first preset threshold, then the code content of the current code file and the target code file are considered to be the same, that is, the current code file and the target code file are essentially the same file. Since the current code file is the latest uploaded version, the target code file is replaced with the current code file.
[0068] In the technical solution of this invention, if no target code file matching the tag information of the code file exists in the database, the code file is directly stored in the database to improve the storage efficiency of the code file through tag information filtering. At the same time, if a target code file exists, the code content of the target code file and the current code file is compared according to the key feature element set, and the target code file is replaced with the current code file, or both code files are saved at the same time. This achieves the simultaneous saving of different code content, ensuring the integrity of code information storage, and avoids redundant storage of the same code content, ensuring the accuracy of code information storage.
[0069] Example 3
[0070] Figure 3 This is a flowchart of a code file management method provided in Embodiment 3 of the present invention. The relationship between this embodiment and the above embodiments is that the tag dimension includes a first type of tag dimension and a second type of tag dimension. Figure 3 As shown, the method includes:
[0071] S301. In response to obtaining the code file to be stored, obtain the set of feature elements of the code file; execute S302.
[0072] S302. Compare the set of feature elements with the feature sets of each dimension under multiple label dimensions to obtain the first label information of the set of feature elements under the first type of label dimension and the second label information under the second type of label dimension; execute S303.
[0073] As described in the above technical solution, the first type of tag dimension can include dimensions such as the requester, purpose, and programming language; the second type of tag dimension can include dimensions such as functional requirements and the writer. Under the first tag information, multiple code files can be stored; under the first tag information + second tag information, only one code file can be stored.
[0074] S303. Based on the first tag information, determine whether there is a target code file in the database that matches the code file; if not, execute S304; if yes, execute S305.
[0075] S304. Store the code file in the database.
[0076] S305. Determine whether the second tag information of the code file matches the second tag information of the target code file; if not, execute S306; if yes, execute S307.
[0077] S306. Store the code file in the database, and continue to save the target code file in the database.
[0078] Taking the above technical solution as an example, from the perspective of a demand side, a code file written in a programming language under a certain purpose can only cover one functional requirement. Only multiple such code files can satisfy different functional requirements. Therefore, multiple code files can be stored under a first tag, and multiple code files can form a complete code file set. The code file and the target code file are equivalent to covering different functional requirements under the same demand side, the same purpose, and the same programming language. Obviously, it is necessary to save the current code file and the target code file at the same time.
[0079] S307. Replace the target code file with the code file.
[0080] Taking the above technical solution as an example, for a demand-side dimension, there is only one code file for a functional requirement dimension written in a programming language under a purpose dimension, and that code file covers all the content under that tag information. The code file and the target code file are equivalent to covering the same functional requirement under the same demand-side dimension, the same purpose dimension, and the same programming language dimension. Obviously, it is sufficient to save either the current code file or the target code file. Since the current code file is the latest uploaded version, the target code file is replaced with the current code file.
[0081] The technical solution of this invention, if there is no target code file in the database that matches the first tag information of the code file, then the code file is directly stored in the database to improve the tag comparison efficiency between the code file and the target file through the filtering of the first tag information. At the same time, if there is a target code file, then the target code file is replaced with the current code file according to the comparison result of the second tag information, or both code files are saved at the same time. This not only realizes the simultaneous saving of different code files, ensuring the integrity of code information storage, but also avoids redundant storage of the same code file, ensuring the accuracy of code information storage.
[0082] Example 4
[0083] Figure 4 This is a structural block diagram of a code file management device provided in Embodiment 4 of the present invention. The device specifically includes:
[0084] The feature element set acquisition module 401 is used to acquire the feature element set of the code file in response to acquiring the code file to be stored.
[0085] The tag information acquisition module 402 is used to compare the feature element set with the feature sets of each dimension under multiple tag dimensions to obtain the tag information of the code file under the multiple tag dimensions.
[0086] The matching and judgment execution module 403 is used to determine, based on the tag information, whether there is a target code file in the database that matches the code file;
[0087] The storage execution module 404 is used to store the target code file in the database if the target code file does not exist.
[0088] The technical solution of this invention compares the acquired feature element set of the code file with the feature sets of each dimension under multiple tag dimensions to obtain the tag information of the code file under multiple tag dimensions. When no other code file with matching tag information exists in the database, the code file is stored in the database. This not only achieves standardized labeling of tag information, but also accurately classifies the code file based on the labeling results under multiple tag dimensions, improving the management efficiency of code files. At the same time, it provides a textual basis for the exchange of technical resources among developers and establishes an efficient development model based on information sharing.
[0089] Optionally, the feature element set acquisition module 401 is specifically used to acquire the code attribute map of the code file, and acquire the feature element set of the code file based on the code attribute map.
[0090] Optionally, the feature element set acquisition module 401 is specifically used to sequentially form feature elements from the adjacent nodes and the directed edges between the adjacent nodes in the code attribute graph, so as to construct the feature element set of the code file.
[0091] Optionally, the tag information acquisition module 402 is specifically used to compare the feature element set with each dimension feature set under multiple tag dimensions to obtain the hit result of the feature element set under each dimension feature set; wherein, the hit result includes the hit count and the hit percentage; and to obtain the tag information of the code file based on the hit result of the feature element set under each dimension feature set.
[0092] Optionally, the code file management device also includes:
[0093] The key feature element set acquisition module is used to extract a key feature element set from the feature element set by word frequency and inverse text frequency if a target code file exists; compare the key feature element set of the code file with the key feature element set of the target code file for similarity; if the similarity comparison result is greater than or equal to a first preset threshold, replace the target code file with the code file; if the similarity comparison result is less than the first preset threshold, store the code file in the database, and continue to save the target code file in the database.
[0094] Optionally, the tag information acquisition module 402 is used to compare the feature element set with the feature sets of each dimension under multiple tag dimensions, so as to obtain the first tag information of the feature element set under the first type of tag dimension and the second tag information under the second type of tag dimension.
[0095] Optionally, the matching judgment execution module 403 is specifically used to determine, based on the first tag information, whether there is a target code file in the database that matches the code file; if a target code file exists, then determine whether the second tag information of the code file matches the second tag information of the target code file; if the second tag information of the code file matches the second tag information of the target code file, then replace the target code file with the code file; if the second tag information of the code file does not match the second tag information of the target code file, then store the code file in the database, and continue to save the target code file in the database.
[0096] Optionally, the code file management device also includes:
[0097] The query condition configuration module is used to respond to the query conditions obtained through the code file query interface under at least one tag dimension, and to configure optional query conditions under other tag dimensions based on the query conditions under the at least one tag dimension.
[0098] The above-described apparatus can execute the code file management method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method. Technical details not described in detail in this embodiment can be found in the code file management method provided in any embodiment of the present invention.
[0099] Example 5
[0100] Figure 5A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0101] like Figure 5 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0102] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0103] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as methods for managing code files.
[0104] In some embodiments, the code file management method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on a heterogeneous hardware accelerator via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the processor, one or more steps of the code file management method described above may be performed. Alternatively, in other embodiments, the processor may be configured to execute the code file management method by any other suitable means (e.g., by means of firmware).
[0105] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0106] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0107] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0108] To provide user interaction, the systems and techniques described herein can be implemented on a heterogeneous hardware accelerator, which includes: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the heterogeneous hardware accelerator. Other types of devices can also be used to provide user interaction; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or haptic feedback); and input from the user can be received in any form (including sound input, voice input, or haptic input).
[0109] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0110] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0111] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0112] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for managing code files, characterized in that, include: In response to obtaining the code file to be stored, obtain the set of feature elements of the code file; The feature element set is compared with each feature set under multiple tag dimensions to obtain the hit result of the feature element set under each feature set; wherein, the hit result includes the number of hits and the hit percentage; each feature set under multiple tag dimensions is composed of a preset number of dimensional features pre-configured according to the code characteristics under different tag dimensions. Based on the hit results of the feature element set under each of the dimensional feature sets, obtain the tag information of the code file; Based on the tag information, determine whether a target code file matching the code file exists in the database; If the target code file does not exist, the code file will be stored in the database.
2. The method according to claim 1, characterized in that, The step of obtaining the feature element set of the code file includes: Obtain the code attribute map of the code file, and obtain the feature element set of the code file based on the code attribute map.
3. The method according to claim 2, characterized in that, The step of obtaining the feature element set of the code file based on the code attribute graph includes: The adjacent nodes and the directed edges between the adjacent nodes in the code attribute graph are sequentially combined to form feature elements, thereby constructing the feature element set of the code file.
4. The method according to claim 1, characterized in that, After determining whether a target code file matching the code file exists in the database based on the tag information, the process further includes: If the target code file exists, the key feature element set is extracted from the feature element set by word frequency and inverse text frequency. The set of key feature elements of the code file is compared with the set of key feature elements of the target code file. If the similarity comparison result is greater than or equal to the first preset threshold, then the target code file is replaced with the code file; If the similarity comparison result is less than the first preset threshold, the code file is stored in the database, and the target code file continues to be saved in the database.
5. The method according to claim 1, characterized in that, The step of comparing the set of feature elements with the feature sets of each dimension under multiple label dimensions to obtain the label information of the code file under the multiple label dimensions includes: The feature element set is compared with the feature sets of each dimension under multiple label dimensions to obtain the first label information of the feature element set under the first type of label dimension and the second label information under the second type of label dimension. The step of determining whether a target code file matching the code file exists in the database based on the tag information includes: Based on the first tag information, determine whether there is a target code file in the database that matches the code file; If a target code file exists, determine whether the second tag information of the code file matches the second tag information of the target code file; If the second tag information of the code file matches the second tag information of the target code file, then the target code file is replaced with the code file; If the second tag information of the code file does not match the second tag information of the target code file, the code file is stored in the database, and the target code file continues to be saved in the database.
6. The method according to claim 1, characterized in that, The method for managing code files also includes: In response to obtaining query conditions under at least one tag dimension through the code file query interface, optional query conditions under other tag dimensions are configured based on the query conditions under the at least one tag dimension.
7. A code file management device, characterized in that, include: The feature element set acquisition module is used to acquire the feature element set of the code file in response to acquiring the code file to be stored. The tag information acquisition module is used to compare the feature element set with each dimension feature set under multiple tag dimensions to obtain the hit result of the feature element set under each dimension feature set; wherein, the hit result includes the hit count and the hit percentage; each dimension feature set under multiple tag dimensions is composed of a preset number of dimension features pre-configured according to the code characteristics under different tag dimensions; and the tag information of the code file is obtained based on the hit result of the feature element set under each dimension feature set. The matching and judgment execution module is used to determine, based on the tag information, whether there is a target code file in the database that matches the code file; The storage execution module is used to store the target code file in the database if the target code file does not exist.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the code file management method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method for managing code files as described in any one of claims 1-6.
Citation Information
Patent Citations
Code clone detection method based on feature fusion
CN115373737A
Code classification mechanism
US20210208874A1