summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-08-05 22:46:43 +0200
committerPatrick Simianer <p@simianer.de>2014-08-05 22:46:43 +0200
commit0b3cdb4ae2fa176ba74a48ff7a1616395079c151 (patch)
tree7092a57ed7d29920df3ae2f97c39efc17c5e6095 /util
parenta27e2c529ddb7dc1be0c6bcc44e3ab558126d15d (diff)
too much to tell
Diffstat (limited to 'util')
-rwxr-xr-xutil/cdec2json.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/util/cdec2json.py b/util/cdec2json.py
index a721644..adddb64 100755
--- a/util/cdec2json.py
+++ b/util/cdec2json.py
@@ -7,6 +7,8 @@ import gzip
#FIXME new format
+# strings?
+# map?
def hg2json(hg, weights):
"""
output a JSON representation of a cdec hypegraph
@@ -20,6 +22,16 @@ def hg2json(hg, weights):
a.append( '"%s":%s'%(i[0], i[1]) )
res += ", ".join(a)+"\n"
res += "},\n"
+ res += '"rules":[\n'
+ rules = []
+ for i in hg.edges:
+ s = json.dumps(str(i.trule))
+ try:
+ rules.index(s)
+ except:
+ rules.append(s)
+ res += ",\n".join(rules)
+ res += "\n],\n"
res += '"nodes":'+"\n"
res += "[\n"
a = []
@@ -34,21 +46,21 @@ def hg2json(hg, weights):
for i in hg.edges:
s = "{"
s += '"head":%d'%(i.head_node.id+1)
- s += ', "rule":%s'%(json.dumps(str(i.trule)))
+ s += ', "rule":%s'%(rules.index(json.dumps(str(i.trule))))
# f
- xs = ' "f":{'
- b = []
- for j in i.feature_values:
- b.append( '"%s":%s'%(j[0], j[1]) )
- xs += ", ".join(b)
- xs += "},"
+ #xs = ' "f":{'
+ #b = []
+ #for j in i.feature_values:
+ # b.append( '"%s":%s'%(j[0], j[1]) )
+ #xs += ", ".join(b)
+ #xs += "},"
# tails
if len(list(i.tail_nodes)) > 0:
s += ', "tails":[ %s ],'%(",".join([str(n.id+1) for n in i.tail_nodes]))
else:
s += ', "tails":[ 0 ],'
- s += xs
- s += ' "weight":%s }'%(i.prob)
+ #s += xs
+ s += ' "score":%s }'%(i.prob)
a.append(s)
res += ",\n".join(a)+"\n"
res += "]\n"