Package: apted
InformationThis is a Python implementation of the APTED algorithm, the
state-of-the-art solution for computing the tree edit distance [1,2],
which supersedes the RTED algorithm [3].It is a port of the original Java implementation available athttps://github.com/DatabaseGroup/apted. During the port, some changes
were made to reduce the duplication on symmetric operations and to make
it look more Pythonic.You can find more information about APTED on the following websitehttp://tree-edit-distance.dbresearch.uni-salzburg.at/Citing APTEDIf you want to refer to APTED in a publication, please cite [1] and [2].LicenceThe source code is published under theMIT licencefound in the root
directory of the project and in the header of each source file.InputCurrently, we support only the so-called bracket notation for the input
trees, for example, encoding{A{B{X}{Y}{F}}{C}}corresponds to the
following tree:A
   / \
  B   C
 /|\
X Y FOutputOur tool computes two outputs: - tree editdistancevalue - the
minimum cost of transforming the source tree into the destination tree.
- tree editmapping- a mapping between nodes that corresponds to
the tree edit distance value. Nodes that are not mapped are deleted
(source tree) or inserted (destination tree).Getting startedThis version were tested on Python 2.7, 3.4, 3.5, and 3.6.First, install it with pip:pip install aptedIf you want to compare the trees {a{b}{c}} and {a{b{d}}}, please run:python -m apted -t {a{b}{c}} {a{b{d}}} -mvThe output is:distance:             2
runtime:              0.000270843505859
{a{b}{c}} -> {a{b{d}}}
{c} -> None
{b} -> {b{d}}
None -> {d}For more information on running options, please runpython -m apted -hCustomizingIt is possible to customize the algorithm to run with custom trees with
labels different from simple strings or custom data-structures.
Additionally it is possible to customize it to use a more sophisticated
cost model than unit cost.For customizing the algorithm, you can create a customConfigclass:fromaptedimportAPTED,ConfigclassCustomConfig(Config):defrename(self,node1,node2):"""Compares attribute .value of trees"""return1ifnode1.value!=node2.valueelse0defchildren(self,node):"""Get left and right children of binary tree"""return[xforxin(node.left,node.right)ifx]apted=APTED(tree1,tree2,CustomConfig())ted=apted.compute_edit_distance()mapping=apted.compute_edit_mapping()By default, the includedConfigclass consider trees with the atributenameas label and the atributechildrenas children in left to right
preorder.In addition to the Config class, we also provide aPerEditOperationConfigclass that allows you to specify weights for
each operation:fromaptedimportAPTED,PerEditOperationConfigapted=APTED(tree1,tree2,PerEditOperationConfig(.4,.4,.6))ted=apted.compute_edit_distance()mapping=apted.compute_edit_mapping()If your main usage for APTED is to obtain the mapping, it is possible to
configure the algorith to keep track of the mapping during the
execution. To do so, we provide a function,meta_chained_config,
that modifies existingConfigclasses:fromaptedimportAPTED,PerEditOperationConfig,meta_chained_confignew_config=meta_chained_config(PerEditOperationConfig)apted=APTED(tree1,tree2,new_config(.4,.4,.6))ted=apted.compute_edit_distance()mapping=apted.compute_edit_mapping()Note that this approach uses much more memory and we didn’t evaluate if
it is faster than the original algorithm for the mapping with huge
trees. The execution time for the mapping tests were about the same as
the original algorithm.ContributingFeel free to submit pull resquests to this repository.The codebase follows the PEP8 conventions. However it is not too strict.
For instance, it is okay to have lines with a little more than 79
characters, but try not to exceed too much.Please, runpython test.pyduring your changes to make sure
everything is working. It is also desirable to use coverage.py to check
test coverage:coverage run test.py.Original AuthorsMateusz PawlikNikolaus AugstenImplementation AuthorJoao Felipe PimentelReferencesM. Pawlik and N. Augsten.Tree edit distance: Robust and memory-
efficient. Information Systems 56. 2016.M. Pawlik and N. Augsten.Efficient Computation of the Tree Edit
Distance. ACM Transactions on Database Systems (TODS) 40(1). 2015.M. Pawlik and N. Augsten.RTED: A Robust Algorithm for the Tree Edit
Distance. PVLDB 5(4). 2011.