Tree Similarity of Edit Distance (TSED) Calculator
Overview
This Python script calculates the Tree Similarity of Edit Distance (TSED) between two trees, utilizing the APTED (A Framework for Tree Edit Distance) library. TSED is commonly employed in tasks such as code review and evaluation, offering a metric for assessing the structural similarity between two tree structures.
Requirements
Dependencies
Usage
Using a virtual environment is a useful way to manage dependencies, particularly with multiple versions of Python.
% python -m venv .venv
% source .venv/bin/activate
Follow the rest of the steps in the virtual environment
-
Ensure that the necessary dependencies are installed:
% pip install -r requirements.txt
-
Modify the script as needed, providing the language, origin tree, and target tree information.
-
Use in your code:
import TSED line1 = "Code1" line2 = "Code2" ts_score = TSED.Calculate("python", line1, line2, 1.0, 0.8, 1.0)
Script Explanation
Node: A class representing a node in the tree structure.parse_tree_string(tree_string): Parses the tree string and constructs a tree structure using theNodeclass._parse(language, program_str, encoding): Parses the given program string into a tree format used bytree_sitter._get_tree(language, program_str): Parses the given program string into a tree format (i.e.,Node) used by the script.Calculate(programming_language, origin, target, deletion_weight, insertion_weight, rename_weight): Calculates the TSED using the APTED library with custom edit operation configurations.
Parameters
programming_language: A programming language for parsing, that is suppored bytree_sitter_language_pack. A list of supported languages is available.originandtarget: Strings representing the origin and target trees.deletion_weight,insertion_weight,rename_weight: Custom edit operation weights for deletion, insertion, and renaming.
Output
The script outputs a similarity score between 0 and 1, representing the structural similarity between two strings representing the origin and target trees of some source code.
Citation
If you use TSED, please cite:
@inproceedings{song-etal-2024-revisiting,
title = "Revisiting Code Similarity Evaluation with Abstract Syntax Tree Edit Distance",
author = "Song, Yewei and
Lothritz, Cedric and
Tang, Daniel and
Bissyand{\'e}, Tegawend{\'e} and
Klein, Jacques",
editor = "Ku, Lun-Wei and
Martins, Andre and
Srikumar, Vivek",
booktitle = "Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers)",
month = aug,
year = "2024",
address = "Bangkok, Thailand",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.acl-short.3/",
doi = "10.18653/v1/2024.acl-short.3",
pages = "38--46",
}
Release files for tsed 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tsed-0.1.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsed-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / tsed-0.1.0.tar.gz
| Download URL | tsed-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17daa2788282b330afd4799bca67d14ed9b2eae53c3e81b0ccc5c483a0ffc37c
|
|
BLAKE2b-256 checksum How to use checksums |
e37325e2028e47b9890f70ae0845bf9465c52f62269dfb1987eed7e6e08b66e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / tsed-0.1.0-py3-none-any.whl
| Download URL | tsed-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d05335512fdd25f8dbef8086a6e91984e7f8cdb8d883cabaed7e108531d5c13e
|
|
BLAKE2b-256 checksum How to use checksums |
ee35262efd8f6eef39a61c691650fc86d0481fac4c449e357bc45fac2f1dbfd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|