3
3
import sqlite3
4
4
import sys
5
5
6
+ from generate import get_ipa , safe_get_word_document , get_word_natures
7
+ from utils .scrap import get_word_metadata
8
+ from utils .dataset import get_words , get_custom_words , get_word2ipa
6
9
from utils .dictionary_database import RemedeDatabase
7
10
from utils .sanitize import sanitize_word
8
11
@@ -33,6 +36,19 @@ def getTimeDetails(time_object):
33
36
return hours , minutes , seconds
34
37
35
38
39
+ def add_to_database (word : str ):
40
+ if word in custom_words :
41
+ document = custom_words_json [word ]
42
+ ipa = document ["phoneme" ]
43
+ else :
44
+ ipa = get_ipa (word )
45
+ document = safe_get_word_document (word , ipa )
46
+ elidable , feminine , syllables , min_syllables , max_syllables , nature = get_word_metadata (word , ipa )
47
+ if not nature :
48
+ nature = get_word_natures (document )
49
+ database .insert (word , sanitize_word (word ), ipa , nature , syllables , min_syllables , max_syllables , elidable , feminine , document )
50
+
51
+
36
52
if __name__ == '__main__' :
37
53
before = datetime .datetime .now ()
38
54
@@ -57,29 +73,30 @@ def getTimeDetails(time_object):
57
73
print ("- Ajout des mots à la liste de mots..." )
58
74
add_to_wordlist (words_to_add )
59
75
print ("Fait." )
76
+ print ("- Génération des ressources..." )
77
+ runpy .run_module ('pre_generate_ressources' , run_name = '__main__' )
78
+ print ("Fait." )
79
+
80
+ # Wordlist
81
+ all_words = get_words ()
82
+ # IPA.json
83
+ all_ipa = get_word2ipa ()
84
+ # custom_words.json
85
+ custom_words_json = get_custom_words ()
86
+ custom_words = custom_words_json .keys ()
87
+
60
88
for element in words_to_add :
61
89
word , phoneme = element
62
90
63
91
if not phoneme .startswith ("/" ):
64
92
print (f"Phoneme must be formated like \" /ʁəmɛd/\" , skipping { word } ." )
65
93
continue
66
94
67
- print (f"Ajout du mot \" { word } \" ..." )
68
-
69
- print ("- Construction du document Remède..." )
70
- document = get_word_document (word , phoneme )
71
- print ("Fait." )
72
-
73
- print ("- Insertion du document Remède..." )
74
- database .insert (word , phoneme )
75
- print ("Fait." )
95
+ add_to_database (word )
76
96
77
97
print ("- Sauvegarde de la base de données..." )
78
98
database .save ()
79
99
print ("Fait." )
80
- print ("- Génération des ressources..." )
81
- runpy .run_module ('pre_generate_ressources' , run_name = '__main__' )
82
- print ("Fait." )
83
100
84
101
except Exception as e :
85
102
print (f"Échec. Assurez vous d'avoir bien fourni les arguments nécessaires. \" { e } \" " )
0 commit comments