summaryrefslogtreecommitdiff
path: root/sa-extract/sa2cdec.py
blob: 55fb19f3ceb13d7f6215f932063ae789a1ea4955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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) )