Git Product home page Git Product logo

pyastsim's Introduction

pyastsim

Build Status PyPI version

Calculates the similarity between a batch of source files.

Installation

The program can be installed using pip:

pip3 install pyastsim

Usage

usage: pyastsim [-h] [--threshold THRESHOLD] [--show-diff]
                [--function FUNCTION]
                files [files ...]

Check source files for similarity

positional arguments:
  files                 List of files to compare

optional arguments:
  -h, --help            show this help message and exit
  --threshold THRESHOLD
                        Similarity threshold. Values below this are not
                        reported.
  --show-diff           Show entire diff when reporting results.
  --function FUNCTION   Specific function to compare (Python source only)

Examples

Show check for similarity of a group of files using default settings:

pyastsim *.py

Set a custom threshold to be more or less sensative (default threshold is 80% similarity):

pyastsim --threshold 90 *.py

Show full diffs when reporting similar files:

pyastsim --show-diff *.py

Remove all but one function from the AST before performing comparison:

pyastsim --function my_func *.py

Language Support

  • Python (using internal AST for comparison)
  • C/C++ (using GCC assembly output for comparison)

Difference Calculation

The difference is calculated by first converting each supplied file to an abstract syntax tree (AST). The AST is then normalized to remove comments, docstrings, and standardize identifier names. We then convert the AST back to Python source code and calculate the Damerau–Levenshtein distance between each pair of source files. We further normalize this number by dividing it by the mean of the number of unicode code points in the files being compared. This gives us a rough percentage similarity between our files. To summarize:

  1. Convert to AST
  2. Remove comments and docstrings
  3. Normalize identifiers
  4. Convert back to source
  5. Calculate Damerau–Levenshtein distance
  6. Covert the edit distance to a percentage

pyastsim's People

Contributors

jncraton avatar

Stargazers

JeongHoon Baek avatar Huang Zhengjie avatar  avatar Hristo Vrigazov avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.