apted icon indicating copy to clipboard operation
apted copied to clipboard

Documentation

Open daubin427 opened this issue 6 years ago • 1 comments

Hello!

Thank you for making this! Do you happen to have a programmatic hello world example? I want to try the algorithm, but I'm not sure how to go about creating a tree in python to hand off to your edit distance calculation.

Thank you :)

daubin427 avatar Nov 21 '18 17:11 daubin427

I think I was looking for something like this:

#!/usr/bin/python3
  
from apted import APTED, Config, helpers
import timeit

test = {}
test["t1"] = "{a{b}{c}}"
test["t2"] = "{a{b{d}}}"

"""Creates testcase for test dict"""
tree1 = helpers.Tree.from_text(test["t1"])
tree2 = helpers.Tree.from_text(test["t2"])

startTime = timeit.default_timer()
apted = APTED(tree1, tree2)
ted = apted.compute_edit_distance()
mapping = apted.compute_edit_mapping()

runtime = timeit.default_timer() - startTime
print("distance: %d" %ted)
print("runtime: %f" %runtime)
for editMap in mapping:
    print("%s -> %s" %(editMap[0], editMap[1]))

distance: 2 runtime: 0.000246 {a{b}{c}} -> {a{b{d}}} {c} -> None {b} -> {b{d}} None -> {d}

daubin427 avatar Nov 21 '18 18:11 daubin427