File size: 3,418 Bytes
9b76a89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #!/usr/bin/python
#
#######################################################################
#
#
# postprocess-specific.py
#
# USAGE: ./postprocess-specific.py [--dont-reverse-Stransform] treebank.gld treebank.jmx < treebank.parsed
#
# Postprocess trees.
# Postprocess a tree against the original treebank tree, such that
# EVALB can compare the parsed tree with the original tree.
#
# WRITEME: Describe more specifically.
#
#
# $Id: postprocess-specific.py 1657 2006-06-04 03:03:05Z turian $
#
#
#######################################################################
# Copyright (c) 2004-2006, New York University. All rights reserved
#######################################################################
from variables import *
import parsetree
import sys
if mysys == "Linux" and not profile:
try:
debug(1, "Linux detected... using psyco")
import psyco
psyco.full(memory=4096)
# psyco.full()
# psyco.log()
# psyco.full(memory=128)
# psyco.profile(0.05, memory=1024)
# psyco.profile(0.2)
except:
debug(1, "Could not import psyco")
elif not profile:
debug(1, "Uname gives %s... NOT using psyco" % (mysys))
else:
debug(1, "Profiling...")
import hotshot, hotshot.stats
def main():
reverse_Stransform = True
if len(sys.argv) == 4:
assert(sys.argv[1]) == "--dont-reverse-Stransform"
reverse_Stransform = False
sys.argv = sys.argv[1:]
debug(1, "NOT reversing Stransform.")
assert(len(sys.argv) == 3)
debug(1, "Opening files:\n\t%s\n\t%s\n" % (sys.argv[1], sys.argv[2]))
treebank_file = open(sys.argv[1])
jmx_file = open(sys.argv[2])
sentence = 0
for l in sys.stdin:
sentence += 1
if not l: assert(0)
if l == "\n":
lt = treebank_file.readline()
lj = jmx_file.readline()
print
continue
tree = parsetree.read_tree(l)
assert tree != None
if duplicate_top_item:
assert(0)
# Add a second TOP label, s.t. we can raise punctuation
# above the first TOP label
node = parsetree.Node()
node.isleaf = 0
node.label = "TOP"
node.children = [tree]
tree = parsetree.refresh(node)
# else:
# tree = parsetree.refresh(tree)
lt = treebank_file.readline()
treebank_tree = parsetree.read_tree(lt)
assert treebank_tree != None
treebank_tree = parsetree.reverse_regularize(treebank_tree)
treebank_leaves = [(n.headword, n.headtag) for n in treebank_tree.leaves()]
del treebank_tree
lj = jmx_file.readline()
jmx_tree = parsetree.read_tree(lj)
assert jmx_tree != None
jmx_tree = parsetree.reverse_regularize(jmx_tree)
jmx_leaves = [(n.headword, n.headtag) for n in jmx_tree.leaves()]
del jmx_tree
tree = parsetree.reverse_regularize(tree)
treestr = tree.to_string()
tree = parsetree.reverse_regularize(tree)
assert treestr == tree.to_string()
parsetree.postprocess(tree, origleaves=jmx_leaves, treebank_leaves=treebank_leaves, reverse_Stransform=reverse_Stransform)
print tree.to_string()
if sentence % 100 == 0:
debug(1, "Sentence #%d done" % sentence)
else:
debug(2, "Sentence #%d done" % sentence)
assert(not treebank_file.readline())
assert(not jmx_file.readline())
treebank_file.close()
jmx_file.close()
if profile:
#prof = hotshot.Profile("oracle.prof", lineevents=1)
prof = hotshot.Profile("oracle.prof")
prof.runcall(main)
prof.close()
stats = hotshot.stats.load("oracle.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
else:
main()
|