Skip to content

Commit

Permalink
Merge pull request #3 from nsaphra/master
Browse files Browse the repository at this point in the history
Giza formatting fix
  • Loading branch information
proycon committed May 8, 2014
2 parents 087970c + 85c07bd commit da4e731
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions formats/giza.py
Expand Up @@ -106,21 +106,19 @@ def __repr__(self):


def getalignedtarget(self, index):
"""Returns target range only if source index aligns to a single consecutive range of target tokens."""
targetindices = []
target = None
foundindex = -1
for sourceindex, targetindex in self.alignment:
if sourceindex == index:
targetindices.append(targetindex)
if len(targetindices) > 1:
consecutive = True
for i in range(1,len(targetindices)):
if abs(targetindices[i] - targetindices[i-1]) != 1:
consecutive = False
break
if consecutive:
foundindex = (min(targetindices), max(targetindices))
target = ' '.join(self.target[min(targetindices):max(targetindices)+1])
break # not consecutive
foundindex = (min(targetindices), max(targetindices))
target = ' '.join(self.target[min(targetindices):max(targetindices)+1])
elif targetindices:
foundindex = targetindices[0]
target = self.target[foundindex]
Expand All @@ -134,7 +132,7 @@ def __init__(self, filename, encoding= 'utf-8'):
elif filename.split(".")[-1] == "gz":
self.f = gzip.GzipFile(filename,'r')
else:
self.f = io.open(filename,'r',encoding)
self.f = io.open(filename,'r',encoding=encoding)
self.nextlinebuffer = None


Expand Down

0 comments on commit da4e731

Please sign in to comment.