mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-29 06:52:34 +03:00
ef028446f3
This is not pleasant to read (and much, much less pleasant to write!) but sort of necessary in an open project. Right now it's quite hard to figure out what is licensed how, which doesn't matter much to most people but can suddenly become very important when people want to know what they're being allowed to do. I kept the notices as short as I could. As far as I could see, everything without a clear license notice is LGPL v2.1 or later.
36 lines
965 B
Python
Executable File
36 lines
965 B
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# This file is part of moses. Its use is licensed under the GNU Lesser General
|
|
# Public License version 2.1 or, at your option, any later version.
|
|
|
|
"""Reduce an ngrams file for training nplm to a smaller version of it.
|
|
|
|
The smaller version will have fewer ngrams.
|
|
"""
|
|
|
|
from sys import argv
|
|
|
|
if len(argv) != 5:
|
|
print("Wrong number of args, got: " + str(len(argv) - 1) + " expected 4.")
|
|
print("Usage: reduce_ngrams.py INFILE OUTFILE START_IDX NGRAMS")
|
|
exit()
|
|
|
|
INFILE = open(argv[1], 'r')
|
|
OUTFILE = open(argv[2], 'w')
|
|
START_IDX = int(argv[3])
|
|
NGRAMS = int(argv[4])
|
|
|
|
for line in INFILE:
|
|
line = line.split()
|
|
line = line[START_IDX:START_IDX + NGRAMS]
|
|
linetowrite = ""
|
|
for token in line:
|
|
linetowrite = linetowrite + token + " "
|
|
# Strip final empty space and add newline.
|
|
linetowrite = linetowrite[:-1]
|
|
linetowrite = linetowrite + '\n'
|
|
OUTFILE.write(linetowrite)
|
|
|
|
INFILE.close()
|
|
OUTFILE.close()
|