#!@TARGET_PYTHON@
import sys
import optparse
-import os
-## so we can call directly as buildscripts/output-distance.py
-me_path = os.path.abspath (os.path.split (sys.argv[0])[0])
-sys.path.insert (0, me_path + '/../python/')
+## so we can call directly as buildscripts/output-distance.py
+sys.path.insert (0, '../python')
import safeeval
empty_interval = (INFTY, -INFTY)
empty_bbox = (empty_interval, empty_interval)
-def interval_is_empty (i):
- return i[0] > i[1]
-
def interval_length (i):
return max (i[1]-i[0], 0)
return (max (i1[0], i2[0]),
min (i1[1], i2[1]))
-def bbox_is_empty (b):
- return (interval_is_empty (b[0])
- or interval_is_empty (b[1]))
-
def bbox_union (b1, b2):
return (interval_union (b1[X_AXIS], b2[X_AXIS]),
interval_union (b2[Y_AXIS], b2[Y_AXIS]))
else:
return OUTPUT_EXPRESSION_PENALTY
+ def distance(self, other, max_distance):
+ return (self.expression_distance (other)
+ + self.centroid_distance (other, max_distance)
+ + self.bbox_distance (other))
+
class SystemSignature:
def __init__ (self, grob_sigs):
d = {}
self.back_link_dict = {}
for g in system1.grobs ():
-
- ## skip empty bboxes.
- if bbox_is_empty (g.bbox):
- continue
-
closest = system2.closest (g.name, g.centroid)
self.link_list_dict.setdefault (closest, [])
self.link_list_dict[closest].append (g)
self.back_link_dict[g] = closest
- def geometric_distance (self):
+ def distance (self):
d = 0.0
- for (g1,g2) in self.back_link_dict.items ():
- if g2:
- # , scale
- d += g1.bbox_distance (g2)
- return d
-
- def orphan_distance (self):
- d = 0.0
+ scale = max (bbox_diameter (self.system1.bbox),
+ bbox_diameter (self.system2.bbox))
+
for (g1,g2) in self.back_link_dict.items ():
if g2 == None:
d += ORPHAN_GROB_PENALTY
- return d
-
- def output_exp_distance (self):
- d = 0.0
- for (g1,g2) in self.back_link_dict.items ():
- if g2:
- d += g1.expression_distance (g2)
+ else:
+ d += g1.distance (g2, scale)
+
+ for (g1,g2s) in self.link_list_dict.items ():
+ if len (g2s) != 1:
+ d += ORPHAN_GROB_PENALTY
return d
- def distance (self):
- return (self.output_exp_distance (),
- self.orphan_distance (),
- self.geometric_distance ())
-
################################################################
# Files/directories
f1 = dir1 + '/' + p
distance = compare_signature_files (f1, f2)
self.result_dict[f2] = (distance, f1)
-
+
def create_text_result_page (self, dir1, dir2):
self.write_text_result_page (dir2 + '/' + os.path.split (dir1)[1] + '.txt')
out = sys.stdout
else:
out = open (filename, 'w')
-
- ## todo: support more scores.
- results = [(geo_score, oldfile, file)
- for (file, ((exp_score, orphan_score,
- geo_score), oldfile))
- in self.result_dict.items ()]
+ results = [(score, oldfile, file) for (file, (score, oldfile)) in self.result_dict.items ()]
results.sort ()
results.reverse ()
threshold = 1.0
- results = [(geo_score, oldfile, file) for (file, ((exp_score, orphan_score,
- geo_score), oldfile)) in self.result_dict.items ()
- if geo_score > threshold]
+ results = [(score, oldfile, file) for (file, (score, oldfile)) in self.result_dict.items ()
+ if score > threshold]
results.sort ()
results.reverse ()
-
+
html = ''
old_prefix = os.path.split (dir1)[1]
dest_dir = os.path.join (dir2, old_prefix)
shutil.rmtree (dest_dir, ignore_errors=True)
os.mkdir (dest_dir)
- for (score, oldfile, newfile) in results:
-
- old_base = re.sub ("-[0-9]+.signature", '', oldfile)
- old_name = os.path.split (old_base)[1]
+ for (score, oldfile, newfile) in results:
+ old_base = re.sub ("-[0-9]+.signature", '', os.path.split (oldfile)[1])
new_base = re.sub ("-[0-9]+.signature", '', newfile)
for ext in 'png', 'ly':
- src_file = old_base + '.' + ext
-
- if os.path.exists (src_file):
- shutil.copy2 (src_file, dest_dir)
- else:
- print "warning: can't find", src_file
+ shutil.copy2 (old_base + '.' + ext, dest_dir)
- img_1 = os.path.join (old_prefix, old_name + '.png')
- ly_1 = os.path.join (old_prefix, old_name + '.ly')
+ img_1 = os.path.join (old_prefix, old_base + '.png')
+ ly_1 = os.path.join (old_prefix, old_base + '.ly')
img_2 = new_base.replace (dir2, '') + '.png'
img_2 = re.sub ("^/*", '', img_2)
html += html_entry
html = '''<html>
-<table rules="rows" border bordercolor="blue">
+<table>
<tr>
<th>distance</th>
<th>old</th>
def compare_trees (dir1, dir2):
- data = ComparisonData ()
+ data = ComparisonData ()
data.compare_trees (dir1, dir2)
data.print_results ()
data.create_html_result_page (dir1, dir2)
-# data.create_text_result_page (dir1, dir2)
+ data.create_text_result_page (dir1, dir2)
################################################################
# TESTING
p (scorify-music m p)))))
%(papermod)s
-<<
-\new Staff \relative c {
- c^"%(userstring)s" %(extragrob)s
- }
-\new Staff \relative c {
+
+\relative c {
c^"%(userstring)s" %(extragrob)s
}
->>
"""
dicts = [{ 'papermod' : '',