gabriel becker
2 years ago
10 changed files with 56 additions and 13 deletions
@ -1,3 +1,4 @@
|
||||
from .base_click import cli |
||||
from .from_csv import generate_anki |
||||
from .make_config import make_csv_config |
||||
from .from_epub import process_epub |
||||
|
@ -1,3 +1,3 @@
|
||||
from .basic_csv_to_anki import basic_pandas_to_anki |
||||
from .config_tasks import create_config, enhance_config |
||||
from .epub import process_epub |
||||
from . import dictionary |
||||
|
@ -0,0 +1,24 @@
|
||||
from multiprocessing import Pool |
||||
from itertools import repeat |
||||
from typing import Iterable, Optional |
||||
from http.client import RemoteDisconnected as HttpClientRemoteDisconnected |
||||
|
||||
from PyMultiDictionary import MultiDictionary |
||||
|
||||
|
||||
def get_and_process_word_definition(language: str, word: str) -> Optional[str]: |
||||
try: |
||||
dictionary = MultiDictionary() |
||||
definition = dictionary.meaning(lang=language, word=word) |
||||
if len(definition[1]) <= 1: |
||||
return None |
||||
definition = definition[1].split('.')[0] |
||||
except HttpClientRemoteDisconnected: |
||||
return None |
||||
return definition |
||||
|
||||
|
||||
def get_word_definitions_from_dictionary(language: str, word_collection: Iterable[str]) -> Iterable[str]: |
||||
with Pool(7) as p: |
||||
definitions = p.starmap(get_and_process_word_definition, zip(repeat(language), word_collection)) |
||||
return definitions |
@ -1 +1 @@
|
||||
from .process_epub import process_epub |
||||
from . load_epub import generate_corpus_from_epub_file |
||||
|
@ -1,6 +0,0 @@
|
||||
from .load_epub import generate_corpus_from_epub_file |
||||
|
||||
|
||||
def process_epub(input_file, output_file, language, deck_name): |
||||
corpus = generate_corpus_from_epub_file(input_file) |
||||
raise NotImplementedError() |
@ -0,0 +1,24 @@
|
||||
from ankimaker import generator |
||||
|
||||
from ankimaker.tasks import epub |
||||
from ankimaker.tasks import dictionary |
||||
|
||||
|
||||
def create_collection_and_filter_out_on_empty_definitions(words_from_epub, definitions): |
||||
collection = [(words, defi) for words, defi in zip(words_from_epub, definitions) if defi is not None] |
||||
return collection |
||||
|
||||
|
||||
def process_epub(input_file, output_file, language, deck_name): |
||||
words_from_epub = epub.generate_corpus_from_epub_file(input_file) |
||||
definitions = dictionary.get_word_definitions_from_dictionary(language, words_from_epub) |
||||
collection = create_collection_and_filter_out_on_empty_definitions(words_from_epub, definitions) |
||||
generator_engine = generator.QuestionAnswerGenerator() |
||||
|
||||
deck = generator.deck.create_deck(deck_name) |
||||
|
||||
words_from_epub, definitions = map(list, zip(*collection)) |
||||
cards = generator_engine.get_cards(words_from_epub, definitions) |
||||
for card in cards: |
||||
deck.add_note(card) |
||||
generator.deck.save_deck(deck, output_file) |
Loading…
Reference in new issue