Code similarity review method based on artificial intelligence
By using artificial intelligence-based methods and deep learning and machine learning models to extract semantic features of code, the accuracy and efficiency problems of traditional code similarity review are solved. This enables efficient identification of code plagiarism, reuse, and vulnerabilities, and is adaptable to diverse programming languages and styles.
Patent Information
- Application Number
- CN202510868738.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-11-07
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence and software engineering, and particularly relates to a code similarity review method based on artificial intelligence. BACKGROUND
[0002] With the continuous expansion of software size and the continuous shortening of development cycle, code similarity review becomes more and more important in software engineering. Traditional code similarity review methods are mainly based on text matching, syntax tree matching and control flow graph matching technologies. Although these methods are simple and easy to use, they have the following shortcomings: traditional methods are difficult to handle the semantic information of code, are easily disturbed by code format, variable naming and other factors, resulting in low accuracy of review results; traditional methods need to define a large number of rules and features manually, which is difficult to cope with the complexity and diversity of code, resulting in low review efficiency; traditional methods are difficult to adapt to new programming languages and code styles, and have poor scalability. SUMMARY
[0003] In order to solve the above technical problems, the present application provides a code similarity review method based on artificial intelligence, which can automatically learn the semantic features of code, detect the similarity of code, identify potential code plagiarism, code reuse and code vulnerabilities, and improve the accuracy, efficiency and scalability of code similarity review.
[0004] The technical scheme of the present application is:
[0005] A code similarity review method based on artificial intelligence,
[0006] comprising the following steps:
[0007] Data preprocessing: preprocessing the source code, including removing comments, formatting code, extracting code features;
[0008] Feature extraction: using a pre-trained deep learning model to extract semantic features of the code;
[0009] Model training: training a machine learning model using the extracted code semantic features;
[0010] Code similarity review: using the trained machine learning model to review the similarity of new code, outputting similarity score and similar code fragments.
[0011] Further,
[0012] Automatically learning the semantic features of the code for detecting the similarity of the code, identifying potential code plagiarism, code reuse and code vulnerabilities.
[0013] Further,
[0014] The code features include: code line number, code complexity, code dependency, code control flow graph.
[0015] Further,
[0016] The deep learning model includes Transformer, BERT.
[0017] The pre-trained deep learning model is used to extract the semantic features of the code, including the context information of the code, the syntax structure of the code, and the semantic information of the code.
[0018] Further,
[0019] The extracted code semantic features are used to train a machine learning model for code similarity classification, including support vector machines, random forests, and neural networks.
[0020] Further,
[0021] The trained machine learning model is used to perform similarity review on new code and output similarity scores and similar code fragments.
[0022] The similarity score and the similar code fragment include the similarity score, the similar code fragment, and the code plagiarism detection result.
[0023] The beneficial effects of the present application are
[0024] The present application uses a deep learning model to extract the semantic features of the code, which can effectively improve the accuracy of the code similarity review, and uses a machine learning model to classify the code similarity, which can effectively improve the efficiency of the code similarity review, and can adapt to new programming languages and code styles, and has strong scalability. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical scheme and advantages of the embodiments of the present application more clear, the technical scheme in the embodiments of the present application will be described clearly and completely below. Obviously, the described embodiments are part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0026] The code similarity review method based on artificial intelligence provided by the present application comprises the following steps:
[0027] Data preprocessing: preprocessing the source code, including removing comments, formatting code, extracting code features, etc.
[0028] Feature extraction: using a pre-trained deep learning model, such as Transformer, BERT, etc., to extract the semantic features of the code.
[0029] Model training: using the extracted code semantic features, train a machine learning model such as support vector machine, random forest, etc. for code similarity classification.
[0030] Code similarity review: using the trained machine learning model, conduct similarity review on new code and output similarity score and similar code fragments.
[0031] The above only describes the preferred embodiments of the present application, which are used to illustrate the technical solutions of the present application, and are not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. An artificial intelligence-based code similarity review method, characterized in that, comprising the following steps: data preprocessing: preprocessing the source code, including removing comments, formatting code, extracting code features; feature extraction: using a pre-trained deep learning model to extract semantic features of the code; model training: using the extracted code semantic features to train a machine learning model; code similarity review: using the trained machine learning model to review the similarity of new code and output similarity scores and similar code fragments.
2. The method of claim 1, characterized in that, automatically learning the semantic features of the code to detect the similarity of the code and identify potential code plagiarism, code reuse and code vulnerabilities.
3. The method of claim 1, characterized in that, code features include: number of code lines, code complexity, code dependency, code control flow graph.
4. The method of claim 1, characterized in that, the deep learning model includes Transformer, BERT.
5. The method of claim 1 or 4, characterized in that, using a pre-trained deep learning model to extract semantic features of the code, including context information of the code, syntax structure of the code, semantic information of the code.
6. The method of claim 1, characterized in that, using the extracted code semantic features to train a machine learning model for code similarity classification, including: support vector machine, random forest, neural network.
7. The method of claim 1, characterized in that, using the trained machine learning model to review the similarity of new code and output similarity scores and similar code fragments.
8. The method of claim 7, characterized in that, similarity scores and similar code fragments include similarity scores, similar code fragments, code plagiarism detection results.