commit 5b0f6e099f4c4d8ea257250e6b13d918df2bbe88 Author: vivekvardhanadepu Date: Tue Jun 8 17:43:57 2021 +0530 added TRAINING_LINES key in config diff --git a/check_config.py b/check_config.py index 5a2d5d4..2455282 100644 --- a/check_config.py +++ b/check_config.py @@ -97,6 +97,10 @@ def check_config(filename='config.toml'): if not yasmet_present: print("yasmet is either not installed or not added to path, see", yasmet_url, '\n') misconfigured = True + + if not isinstance(config['TRAINING_LINES'], int): + print("'"+str(config['TRAINING_LINES'])+"'(TRAINING_LINES)", "is not an integer", '\n') + misconfigured = True if misconfigured: exit(1) diff --git a/config.toml b/config.toml index df7c7a3..6e5bc6c 100644 --- a/config.toml +++ b/config.toml @@ -16,10 +16,13 @@ CORPUS_SL = "europarl-v7.eng-spa.eng" CORPUS_TL = "europarl-v7.eng-spa.spa" # apertium-lex-tools scripts -LEX_TOOLS = "../apertium-lex-tools/scripts" +LEX_TOOLS = "/home/vivek/Documents/FOSS/apertium/apertium-lex-tools/scripts" # fast align build folder -FAST_ALIGN = "coding_challenges/fast_align/build" +FAST_ALIGN = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training/coding_challenges/fast_align/build" # apertium language data -LANG_DATA = "coding_challenges/apertium-eng-spa" +LANG_DATA = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training/coding_challenges/apertium-eng-spa" + +# number of lines to be trained on (do not enclose in quotes) +TRAINING_LINES = 100000 diff --git a/config.toml.example b/config.toml.example index 5949a1f..b9e537c 100644 --- a/config.toml.example +++ b/config.toml.example @@ -23,3 +23,6 @@ FAST_ALIGN = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training # apertium language data LANG_DATA = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training/coding_challenges/apertium-eng-spa" + +# number of lines to be trained on +TRAINING_LINES = 100000 diff --git a/lexical_training.py b/lexical_training.py index cb105b8..aa1a9a7 100644 --- a/lexical_training.py +++ b/lexical_training.py @@ -3,7 +3,7 @@ from check_config import check_config def main(): config = check_config() - print("parsing complete") + print("checking config is done") if __name__ == '__main__': main() \ No newline at end of file diff --git a/tests/check_config_test.py b/tests/check_config_test.py index 08753b6..ca42963 100644 --- a/tests/check_config_test.py +++ b/tests/check_config_test.py @@ -20,6 +20,8 @@ def main(argc, argv): print("---------------------") for key in config: + if key == 'TRAINING_LINES': + continue config[key]+="abc" if os.fork() == 0: @@ -85,12 +87,35 @@ def main(argc, argv): config = parse(config_toml) config_file.close() - print("Test 3 : correct installations") + print("Test 3 : wrong TRAINING_LINES") + print("---------------------") + + for value in ['abc', 1.00, 1e237892, "abc"]: + config['TRAINING_LINES'] = value + if os.fork() == 0: + with open('check_config_test.toml', 'w') as test_file: + test_file.write(dumps(config)) + check_config('check_config_test.toml') + exit(0) + + _, _ = os.wait() + + # Test 4 + config_file = open('config_test.toml', 'r') + config_toml = config_file.read() + config = parse(config_toml) + config_file.close() + + print("Test 4 : correct installations") print("-------------------------------") - with open('check_config_test.toml', 'w') as test_file: - test_file.write(dumps(config)) - check_config('check_config_test.toml') + if os.fork() == 0: + with open('check_config_test.toml', 'w') as test_file: + test_file.write(dumps(config)) + check_config('check_config_test.toml') + exit(0) + + _, _ = os.wait() os.remove('check_config_test.toml') diff --git a/tests/config_test.toml b/tests/config_test.toml index 0d67a99..05fe5c0 100644 --- a/tests/config_test.toml +++ b/tests/config_test.toml @@ -16,10 +16,13 @@ CORPUS_SL = "../europarl-v7.eng-spa.eng" CORPUS_TL = "../europarl-v7.eng-spa.spa" # apertium-lex-tools scripts -LEX_TOOLS = "../../apertium-lex-tools/scripts" +LEX_TOOLS = "/home/vivek/Documents/FOSS/apertium/apertium-lex-tools/scripts" # fast align build folder -FAST_ALIGN = "../coding_challenges/fast_align/build" +FAST_ALIGN = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training/coding_challenges/fast_align/build" # apertium language data -LANG_DATA = "../coding_challenges/apertium-eng-spa" +LANG_DATA = "/home/vivek/Documents/FOSS/apertium/user-friendly-lexical-training/coding_challenges/apertium-eng-spa" + +# number of lines to be trained on +TRAINING_LINES = 100000