Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/camarm-dev/remede into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
camarm-dev committed Jul 11, 2024
2 parents 3522d0f + 7cafada commit 84e2977
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
41 changes: 29 additions & 12 deletions scripts/add_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import sqlite3
import sys

from generate import get_ipa, safe_get_word_document, get_word_natures
from utils.scrap import get_word_metadata
from utils.dataset import get_words, get_custom_words, get_word2ipa
from utils.dictionary_database import RemedeDatabase
from utils.sanitize import sanitize_word

Expand Down Expand Up @@ -33,6 +36,19 @@ def getTimeDetails(time_object):
return hours, minutes, seconds


def add_to_database(word: str):
if word in custom_words:
document = custom_words_json[word]
ipa = document["phoneme"]
else:
ipa = get_ipa(word)
document = safe_get_word_document(word, ipa)
elidable, feminine, syllables, min_syllables, max_syllables, nature = get_word_metadata(word, ipa)
if not nature:
nature = get_word_natures(document)
database.insert(word, sanitize_word(word), ipa, nature, syllables, min_syllables, max_syllables, elidable, feminine, document)


if __name__ == '__main__':
before = datetime.datetime.now()

Expand All @@ -57,29 +73,30 @@ def getTimeDetails(time_object):
print("- Ajout des mots à la liste de mots...")
add_to_wordlist(words_to_add)
print("Fait.")
print("- Génération des ressources...")
runpy.run_module('pre_generate_ressources', run_name='__main__')
print("Fait.")

# Wordlist
all_words = get_words()
# IPA.json
all_ipa = get_word2ipa()
# custom_words.json
custom_words_json = get_custom_words()
custom_words = custom_words_json.keys()

for element in words_to_add:
word, phoneme = element

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

print(f"Ajout du mot \"{word}\"...")

print("- Construction du document Remède...")
document = get_word_document(word, phoneme)
print("Fait.")

print("- Insertion du document Remède...")
database.insert(word, phoneme)
print("Fait.")
add_to_database(word)

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

except Exception as e:
print(f"Échec. Assurez vous d'avoir bien fourni les arguments nécessaires. \"{e}\"")
Expand Down
2 changes: 2 additions & 0 deletions scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ def getTimeDetails(time_object):
print(f"Resumed at word {all_words[0]}. Continuing generation...\n")

database = RemedeDatabase(sqlite3.connect('data/remede.db'))
database.init_dictionary()

try:
remedize(all_words)
except KeyboardInterrupt:
print("Received exit signal.")

database.save()
after = datetime.datetime.now()
time = after - before
hour, minute, second = getTimeDetails(time)
Expand Down

0 comments on commit 84e2977

Please sign in to comment.