|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | from config import Directories
|
3 |
| -from file_utils import load_txt_into_set, load_json, open_file_dir_safe |
4 |
| -import re |
| 3 | +from conjugation_generator import ConjugationGenerator |
| 4 | +from file_utils import load_txt_into_set, open_file_dir_safe |
5 | 5 |
|
6 | 6 | infinitives = load_txt_into_set(f"{Directories.processed_data}/infinitive.txt")
|
7 |
| -irregular = load_json(f"{Directories.processed_data}/irregular_verbs.json") |
8 | 7 |
|
9 |
| -imperative_file = open_file_dir_safe(f"{Directories.processed_data}/imperative.txt", 'w') |
10 |
| -third_person_file = open_file_dir_safe(f"{Directories.processed_data}/third_person.txt", 'w') |
11 |
| -gerund_file = open_file_dir_safe(f"{Directories.processed_data}/gerund.txt", 'w') |
12 |
| -past_tense_file = open_file_dir_safe(f"{Directories.processed_data}/past_tense.txt", 'w') |
| 8 | +generator = ConjugationGenerator() |
13 | 9 |
|
14 |
| -vowel = "[aeiouy]" |
15 |
| -consonant = "[b-df-hj-np-tv-z]" |
16 |
| - |
17 |
| -for infinitive in infinitives: |
18 |
| - # imperative |
19 |
| - # I know this is a duplicity but the two files have |
20 |
| - # a slightly different meaning and purpose |
21 |
| - imperative_file.write(infinitive + "\n") |
22 |
| - |
23 |
| - # third person |
24 |
| - if re.search(f"{consonant}y$", infinitive): |
25 |
| - third_person = infinitive[:-1] + "ies" |
26 |
| - elif re.search("(s|z|ch|sh|x)$", infinitive) or infinitive.endswith("o"): |
27 |
| - third_person = infinitive + "es" |
28 |
| - else: |
29 |
| - third_person = infinitive + "s" |
30 |
| - third_person_file.write(third_person + "\n") |
31 |
| - |
32 |
| - # gerund |
33 |
| - if infinitive.endswith("e"): |
34 |
| - gerund = infinitive[:-1] + "ing" |
35 |
| - elif re.search(f"{consonant}{vowel}{consonant}$", infinitive): |
36 |
| - gerund = infinitive + infinitive[-1] + "ing" |
37 |
| - else: |
38 |
| - gerund = infinitive + "ing" |
39 |
| - gerund_file.write(gerund + "\n") |
40 |
| - |
41 |
| - # past tense |
42 |
| - if infinitive in irregular: |
43 |
| - past_tense = irregular[infinitive] |
44 |
| - elif infinitive.endswith("e"): |
45 |
| - past_tense = infinitive + "d" |
46 |
| - elif re.search(f"{consonant}{vowel}{consonant}$", infinitive): |
47 |
| - past_tense = infinitive + infinitive[-1] + "ed" |
48 |
| - elif re.search(f"{consonant}y$", infinitive): |
49 |
| - past_tense = infinitive[:-1] + "ied" |
50 |
| - else: |
51 |
| - past_tense = infinitive + "ed" |
52 |
| - past_tense_file.write(past_tense + "\n") |
53 |
| - |
54 |
| -gerund_exceptions = [ |
55 |
| - "fixing" # generated as fixxing |
56 |
| -] |
57 |
| -past_tense_exceptions = [ |
58 |
| - "fixed" # generated as fixxed |
59 |
| -] |
60 |
| - |
61 |
| -for word in gerund_exceptions: |
62 |
| - gerund_file.write(word + "\n") |
63 |
| - |
64 |
| -for word in past_tense_exceptions: |
65 |
| - past_tense_file.write(word + "\n") |
| 10 | +forms = ['imperative', 'third_person', 'gerund', 'past_tense'] |
| 11 | +for form in forms: |
| 12 | + file = open_file_dir_safe(f"{Directories.processed_data}/{form}.txt", "w") |
| 13 | + with file: |
| 14 | + for word in infinitives: |
| 15 | + method = getattr(generator, form) |
| 16 | + conjugation = method(word) |
| 17 | + file.write(conjugation + "\n") |
0 commit comments