GithubHelp home page GithubHelp logo

t-diff's Introduction

Build Status

T-diff

This repository contains the implementation of an algorithm computing the distance between two trees. The algorithm was published in an aricle titled "The Tree-to-Tree Correction Problem" by Kuo-Chung Tai at the Journal of the ACM, 26(3):422-433, in July 1979.

The time complexity of the algorithm is O(V * V' * L^2 * L'^2) where V, V' are the number of nodes and L, L' are the the maximum depths of the source and target trees respectively.

During the implementation, we came across some minor issues in the reported algorithm. The implementation contains the fixes for these issues.

At the moment, the trees are assumed to be instances of Tree class in the tree module contained in the implementation. An example run is below

from util.tree import *
from treediff import *

# Source Tree
a = TreeNode('A')
b = TreeNode('B')
a.add_child(b)
d = TreeNode('D')
b.add_child(d)
treeOne = Tree(a)
treeOne.build_caches()

# Target Tree
a = TreeNode('A')
b = TreeNode('B')
c = TreeNode('C')
d = TreeNode('D')
a.add_child(b)
a.add_child(c)
c.add_child(d)
treeTwo = Tree(a)
treeTwo.build_caches()

# Diff Computation
distance, mapping = computeDiff(treeOne, treeTwo) 
print distance # Prints 2
print mapping # [(1, 1), (2, 3), (3, 4), ('alpha', 2)]
print produceHumanFriendlyMapping(mapping, treeOne, treeTwo) # ['No change for A (@1 and @1)', 'Change from B (@2) to C (@3)', 'No change for D (@3 and @4)', 'Insert B (@2)']

The last line shows how to produce the mapping between the source and the target describing how a sequence of edit operations transforms the source tree to the target, ignoring the order in which edit operations are applied.

Project site: https://cagdasgerede.github.io/T-diff/

Dependencies:

  • Graphviz (sudo apt-get install graphviz)
  • pip install requirements.txt

t-diff's People

Contributors

cagdasgerede avatar hacetin avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

brambg

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.