Skip to content

Commit 7cafada

Browse files
committed
fix: new add_word.py script
1 parent b3c6c94 commit 7cafada

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

scripts/add_word.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import sqlite3
44
import sys
55

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
69
from utils.dictionary_database import RemedeDatabase
710
from utils.sanitize import sanitize_word
811

@@ -33,6 +36,19 @@ def getTimeDetails(time_object):
3336
return hours, minutes, seconds
3437

3538

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+
3652
if __name__ == '__main__':
3753
before = datetime.datetime.now()
3854

@@ -57,29 +73,30 @@ def getTimeDetails(time_object):
5773
print("- Ajout des mots à la liste de mots...")
5874
add_to_wordlist(words_to_add)
5975
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+
6088
for element in words_to_add:
6189
word, phoneme = element
6290

6391
if not phoneme.startswith("/"):
6492
print(f"Phoneme must be formated like \"/ʁəmɛd/\", skipping {word}.")
6593
continue
6694

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)
7696

7797
print("- Sauvegarde de la base de données...")
7898
database.save()
7999
print("Fait.")
80-
print("- Génération des ressources...")
81-
runpy.run_module('pre_generate_ressources', run_name='__main__')
82-
print("Fait.")
83100

84101
except Exception as e:
85102
print(f"Échec. Assurez vous d'avoir bien fourni les arguments nécessaires. \"{e}\"")

0 commit comments

Comments
 (0)