Code scanning rule recommendation method and device, processor and electronic device
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2022-06-16
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]本申请的主要目的在于提供一种代码扫描规则的推荐方法和装置、处理器和电子设备,以解决相关技术中通过人工凭经验选择对目标应用代码的代码扫描规则,导致代码扫描规则的使用效果比较差的问题
[0027]This application employs the following steps: obtaining the target application code to be scanned, wherein the target application code consists of multiple code files; determining a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; obtaining the target recommendation degree for each code scanning rule according to the target recommendation algorithm; and recommending target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule. This solves the problem in related technologies where code scanning rules for the target application code are selected manually based on experience, resulting in poor performance of the code scanning rules. When it is necessary to scan the target application code, the target recommendation algorithm is used to obtain the target recommendation degree for each code scanning rule, and then target code scanning rules are recommended for the target application code based on the target recommendation degree, thereby improving the effectiveness of the code scanning rules.
Smart Images

Figure CN115048304B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of financial technology, and more specifically, to a method and apparatus for recommending code scanning rules, a processor, and an electronic device. Background Technology
[0002] Code scanning, in software engineering, refers to the process of scanning a program's source code using code scanning rules to identify potential problems, security vulnerabilities, or coding irregularities. The scanned object may be uncompiled source code or compiled target code. When selecting code scanning rules, the sheer number of rules—for example, SonarQube, a commonly used code scanning tool, has over two thousand rules for the Java language—makes it difficult for application developers to be familiar with them all and know which rules to use. Consequently, developers often rely on experience to select rules, hindering the efficient use of code scanning rules to uncover potential problems in application code.
[0003] There is currently no effective solution to the problem that the code scanning rules for target applications are poorly used due to manual selection of code scanning rules based on experience in related technologies. Summary of the Invention
[0004] The main objective of this application is to provide a method, apparatus, processor, and electronic device for recommending code scanning rules, in order to solve the problem in related technologies where code scanning rules for target application code are selected manually based on experience, resulting in poor performance of code scanning rules.
[0005] To achieve the above objectives, according to one aspect of this application, a method for recommending code scanning rules is provided. The method includes: acquiring target application code to be scanned, wherein the target application code consists of multiple code files; determining a target recommendation algorithm for code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and operation information of a target object on the target application code; obtaining a target recommendation degree for each code scanning rule according to the target recommendation algorithm; and recommending target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule.
[0006] Further, when the target recommendation algorithm is the recommendation algorithm based on the target application code, obtaining the target recommendation degree for each code scanning rule according to the target recommendation algorithm includes: acquiring multiple code scanning rules and setting category labels for each code scanning rule to obtain multiple code scanning rules of multiple rule categories; calculating based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; calculating based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; calculating based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; acquiring a fourth feature vector corresponding to the code scanning rules that have been used by the target application code; and obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector.
[0007] Further, the calculation based on multiple code files in the target application code to obtain the second feature vector corresponding to the target application code includes: obtaining the total code in the multiple code files in the target application code; performing data cleaning on the total code to obtain the processed total code; matching and classifying the processed total code using regular expressions to obtain the code corresponding to multiple code categories; and vectorizing the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector.
[0008] Further, the vectorization of the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector includes: detecting whether there is an incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category; if the incremental code exists in the code corresponding to the keyword code category and the code corresponding to the identifier code category, modifying the word frequency of each code in the incremental code to obtain the latest word frequency of each code in the incremental code; and vectorizing the code corresponding to the keyword and the code corresponding to the identifier based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code to obtain the second feature vector.
[0009] Further, obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector includes: obtaining a first radar distribution map based on the first feature vector, the second feature vector, and the fourth feature vector; obtaining a first recommendation coefficient for each rule category of the code scanning rule using the first radar distribution map; obtaining a second radar distribution map based on the first feature vector and the third feature vector; obtaining a second recommendation coefficient for each code scanning rule using the second radar distribution map; obtaining the total score for each code scanning rule, wherein the total score is calculated from the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and calculating the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0010] Further, obtaining the first radar distribution map based on the first feature vector, the second feature vector, and the fourth feature vector includes: calculating the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; calculating the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; and mapping the first similarity values and the second similarity values onto the radar map to obtain the first radar distribution map.
[0011] Further, obtaining the second radar distribution map based on the first feature vector and the third feature vector includes: calculating the similarity between the third feature vector and each of the first feature vectors to obtain multiple third similarity values; mapping the third similarity values and the first similarity values onto the radar map to obtain the second radar distribution map.
[0012] Furthermore, when the target recommendation algorithm is the recommendation algorithm based on the target application code and the operation information of the target object on the target application code, obtaining the target recommendation degree of each code scanning rule according to the target recommendation algorithm includes: obtaining the fifth feature vector corresponding to the target application code; and obtaining the second target recommendation degree of each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector.
[0013] Further, obtaining the second target recommendation degree for each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector includes: obtaining a third radar distribution map based on the first feature vector, the fifth feature vector, and the fourth feature vector; obtaining a third recommendation coefficient for each category of the code scanning rule through the third radar distribution map; and calculating the second target recommendation degree for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0014] Further, obtaining the fifth feature vector corresponding to the target application code includes: obtaining, through the target program development application, a first code file that the target object is editing, a target code scanning rule that the target object has browsed, and a second code file that the target object has submitted to change the target application code, wherein the first code file is a code file in the target application code; setting weight values for the code in the first code file, the target code scanning rule, and the second code file, and vectorizing the first code file, the target code scanning rule, and the second code file according to the weight values to obtain a first initial feature vector; calculating based on multiple code files in the target application code to obtain a second initial feature vector corresponding to the target application code; and obtaining the fifth feature vector corresponding to the target application code based on the first initial feature vector and the second initial feature vector.
[0015] To achieve the above objectives, according to another aspect of this application, a code scanning rule recommendation apparatus is provided. The apparatus includes: an acquisition unit for acquiring target application code to be scanned, wherein the target application code comprises multiple code files; a first determination unit for determining a target recommendation algorithm for code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and operation information of a target object on the target application code; a second determination unit for obtaining a target recommendation degree for each code scanning rule according to the target recommendation algorithm; and a recommendation unit for recommending target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule.
[0016] Further, when the target recommendation algorithm is the recommendation algorithm based on the target application code, the second determining unit includes: a first acquisition subunit, used to acquire multiple code scanning rules and set category labels for each code scanning rule to obtain multiple rule categories of code scanning rules; a first calculation subunit, used to calculate based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; a second calculation subunit, used to calculate based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; a third calculation subunit, used to calculate based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; a second acquisition subunit, used to acquire a fourth feature vector corresponding to the code scanning rules already used by the target application code; and a first determining subunit, used to obtain a first target recommendation degree for each code scanning rule based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector.
[0017] Further, the second calculation subunit includes: a first acquisition module, used to acquire the total code in multiple code files in the target application code; a cleaning module, used to perform data cleaning on the total code to obtain processed total code; a classification module, used to match and classify the processed total code using regular expressions to obtain code corresponding to multiple code categories; and a processing module, used to vectorize the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector.
[0018] Further, the processing module includes: a detection submodule, used to detect whether there is an incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category; a modification submodule, used to modify the word frequency of each code in the incremental code if the incremental code exists in the code corresponding to the keyword code category and the code corresponding to the identifier code category, to obtain the latest word frequency of each code in the incremental code; and a processing submodule, used to perform vectorization processing on the code corresponding to the keyword and the code corresponding to the identifier based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code, to obtain the second feature vector.
[0019] Further, the first determining subunit includes: a first determining module, used to obtain a first radar distribution map based on the first feature vector, the second feature vector, and the fourth feature vector; a second determining module, used to obtain a first recommendation coefficient for each rule category of the code scanning rule through the first radar distribution map; a third determining module, used to obtain a second radar distribution map based on the first feature vector and the third feature vector; a fourth determining module, used to obtain a second recommendation coefficient for each code scanning rule through the second radar distribution map; a second obtaining module, used to obtain the total score of each code scanning rule, wherein the total score is calculated by the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and a first calculating module, used to calculate a first target recommendation degree for each code scanning rule based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0020] Further, the first determining module includes: a first calculation submodule, used to calculate the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; a second calculation submodule, used to calculate the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; and a first mapping submodule, used to map the first similarity values and the second similarity values onto a radar map to obtain a first radar distribution map.
[0021] Furthermore, the third determining module includes: a third calculation submodule, used to calculate the similarity between the third feature vector and each of the first feature vectors to obtain multiple third similarity values; and a second mapping submodule, used to map the third similarity values and the first similarity values onto a radar map to obtain the second radar distribution map.
[0022] Furthermore, when the target recommendation algorithm is the recommendation algorithm based on the target application code and the target object's operation information on the target application code, the second determining unit includes: a third obtaining subunit, used to obtain the fifth feature vector corresponding to the target application code; and a second determining subunit, used to obtain the second target recommendation degree of each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector.
[0023] Further, the second determining subunit includes: a fifth determining module, used to obtain a third radar distribution map based on the first feature vector, the fifth feature vector, and the fourth feature vector; a sixth determining module, used to obtain a third recommendation coefficient for each category of the code scanning rule through the third radar distribution map; and a second calculation module, used to calculate a second target recommendation degree for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0024] Further, the third acquisition subunit includes: a third acquisition module, used to acquire, through the target program development application, a first code file that the target object is editing, a target code scanning rule that the target object has browsed, and a second code file that the target object has submitted to change the target application code, wherein the first code file is a code file in the target application code; a setting module, used to set weight values for the code in the first code file, the target code scanning rule, and the second code file, and vectorize the first code file, the target code scanning rule, and the second code file according to the weight values to obtain a first initial feature vector; a third calculation module, used to calculate based on multiple code files in the target application code to obtain a second initial feature vector corresponding to the target application code; and to obtain a fifth feature vector corresponding to the target application code based on the first initial feature vector and the second initial feature vector.
[0025] To achieve the above objectives, according to one aspect of this application, a processor is provided for running a program, wherein the program executes the recommended method of the code scanning rules described in any of the preceding claims.
[0026] To achieve the above objectives, according to one aspect of this application, an electronic device is provided, the electronic device including one or more processors and a memory, the memory being used to store a recommended method for the one or more processors to implement the code scanning rules described in any one of the above.
[0027] This application employs the following steps: obtaining the target application code to be scanned, wherein the target application code consists of multiple code files; determining a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; obtaining the target recommendation degree for each code scanning rule according to the target recommendation algorithm; and recommending target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule. This solves the problem in related technologies where code scanning rules for the target application code are selected manually based on experience, resulting in poor performance of the code scanning rules. When it is necessary to scan the target application code, the target recommendation algorithm is used to obtain the target recommendation degree for each code scanning rule, and then target code scanning rules are recommended for the target application code based on the target recommendation degree, thereby improving the effectiveness of the code scanning rules. Attached Figure Description
[0028] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0029] Figure 1 This is a flowchart of a recommended method for code scanning rules provided in the embodiments of this application;
[0030] Figure 2 This is a first radar distribution map provided according to an embodiment of this application;
[0031] Figure 3 This is a schematic diagram illustrating the calculation of the first recommendation coefficient according to an embodiment of this application;
[0032] Figure 4 This is a second radar distribution map provided according to an embodiment of this application;
[0033] Figure 5 This is a schematic diagram of a recommended device based on the code scanning rules provided in the embodiments of this application;
[0034] Figure 6 This is a schematic diagram of a recommendation system based on code scanning rules provided in an embodiment of this application;
[0035] Figure 7 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0036] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0037] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0038] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application 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 for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover 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.
[0039] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are information and data authorized by the user or fully authorized by all parties. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving consent information from the aforementioned user or organization.
[0040] The present invention will now be described in conjunction with preferred implementation steps. Figure 1 This is a flowchart of a recommended method for code scanning rules provided in the embodiments of this application, such as... Figure 1 As shown, the method includes the following steps:
[0041] Step S101: Obtain the target application code to be scanned, wherein the target application code consists of multiple code files.
[0042] Step S102: Determine the target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code.
[0043] Step S103: Based on the target recommendation algorithm, obtain the target recommendation degree for each code scanning rule.
[0044] Step S104: Recommend target code scanning rules for the target application code based on the target recommendation score of each code scanning rule.
[0045] Specifically, the target application code that needs to be scanned is determined, the target recommendation degree of all current code scanning rules is obtained through a target recommendation algorithm, and then the target code scanning rules are recommended to the target application code based on the target recommendation degree.
[0046] Target recommendation algorithms include at least one of the following: recommendation algorithms based on target application code and recommendation algorithms based on target application code and the target object's operation information on the target application code. Recommendation algorithms based on target application code determine the target recommendation score for each code scanning rule by considering the correlation between the target application code and each code scanning rule. The aforementioned recommendation algorithms based on target application code primarily determine the target recommendation score for each code scanning rule based on the target application code. In practical use, since the actions of developers (i.e., the aforementioned target objects) on the target application code also affect the target recommendation score of the code scanning rule, to provide more personalized recommendations, a recommendation algorithm based on target application code and the target object's operation information on the target application code can be adopted. This algorithm comprehensively considers the target object's operation information on the target application code and the target application code itself to obtain the target recommendation score for each code scanning rule.
[0047] In summary, when it is necessary to scan the code of a target application, the target recommendation degree of each code scanning rule is obtained through the target recommendation algorithm. Then, target code scanning rules are recommended to the target application code based on the target recommendation degree. Through the above steps, target code scanning rules can be recommended to the target application code more reasonably, thereby improving the effectiveness of code scanning rules.
[0048] When the target recommendation algorithm is a recommendation algorithm based on the target application code, the recommendation method for code scanning rules provided in this application embodiment obtains the target recommendation degree of each code scanning rule in the following manner: Multiple code scanning rules are obtained, and category labels are set for each code scanning rule to obtain multiple code scanning rules of rule categories; a first feature vector corresponding to each rule category is calculated based on the code scanning rules of each rule category; a second feature vector corresponding to the target application code is calculated based on multiple code files in the target application code; multiple third feature vectors corresponding to each code scanning rule are calculated based on each code scanning rule; a fourth feature vector corresponding to the code scanning rules already used by the target application code is obtained; and a first target recommendation degree for each code scanning rule is obtained based on the first feature vector, second feature vector, third feature vector, and fourth feature vector.
[0049] Specifically, the recommendation algorithm based on target application code mainly includes the following steps: Add rule categories to all code scanning rules by domain; select representative domains with strong characteristics as rule categories; first, determine the name of each rule category; and then add a rule category for each rule. For example, rule categories could be: distributed systems, security, multithreading, performance, test cases, big data, mobile, and new terminal categories.
[0050] When selecting code scanning rules, the target application code chooses rule categories that match its application domain. For example, a big data application might choose big data category rules, while a mobile application might choose mobile category rules. However, the boundaries between the same code scanning rule and its classification in different categories are often unclear, and a single code scanning rule might even be associated with multiple rule categories. For instance, a code scanning rule might belong to both distributed and security categories. Therefore, after assigning category labels to each code scanning rule to obtain multiple rule categories, a first feature vector is calculated for each rule category. Then, multiple code files in the target application code are converted into corresponding second feature vectors, each code scanning rule is converted into multiple corresponding third feature vectors, and the code scanning rules already used by the target application code are converted into fourth feature vectors. Using the first, second, third, and fourth feature vectors, the first target recommendation score for each code scanning rule is determined. Converting all the code into feature vectors facilitates similarity calculations; for example, the first and second feature vectors reveal the relationship between the target application code and each category rule.
[0051] In summary, by converting the target application code, each code scanning rule, and the rule category into corresponding feature vectors, and using these feature vectors to determine the recommendation degree of each code scanning rule, the rationality of the recommendations is improved, and code scanning rules can be used more efficiently.
[0052] Determining the first target recommendation degree for each code scanning rule based on the first, second, third, and fourth feature vectors is crucial. The code scanning rule recommendation method provided in this application employs the following steps: calculating the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; calculating the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; mapping the first and second similarity values onto a radar chart to obtain a first radar distribution map; obtaining a first recommendation coefficient for each rule category of the code scanning rule using the first radar distribution map; calculating the similarity between the third feature vector and each first feature vector to obtain multiple third similarity values; mapping the third and first similarity values onto a radar chart to obtain a second radar distribution map; obtaining a second recommendation coefficient for each code scanning rule using the second radar distribution map; obtaining the total score for each code scanning rule, where the total score is calculated from the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and calculating the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0053] Specifically, the first target recommendation degree for each code scanning rule is determined mainly through three aspects: the rule category recommendation coefficient (i.e., the first recommendation coefficient mentioned above), the rule recommendation coefficient (i.e., the second recommendation coefficient mentioned above), and the total score for each code scanning rule.
[0054] Rule category recommendation coefficient (i.e., the first recommendation coefficient mentioned above): The similarity between the second feature vector corresponding to the target application code and the first feature vector corresponding to each rule category is calculated to obtain multiple first similarity values. The similarity between the first feature vector corresponding to each rule category and the fourth feature vector corresponding to the code scanning rules already used by the target application code is then calculated to obtain multiple second similarity values. The calculated first and second similarity values, ranging from 0 to 1, are mapped onto line segments at the center and corners of the radar image to obtain the first radar distribution map, as shown below. Figure 2 The figure shows the overall correlation between the feature vectors of the target application code and the feature vectors of each rule category. The code characteristics of the target application code can be seen from this figure. The recommendation coefficients for the rule categories (i.e., the first recommendation coefficients mentioned above) are obtained through the first radar distribution map.
[0055] In an alternative embodiment, such as Figure 3 The recommendation coefficient for rule categories in large and medium-sized data types is calculated as follows: the recommendation coefficient for a rule category is determined by the code scanning rules already used by the application of that category and the target application code, as follows: Figure 3As shown in (3), the rule category recommendation coefficient = the similarity between the target application code and the rule category - the similarity between the rules used by the target application code and the rule category + (1 - the similarity between the target application code and the rule category) / 2.
[0056] In an alternative embodiment, similarity can be calculated by using cosine similarity to calculate the similarity between two vectors A and B.
[0057] Where vector A i The word frequency statistics w of the i-th word in vector A Ai Sim(A, B) is calculated as the cosine of the angle between two vectors A and B in the vector space. The smaller the angle, the higher the similarity between the two vectors. If A and B are the same vectors, the angle is 0 degrees and the calculated value is 1. When the angle between the two vectors A and B is 90 degrees, the calculated similarity is 0.
[0058] It should be noted that, in an optional embodiment, the interest of developers of the target application code (i.e., the target objects mentioned above) in different rule categories can be collected. If a certain rule category is of interest to the developers, the recommendation coefficient of that rule category can be adjusted accordingly.
[0059] Rule recommendation coefficient (i.e., the second recommendation coefficient mentioned above): Calculate the similarity between the feature vector (i.e., the third feature vector mentioned above) of each code scanning rule and the first feature vector to obtain multiple third similarity values; map the third similarity values and the first similarity values onto a radar map to obtain a second radar distribution map, for example, Figure 4 The image shows a radar distribution map of a code scanning rule and the target application code. Because code scanning rules may be associated with multiple rule categories, and target application codes may also be associated with multiple rule categories, the similarity calculation is not performed within a single category. Instead, the area of the rings in the second radar distribution map is calculated. For example, the rule recommendation coefficient is the ratio of the area where two rings intersect to the area where two rings are joined.
[0060] Total score for each code scanning rule: Total score = Issues found by the rule / Number of lines scanned by the rule * (1 - False positive rate) * Rule score; False positive rate: (Number of issues missed by the rule + Number of issues overreported by the rule) / Number of issues found by the rule * (Number of falsely reported issues by the rule / Total number of falsely reported issues by all rules); Rule score: (Application rating / 10) * (Number of issues detected by the application / Total number of issues for this rule) * Rule comment score; The application rating and rule comment score can be determined by collecting ratings and comments from the target audience regarding the code scanning rule. If there are comments, the weight is 1; if there are no comments, the weight is 0.5. The rating reference is as follows: Very useful 9-10 points; Somewhat useful 7-8 points; Average 5-6 points; Not useful 3-4 points; Not recommended 0-2 points. For example, if an application has a rating of 9 points and no comments, the corresponding rule comment score is 9 * 0.5 = 4.5.
[0061] Finally, based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule obtained above, the first target recommendation degree for each code scanning rule is calculated. For example, the rule recommendation degree calculation formula is: Category recommendation coefficient * Rule recommendation degree coefficient * Total score.
[0062] By following the steps above, code scanning rules applicable to the target application code are calculated based on similarity, thus improving the accuracy of recommendations.
[0063] Converting the aforementioned code into corresponding feature vectors is crucial. Therefore, in the recommended method for code scanning rules provided in the application embodiment, the second feature vector corresponding to the target application code is obtained in the following manner: obtaining the total code from multiple code files in the target application code; performing data cleaning on the total code to obtain the processed total code; matching and classifying the processed total code using regular expressions to obtain the code corresponding to multiple code categories; and vectorizing the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector.
[0064] Specifically, the process reads the total code from multiple code files within the target application's codebase and performs data cleaning, such as removing comments, whitespace, newlines, and other special characters. It then scans each line of the source file, matching it using regular expressions to categorize and statistically analyze each piece of code. Code categories primarily include: keywords (fixed terms with special meaning in Java, such as "class", "public", "protect", etc.), identifiers (variables, methods, or user-defined names), operators, constants, and delimiters. An array is used to store each piece of code read from the file, recording its category and frequency. The keyword and identifier categories are vectorized to form a feature vector (w1, w2, w3, ..., wi, ..., wn) (i.e., the second feature vector mentioned above), where n is the number of codes, and wi represents the weighted frequency of the i-th word.
[0065] It should be noted that the same method described above is used to calculate the corresponding feature vector for each code scanning rule and rule category.
[0066] By following the steps above, we can extract the features of the code more accurately and obtain the corresponding feature vector.
[0067] Incremental code requires more scanning and detection. Therefore, in order to more accurately reflect the application code characteristics when calculating code vector features, the recommended method for code scanning rules provided in this application embodiment adopts the following steps to vectorize the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain a second feature vector: detect whether there is incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category; if there is incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category, modify the word frequency of each code in the incremental code to obtain the latest word frequency of each code in the incremental code; based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code, vectorize the code corresponding to the keyword and the code corresponding to the identifier to obtain a second feature vector.
[0068] Specifically, incremental code reflects the current state of the application code better than existing code. Therefore, we determine if incremental code exists; if so, we increase its word frequency to improve its weight. Then, based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code, we vectorize the code corresponding to the keyword and the code corresponding to the identifier to obtain the second feature vector.
[0069] In an optional embodiment, the word frequency of incremental code can be increased by multiplying the word frequency number by the word frequency coefficient: word frequency coefficient = 1 + number of unmodified codes in the current version / total number of applied codes.
[0070] The feature vectors obtained through the above steps can more accurately reflect the characteristics of the target application code.
[0071] The above content describes a recommendation algorithm based on target application code. For developers, to provide more personalized recommendations, a recommendation algorithm based on target application code and the target object's actions on the target application code is used to obtain the target recommendation score for each code scanning rule. Specifically, this includes: obtaining the first code file being edited by the target object, the target code scanning rules viewed by the target object, and the second code file containing changes to the target application code submitted by the target object through the target application development application; setting weight values for the code in the first code file, the target code scanning rules, and the second code file, and vectorizing them according to the weight values to obtain a first initial feature vector; calculating the second initial feature vector corresponding to the target application code based on multiple code files in the target application code; obtaining the fifth feature vector corresponding to the target application code based on the first and second initial feature vectors; obtaining a third radar distribution map based on the first, fifth, and fourth feature vectors; obtaining a third recommendation coefficient for each category of the code scanning rule using the third radar distribution map; and calculating the second target recommendation score for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0072] Specifically, the recommendation algorithm, based on the target application code and the target object's operation information on the target application code, derives the target recommendation score for each code scanning rule. This includes the following: Developers can browse and query relevant scanning rules through their local editor IDE scanning plugin (i.e., the target application development tool mentioned above), and select scanning rules to scan their local project code. The IDE plugin can also collect developer behavior information, such as the rules viewed by developers and the code they open for editing. Furthermore, the recommendation score for the code scanning rule is recalculated and updated in real time based on the collected behavior information.
[0073] The code edited by the developer (i.e., the first code file mentioned above): The code edited by the IDE includes the project opened in the IDE and the file opened in the code editor. The currently edited program is the code that the developer is most concerned about and most likely to want to be scanned, so it has the highest priority and its weight value can be set to 2; the program file currently opened in the editor is also program code that is of considerable concern, so it has a relatively high priority and its weight value can be set to 1; the project opened in the IDE is also content that the developer is concerned about, and the code weight value of the current project can be set to 0.5.
[0074] The code content viewed by developers (i.e., the target code scanning rules mentioned above): The IDE plugin provides a nested link to the code scanning center rule information query interface, which records the code viewed by developers in the background.
[0075] Developer-submitted code: Extract the code files (i.e., the second code file mentioned above) containing the target application code changes previously submitted by developers from the code version. This mainly includes the following: reading the date of the changed line code and calculating the number of days between the change date and the current date. Calculating the weight value of the changed line code based on the change date. Change weight value = (0.4 < number of days < 1263), this formula corresponds to a value monotonically decreasing from 100 to 0 for 0 to 1263 days, decreasing rapidly within 30 days, and then slowing down after 30 days. When the number of days is approximately less than 0.4, the change weight value is calculated using the above formula; if it is greater than 100, it is based on 100; when the number of days is greater than 1263, the change weight value is 0. When calculating code features, the weight value and word frequency are converted at a ratio of 100 to 1.
[0076] The first code file, target code scanning rules, and second code file are vectorized to obtain the developer's behavioral feature vector (i.e., the first initial feature vector). Multiple code files in the target application code are then processed to obtain the second initial feature vector corresponding to the target application code. Finally, the fifth feature vector corresponding to the target application code is obtained using the first and second initial feature vectors.
[0077] It should be noted that after obtaining the fifth feature vector corresponding to the target application code, the method for determining the recommendation degree of each code scanning rule is the same as that for the recommendation algorithm based on the target application code, and will not be elaborated here.
[0078] It should be noted that the two recommendation algorithms mentioned above can also be combined to obtain the recommendation score for each code scanning rule. For example, the recommendation score calculation formula is: First Target Recommendation Score * First Target Recommendation Score Percentage + Second Target Recommendation Score * Second Target Recommendation Score Percentage.
[0079] The code scanning rule recommendation method provided in this application embodiment obtains the target application code to be scanned, wherein the target application code consists of multiple code files; determines a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; obtains the target recommendation degree for each code scanning rule according to the target recommendation algorithm; and recommends target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule. This solves the problem in related technologies where code scanning rules for the target application code are selected manually based on experience, resulting in poor performance of the code scanning rules. When it is necessary to scan the target application code, the target recommendation algorithm is used to obtain the target recommendation degree of each code scanning rule, and then target code scanning rules are recommended for the target application code based on the target recommendation degree, thereby improving the effectiveness of the code scanning rules.
[0080] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0081] This application also provides a code scanning rule recommendation device. It should be noted that the code scanning rule recommendation device of this application can be used to execute the code scanning rule recommendation method provided in this application. The code scanning rule recommendation device provided in this application will be described below.
[0082] Figure 5 This is a schematic diagram of a recommended apparatus for code scanning rules according to embodiments of this application. Figure 5 As shown, the device includes: an acquisition unit 501, a first determination unit 502, a second determination unit 503, and a recommendation unit 504.
[0083] The acquisition unit 501 is used to acquire the target application code to be scanned, wherein the target application code consists of multiple code files;
[0084] The first determining unit 502 is used to determine a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code;
[0085] The second determining unit 503 is used to obtain the target recommendation degree of each code scanning rule based on the target recommendation algorithm;
[0086] Recommendation unit 504 is used to recommend target code scanning rules to the target application code based on the target recommendation degree of each code scanning rule.
[0087] The code scanning rule recommendation device provided in this application embodiment acquires the target application code to be scanned by an acquisition unit 501, wherein the target application code consists of multiple code files; a first determination unit 502 determines a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; a second determination unit 503 obtains the target recommendation degree of each code scanning rule according to the target recommendation algorithm; and a recommendation unit 504 recommends target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule. This solves the problem in related technologies where code scanning rules for the target application code are selected manually based on experience, resulting in poor performance of the code scanning rules. When it is necessary to scan the target application code, the target recommendation degree of each code scanning rule is obtained through the target recommendation algorithm, and then target code scanning rules are recommended for the target application code based on the target recommendation degree, thereby improving the performance of the code scanning rules.
[0088] Optionally, in the code scanning rule recommendation device provided in this application embodiment, when the target recommendation algorithm is a recommendation algorithm based on the target application code, the second determining unit 503 includes: a first acquisition subunit, used to acquire multiple code scanning rules and set a category label for each code scanning rule to obtain multiple rule categories of code scanning rules; a first calculation subunit, used to perform calculations based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; a second calculation subunit, used to perform calculations based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; a third calculation subunit, used to perform calculations based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; a second acquisition subunit, used to acquire a fourth feature vector corresponding to the code scanning rules that have been used by the target application code; and a first determining subunit, used to obtain a first target recommendation degree for each code scanning rule based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector.
[0089] Optionally, in the code scanning rule recommendation device provided in this application embodiment, the second calculation subunit includes: a first acquisition module, used to acquire the total code in multiple code files in the target application code; a cleaning module, used to perform data cleaning on the total code to obtain the processed total code; a classification module, used to match and classify the processed total code using regular expressions to obtain the code corresponding to multiple code categories; and a processing module, used to vectorize the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain a second feature vector.
[0090] Optionally, in the code scanning rule recommendation device provided in this application embodiment, the processing module includes: a detection submodule, used to detect whether there is incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category; a modification submodule, used to modify the word frequency of each code in the incremental code if there is incremental code in the code corresponding to the keyword code category and the code corresponding to the identifier code category, to obtain the latest word frequency of each code in the incremental code; and a processing submodule, used to perform vectorization processing on the code corresponding to the keyword and the code corresponding to the identifier based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code, to obtain a second feature vector.
[0091] Optionally, in the code scanning rule recommendation device provided in this application embodiment, the first determining subunit includes: a first determining module, used to obtain a first radar distribution map based on a first feature vector, a second feature vector, and a fourth feature vector; a second determining module, used to obtain a first recommendation coefficient for each rule category of the code scanning rule through the first radar distribution map; a third determining module, used to obtain a second radar distribution map based on the first feature vector and the third feature vector; a fourth determining module, used to obtain a second recommendation coefficient for each code scanning rule through the second radar distribution map; a second obtaining module, used to obtain the total score for each code scanning rule, wherein the total score is calculated by the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and a first calculating module, used to calculate the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0092] Optionally, in the code scanning rule recommendation device provided in the embodiments of this application, the first determining module includes: a first calculation submodule, used to calculate the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; a second calculation submodule, used to calculate the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; and a first mapping submodule, used to map the first similarity values and the second similarity values onto a radar map to obtain a first radar distribution map.
[0093] Optionally, in the code scanning rule recommendation device provided in the embodiments of this application, the third determining module includes: a third calculation submodule, used to calculate the similarity between the third feature vector and each first feature vector to obtain multiple third similarity values; and a second mapping submodule, used to map the third similarity values and the first similarity values onto a radar map to obtain a second radar distribution map.
[0094] Optionally, in the code scanning rule recommendation device provided in this application embodiment, when the target recommendation algorithm is a recommendation algorithm based on the target application code and the operation information of the target object on the target application code, the second determining unit 503 includes: a third obtaining subunit, used to obtain the fifth feature vector corresponding to the target application code; and a second determining subunit, used to obtain the second target recommendation degree of each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector and the fifth feature vector.
[0095] Optionally, in the code scanning rule recommendation device provided in this application embodiment, the second determining subunit includes: a fifth determining module, used to obtain a third radar distribution map based on the first feature vector, the fifth feature vector, and the fourth feature vector; a sixth determining module, used to obtain a third recommendation coefficient for each category of the code scanning rule through the third radar distribution map; and a second calculation module, used to calculate a second target recommendation degree for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0096] Optionally, in the code scanning rule recommendation device provided in this application embodiment, the third acquisition subunit includes: a third acquisition module, used to acquire, through the target program development application, a first code file that the target object is editing, a target code scanning rule that the target object has browsed, and a second code file that the target object has submitted to change the target application code, wherein the first code file is a code file in the target application code; a setting module, used to set the weight values of the code in the first code file, the target code scanning rule, and the second code file, and vectorize the first code file, the target code scanning rule, and the second code file according to the weight values to obtain a first initial feature vector; a third calculation module, used to calculate based on multiple code files in the target application code to obtain a second initial feature vector corresponding to the target application code; and to obtain a fifth feature vector corresponding to the target application code based on the first initial feature vector and the second initial feature vector.
[0097] The code scanning rule recommendation device includes a processor and a memory. The aforementioned acquisition unit 501, first determination unit 502, second determination unit 503, and recommendation unit 504 are all stored in the memory as program units. The processor executes the aforementioned program units stored in the memory to implement the corresponding functions.
[0098] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and the recommended code scanning rules can be implemented by adjusting kernel parameters.
[0099] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0100] like Figure 6 As shown in the figure, this embodiment of the invention provides a code scanning rule recommendation system, which mainly includes the following modules: A data collection and processing module: Data collection is the fundamental prerequisite for a code scanning rule recommendation system, including target application code data, behavioral data, etc., mainly achieved through methods such as preset tracking points, analysis of user logs, and result reporting. A correlation calculation and rule recommendation module: By analyzing the characteristics of the target application code, the recommendation degree of the code scanning rules is calculated. A system query and information collection module: This is a code scanning center containing functions such as managing the rule base, code scanning tasks, and collecting user information. Users can query the recommendation degree of each code scanning rule through the system query and information collection module, which also collects user behavior data.
[0101] This invention provides a processor for running a program, wherein the program executes a recommended method for code scanning rules during runtime.
[0102] like Figure 7 As shown, this embodiment of the invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: acquiring target application code to be scanned, wherein the target application code consists of multiple code files; determining a target recommendation algorithm for code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; obtaining the target recommendation degree of each code scanning rule according to the target recommendation algorithm; and recommending target code scanning rules for the target application code according to the target recommendation degree of each code scanning rule.
[0103] Optionally, when the target recommendation algorithm is a recommendation algorithm based on the target application code, obtaining the target recommendation degree for each code scanning rule according to the target recommendation algorithm includes: acquiring multiple code scanning rules and setting category labels for each code scanning rule to obtain multiple code scanning rules of rule categories; calculating based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; calculating based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; calculating based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; acquiring a fourth feature vector corresponding to the code scanning rules already used by the target application code; and obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, second feature vector, third feature vector, and fourth feature vector.
[0104] Optionally, calculating the second feature vector corresponding to the target application code based on multiple code files in the target application code includes: obtaining the total code from multiple code files in the target application code; cleaning the total code to obtain the processed total code; matching and classifying the processed total code using regular expressions to obtain the code corresponding to multiple code categories; and vectorizing the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector.
[0105] Optionally, vectorizing the codes corresponding to the keyword code category and the codes corresponding to the identifier code category to obtain the second feature vector includes: detecting whether there are incremental codes for the codes corresponding to the keyword code category and the codes corresponding to the identifier code category; if there are incremental codes for the codes corresponding to the keyword code category and the codes corresponding to the identifier code category, modifying the word frequency of each code in the incremental code to obtain the latest word frequency of each code in the incremental code; and vectorizing the codes corresponding to the keywords and the codes corresponding to the identifiers based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code to obtain the second feature vector.
[0106] Optionally, obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, second feature vector, third feature vector, and fourth feature vector includes: obtaining a first radar distribution map based on the first feature vector, second feature vector, and fourth feature vector; obtaining a first recommendation coefficient for each rule category of the code scanning rule using the first radar distribution map; obtaining a second radar distribution map based on the first feature vector and third feature vector; obtaining a second recommendation coefficient for each code scanning rule using the second radar distribution map; obtaining the total score for each code scanning rule, wherein the total score is calculated by the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and calculating the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, second recommendation coefficient, and the total score for each code scanning rule.
[0107] Optionally, obtaining the first radar distribution map based on the first feature vector, the second feature vector, and the fourth feature vector includes: calculating the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; calculating the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; and mapping the first similarity values and the second similarity values onto the radar map to obtain the first radar distribution map.
[0108] Optionally, obtaining the second radar distribution map based on the first feature vector and the third feature vector includes: calculating the similarity between the third feature vector and each first feature vector to obtain multiple third similarity values; mapping the third similarity values and the first similarity values onto the radar map to obtain the second radar distribution map.
[0109] Optionally, when the target recommendation algorithm is a recommendation algorithm based on the target application code and the operation information of the target object on the target application code, the target recommendation degree of each code scanning rule is obtained according to the target recommendation algorithm, including: obtaining the fifth feature vector corresponding to the target application code; and obtaining the second target recommendation degree of each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector and the fifth feature vector.
[0110] Optionally, the second target recommendation degree for each code scanning rule is obtained based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector, including: obtaining a third radar distribution map based on the first feature vector, the fifth feature vector, and the fourth feature vector; obtaining a third recommendation coefficient for each category of the code scanning rule through the third radar distribution map; and calculating the second target recommendation degree for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0111] Optionally, obtaining the fifth feature vector corresponding to the target application code includes: obtaining the first code file that the target object is editing, the target code scanning rules that the target object has browsed, and the second code file that the target object has submitted to modify the target application code through the target program development application, wherein the first code file is a code file in the target application code; setting the weight values of the code in the first code file, the target code scanning rules, and the second code file, and vectorizing the first code file, the target code scanning rules, and the second code file according to the weight values to obtain the first initial feature vector; calculating based on multiple code files in the target application code to obtain the second initial feature vector corresponding to the target application code; and obtaining the fifth feature vector corresponding to the target application code based on the first initial feature vector and the second initial feature vector.
[0112] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0113] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: obtaining target application code to be scanned, wherein the target application code consists of multiple code files; determining a target recommendation algorithm for code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; obtaining a target recommendation degree for each code scanning rule according to the target recommendation algorithm; and recommending target code scanning rules for the target application code according to the target recommendation degree of each code scanning rule.
[0114] Optionally, when the target recommendation algorithm is a recommendation algorithm based on the target application code, obtaining the target recommendation degree for each code scanning rule according to the target recommendation algorithm includes: acquiring multiple code scanning rules and setting category labels for each code scanning rule to obtain multiple code scanning rules of rule categories; calculating based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; calculating based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; calculating based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; acquiring a fourth feature vector corresponding to the code scanning rules already used by the target application code; and obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, second feature vector, third feature vector, and fourth feature vector.
[0115] Optionally, calculating the second feature vector corresponding to the target application code based on multiple code files in the target application code includes: obtaining the total code from multiple code files in the target application code; cleaning the total code to obtain the processed total code; matching and classifying the processed total code using regular expressions to obtain the code corresponding to multiple code categories; and vectorizing the code corresponding to the keyword code category and the code corresponding to the identifier code category to obtain the second feature vector.
[0116] Optionally, vectorizing the codes corresponding to the keyword code category and the codes corresponding to the identifier code category to obtain the second feature vector includes: detecting whether there are incremental codes for the codes corresponding to the keyword code category and the codes corresponding to the identifier code category; if there are incremental codes for the codes corresponding to the keyword code category and the codes corresponding to the identifier code category, modifying the word frequency of each code in the incremental code to obtain the latest word frequency of each code in the incremental code; and vectorizing the codes corresponding to the keywords and the codes corresponding to the identifiers based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code to obtain the second feature vector.
[0117] Optionally, obtaining the first target recommendation degree for each code scanning rule based on the first feature vector, second feature vector, third feature vector, and fourth feature vector includes: obtaining a first radar distribution map based on the first feature vector, second feature vector, and fourth feature vector; obtaining a first recommendation coefficient for each rule category of the code scanning rule using the first radar distribution map; obtaining a second radar distribution map based on the first feature vector and third feature vector; obtaining a second recommendation coefficient for each code scanning rule using the second radar distribution map; obtaining the total score for each code scanning rule, wherein the total score is calculated by the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and calculating the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, second recommendation coefficient, and the total score for each code scanning rule.
[0118] Optionally, obtaining the first radar distribution map based on the first feature vector, the second feature vector, and the fourth feature vector includes: calculating the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; calculating the similarity between the fourth feature vector and each first feature vector to obtain multiple second similarity values; and mapping the first similarity values and the second similarity values onto the radar map to obtain the first radar distribution map.
[0119] Optionally, obtaining the second radar distribution map based on the first feature vector and the third feature vector includes: calculating the similarity between the third feature vector and each first feature vector to obtain multiple third similarity values; mapping the third similarity values and the first similarity values onto the radar map to obtain the second radar distribution map.
[0120] Optionally, when the target recommendation algorithm is a recommendation algorithm based on the target application code and the operation information of the target object on the target application code, the target recommendation degree of each code scanning rule is obtained according to the target recommendation algorithm, including: obtaining the fifth feature vector corresponding to the target application code; and obtaining the second target recommendation degree of each code scanning rule based on the first feature vector, the third feature vector, the fourth feature vector and the fifth feature vector.
[0121] Optionally, the second target recommendation degree for each code scanning rule is obtained based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector, including: obtaining a third radar distribution map based on the first feature vector, the fifth feature vector, and the fourth feature vector; obtaining a third recommendation coefficient for each category of the code scanning rule through the third radar distribution map; and calculating the second target recommendation degree for each code scanning rule based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
[0122] Optionally, obtaining the fifth feature vector corresponding to the target application code includes: obtaining the first code file that the target object is editing, the target code scanning rules that the target object has browsed, and the second code file that the target object has submitted to modify the target application code through the target program development application, wherein the first code file is a code file in the target application code; setting the weight values of the code in the first code file, the target code scanning rules, and the second code file, and vectorizing the first code file, the target code scanning rules, and the second code file according to the weight values to obtain the first initial feature vector; calculating based on multiple code files in the target application code to obtain the second initial feature vector corresponding to the target application code; and obtaining the fifth feature vector corresponding to the target application code based on the first initial feature vector and the second initial feature vector.
[0123] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0124] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0125] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0126] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0127] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0128] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0129] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0130] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0131] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0132] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for recommending code scanning rules, characterized in that, include: Obtain the target application code to be scanned, wherein the target application code consists of multiple code files; A target recommendation algorithm is determined for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; Based on the target recommendation algorithm, the target recommendation score for each code scanning rule is obtained; Based on the target recommendation score of each code scanning rule, target code scanning rules are recommended for the target application code; When the target recommendation algorithm is the recommendation algorithm based on the target application code, the target recommendation degree for each code scanning rule is obtained according to the target recommendation algorithm, including: Multiple code scanning rules are obtained, and a category label is set for each code scanning rule to obtain code scanning rules with multiple rule categories; The first feature vector corresponding to each rule category is calculated based on the code scanning rules for each rule category. The second feature vector corresponding to the target application code is obtained by calculating based on multiple code files in the target application code. Based on each code scanning rule, multiple third feature vectors corresponding to each code scanning rule are obtained; Obtain the fourth feature vector corresponding to the code scanning rules that have been used by the target application code; Based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector, the first target recommendation degree of each code scanning rule is obtained; Based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector, the first target recommendation degree for each code scanning rule is obtained as follows: Based on the first feature vector, the second feature vector, and the fourth feature vector, a first radar distribution map is obtained; The first recommendation coefficient for each rule category of the code scanning rule is obtained using the first radar distribution map. Based on the first feature vector and the third feature vector, a second radar distribution map is obtained; The second recommendation coefficient for each code scanning rule is obtained using the second radar distribution map. Obtain the total score for each code scanning rule, wherein the total score is calculated from the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; The first target recommendation score for each code scanning rule is calculated based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
2. The method according to claim 1, characterized in that, The second feature vector corresponding to the target application code is calculated based on multiple code files in the target application code, including: Obtain the total code from multiple code files within the target application code; The total code is cleaned to obtain the processed total code; The processed total code is matched and classified using regular expressions to obtain code corresponding to multiple code categories; The code corresponding to the keyword code category and the code corresponding to the identifier code category are vectorized to obtain the second feature vector.
3. The method according to claim 2, characterized in that, The codes corresponding to the keyword code category and the codes corresponding to the identifier code category are vectorized to obtain the second feature vector, which includes: Detect whether there is an incremental code in the code corresponding to the keyword code category or the code corresponding to the identifier code category; If the incremental code exists between the code corresponding to the keyword code category and the code corresponding to the identifier code category, then the word frequency of each code in the incremental code is modified to obtain the latest word frequency of each code in the incremental code; Based on the latest word frequency of each code in the incremental code and the word frequency of each code in the existing code, the code corresponding to the keyword and the code corresponding to the identifier are vectorized to obtain the second feature vector.
4. The method according to claim 1, characterized in that, Based on the first feature vector, the second feature vector, and the fourth feature vector, the first radar distribution map is obtained as follows: Calculate the similarity between the second feature vector and each first feature vector to obtain multiple first similarity values; Calculate the similarity between the fourth feature vector and each of the first feature vectors to obtain multiple second similarity values; The first similarity value and the second similarity value are mapped onto the radar map to obtain the first radar distribution map.
5. The method according to claim 4, characterized in that, Based on the first feature vector and the third feature vector, the second radar distribution map is obtained as follows: Calculate the similarity between the third feature vector and each of the first feature vectors to obtain multiple third similarity values; The third similarity value and the first similarity value are mapped onto the radar map to obtain the second radar distribution map.
6. The method according to claim 3, characterized in that, When the target recommendation algorithm is the recommendation algorithm based on the target application code and the target object's operation information on the target application code, the target recommendation degree for each code scanning rule obtained according to the target recommendation algorithm includes: Obtain the fifth feature vector corresponding to the target application code; Based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector, the second target recommendation degree of each code scanning rule is obtained.
7. The method according to claim 6, characterized in that, Based on the first feature vector, the third feature vector, the fourth feature vector, and the fifth feature vector, the second target recommendation degree for each code scanning rule is obtained as follows: Based on the first feature vector, the fifth feature vector, and the fourth feature vector, a third radar distribution map is obtained; The third recommendation coefficient for each category of the code scanning rule is obtained through the third radar distribution map. The second target recommendation degree of each code scanning rule is calculated based on the third recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
8. The method according to claim 6, characterized in that, Obtaining the fifth feature vector corresponding to the target application code includes: The target program development application obtains the first code file that the target object is editing, the target code scanning rules that the target object has browsed, and the second code file that the target object has submitted to change the target application code, wherein the first code file is a code file in the target application code; Set the weight values of the code in the first code file, the target code scanning rule, and the second code file, and vectorize the first code file, the target code scanning rule, and the second code file according to the weight values to obtain a first initial feature vector; The second initial feature vector corresponding to the target application code is obtained by calculating based on multiple code files in the target application code. Based on the first initial feature vector and the second initial feature vector, the fifth feature vector corresponding to the target application code is obtained.
9. A code scanning rule recommendation device, characterized in that, include: The acquisition unit is used to acquire the target application code to be scanned, wherein the target application code consists of multiple code files; The first determining unit is configured to determine a target recommendation algorithm for the code scanning rules of the target application code, wherein the target recommendation algorithm includes at least one of the following: a recommendation algorithm based on the target application code and a recommendation algorithm based on the target application code and the operation information of the target object on the target application code; The second determining unit is used to obtain the target recommendation degree for each code scanning rule based on the target recommendation algorithm. The recommendation unit is used to recommend target code scanning rules for the target application code based on the target recommendation degree of each code scanning rule; Wherein, when the target recommendation algorithm is a recommendation algorithm based on the target application code, the second determining unit includes: a first acquisition subunit, used to acquire multiple code scanning rules and set category labels for each code scanning rule to obtain multiple rule categories of code scanning rules; a first calculation subunit, used to calculate based on the code scanning rules of each rule category to obtain a first feature vector corresponding to each rule category; a second calculation subunit, used to calculate based on multiple code files in the target application code to obtain a second feature vector corresponding to the target application code; a third calculation subunit, used to calculate based on each code scanning rule to obtain multiple third feature vectors corresponding to each code scanning rule; a second acquisition subunit, used to acquire a fourth feature vector corresponding to the code scanning rules already used by the target application code; and a first determining subunit, used to obtain a first target recommendation degree for each code scanning rule based on the first feature vector, the second feature vector, the third feature vector, and the fourth feature vector. The first determining subunit includes: a first determining module, used to obtain a first radar distribution map based on a first feature vector, a second feature vector, and a fourth feature vector; a second determining module, used to obtain a first recommendation coefficient for each rule category of the code scanning rule through the first radar distribution map; a third determining module, used to obtain a second radar distribution map based on the first feature vector and the third feature vector; a fourth determining module, used to obtain a second recommendation coefficient for each code scanning rule through the second radar distribution map; a second obtaining module, used to obtain the total score for each code scanning rule, wherein the total score is calculated by the rule error rate of each code scanning rule and the target object's rating of each code scanning rule; and a first calculating module, used to calculate the first target recommendation degree for each code scanning rule based on the first recommendation coefficient, the second recommendation coefficient, and the total score of each code scanning rule.
10. A processor, characterized in that, The processor is used to run a program, wherein the program, when running, executes the recommended method of the code scanning rules as described in any one of claims 1 to 8.
11. An electronic device, characterized in that, It includes one or more processors and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the recommended method of the code scanning rules as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Code verification algorithm selection method and device and storage medium
CN112214402A