import sys
import os

dir = sys.argv[1]

def readTxt(inputfile):
    with open(inputfile, 'r') as fin:
        datas = fin.readlines()
    return datas

srcs = readTxt(os.path.join(dir, "fr.train.spm.src"))
tgts = readTxt(os.path.join(dir, "fr.train.spm.tgt"))

ratios = []
for (src, tgt) in zip(srcs, tgts):
    ratio = len(src.strip().split()) / len(tgt.strip().split())
    ratios.append(ratio)
print("averaged: {:.3f}".format(sum(ratios) / len(ratios)))
