forked from miguelemosreverte/MTTT_PyQT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants.py
92 lines (71 loc) · 3.18 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""@brief Contains constants common to all modules of MTTT."""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
#
# Machine Translation Training Tool
# Copyright (C) 2016 Roxana Lafuente <roxana.lafuente@gmail.com>
# Miguel Lemos <miguelemosreverte@gmail.com>
# Paula Estrella <pestrella@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
# Languages we show in the GUI to work with Moses.
languages = ["ar", "cz", "de", "en", "es", "fr", "it" , "pt","ru"]
def adapt_path_for_cygwin(is_windows, directory):
"""@brief Adapts a linux path to a windows one."""
assert len(directory) > 0
adapted_directory = "/cygdrive/"
if is_windows:
if directory[1:3] == ":\\":
adapted_directory += directory[0] + "/" + directory[3:].replace("\\", "/")
else:
adapted_directory = directory.replace("\\", "/")
else:
adapted_directory = directory
return adapted_directory
def is_valid_dir(directory):
"""
@brief Determines if a directory is valid.
@returnReturns True if directory is valid, False otherwise.
"""
is_valid = directory is not None and directory != ""
is_valid = is_valid and os.path.exists(directory)
return is_valid
def is_valid_file(filepath):
"""
@brief Determines if a file is valid.
@returnReturns True if directory is valid, False otherwise.
"""
is_valid = filepath is not None and filepath != ""
is_valid = is_valid and os.path.exists(filepath)
return is_valid
# Config file where info from Moses is saved.
moses_dir_fn = "moses.config"
# Filenames.
train_fn = "training.out"
# Check OS
is_win = os.name == 'nt'
# Moses commands
tokenizer = adapt_path_for_cygwin(is_win, "%s/scripts/tokenizer/tokenizer.perl ")
truecaser_train = adapt_path_for_cygwin(is_win, "%s/scripts/recaser/train-truecaser.perl ")
model = adapt_path_for_cygwin(is_win, "%s/truecase-model.en")
truecaser = adapt_path_for_cygwin(is_win, "%s/scripts/recaser/truecase.perl ")
cleaner = adapt_path_for_cygwin(is_win, "%s/scripts/training/clean-corpus-n.perl ")
lm_train = adapt_path_for_cygwin(is_win, "%s/bin/lmplz ") + "--discount_fallback -o 3 " # TODO: Should be chosen by the user.
blm_train = adapt_path_for_cygwin(is_win, "%s/bin/build_binary ")
tm_train = "nohup nice " + adapt_path_for_cygwin(is_win, "%s/scripts/training/train-model.perl") + " -root-dir train "
test = adapt_path_for_cygwin(is_win, "%s/bin/moses") + " -f "