concordia-server/fast-aligner/get_alignments.py
2019-02-21 14:02:51 +01:00

26 lines
763 B
Python
Executable File

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
with open(sys.argv[1]) as falign_result, open(sys.argv[2]) as src_clean_lem:
for line in src_clean_lem:
src_line_lem = line.strip()
falign_alignment_pairs = falign_result.readline().rstrip().split()
falign_map = {}
for pair in falign_alignment_pairs:
numbers = pair.split('-')
s = int(numbers[0])
t = int(numbers[1])
if not s in falign_map:
falign_map[s] = []
falign_map[s].append(t)
res = []
for i in range(len(src_line_lem.split())):
if i in falign_map:
res.append(falign_map[i])
else:
res.append([])
print(res)