This project implements a system to detect similarity between source code snippets using Abstract Syntax Tree (AST) analysis and textual comparison. A fuzzy logic model integrates these metrics to produce an overall similarity score, assisting in assessing originality and preventing copyright infringement.
- AST Analysis: Analyzes the structure of code snippets to determine similarity.
- Textual Similarity: Computes the textual similarity percentage between code strings.
- Fuzzy Logic Model: Utilizes fuzzy logic to evaluate overall similarity based on AST and textual metrics.
- Similarity Classification: Categorizes similarity scores into distinct classes.
- Python 3.x
numpy
skfuzzy
- Import the necessary libraries.
- Define the code snippets you want to compare.
- Call the
compare_codes(code1, code2)
function to get the similarity score and classification.
analyze_ast(code):
Analyzes the AST of the given code.calculate_text_similarity(code1, code2):
Computes the textual similarity percentage.create_fuzzy_logic_model():
Creates and configures the fuzzy logic model.compare_codes(code1, code2):
Main function to compare two code snippets.classify_similarity(score):
Classifies the similarity score into categories.
- Skfuzzy for fuzzy logic implementation.
- Numpy for numerical operations.
This project is licensed under the MIT License - see the LICENSE file for details.