summaryrefslogtreecommitdiff
path: root/sa-extract
diff options
context:
space:
mode:
authorJonathan Clark <jon.h.clark@gmail.com>2012-05-23 13:33:48 -0400
committerJonathan Clark <jon.h.clark@gmail.com>2012-05-23 13:33:48 -0400
commite70a73b8c365329f7a8cf86ad527b12358752266 (patch)
tree2cac86cc01c31f967416e2b8008b4e95f804b732 /sa-extract
parent2c217893e517eaeb288c70b51816015a3a8a8124 (diff)
Add script to convert from sa-extract's unnamed format to cdec's more readable named format
Diffstat (limited to 'sa-extract')
-rwxr-xr-xsa-extract/sa2cdec.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/sa-extract/sa2cdec.py b/sa-extract/sa2cdec.py
new file mode 100755
index 00000000..55fb19f3
--- /dev/null
+++ b/sa-extract/sa2cdec.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+import sys
+
+featNames = [ line.strip() for line in open(sys.argv[1]) if not line.startswith('#') ]
+
+for line in sys.stdin:
+ try:
+ (lhs, src, tgt, feats, align) = line.strip("\n").split(' ||| ')
+ except:
+ print >>sys.stderr, 'WARNING: No alignments:', line
+ try:
+ (lhs, src, tgt, feats) = line.strip().split(' ||| ')
+ align = ''
+ except:
+ print >>sys.stderr, "ERROR: Malformed line:", line
+ raise
+ featValues = feats.split(' ')
+ namedFeats = ' '.join( name+"="+value for (name, value) in zip(featNames, featValues) )
+ print " ||| ".join( (lhs, src, tgt, namedFeats, align) )