abdnh / anki-incontext

An Anki add-on that shows random example sentences each time you review a vocabulary card
https://ankiweb.net/shared/info/385420176
GNU General Public License v3.0
3 stars 1 forks source link

Fetching sentences from a deck or list of sentences? #1

Open ghost opened 2 years ago

ghost commented 2 years ago

Hey! Such a cool idea :D Maybe it would be useful if one could do this locally, by selecting a sentence list from a file or having it look at your deck and fetch from there? In this case one could support many more languages, I think. Right? Anyway, looking forward to more languages in this!

abdnh commented 2 years ago

Hi!

I've actually added an option to import sentences from files recently: image

The add-on is still experimental, and I'll probably refactor the GUI and move options around if I figure a better way to organize things.

Support for different languages is now done by adding Python files to the providers directory. A minimal ja.py file looks like this, for example:

NAME = "Japanese"
PROVIDERS = []

You can then choose Japanese in the GUI and click "Open Files" to import sentences.

After that, you modify your template as follows:

{{incontext lang=ja:Front}}

Though I've used Japanese as an example, the add-on uses spaces to figure out to which word entry it should add each sentence in the files to, so the "Parse text and import sentences for found words" option won't work for such languages now. I plan to make the parsing function more sophisticated and language-specific in the future. In the meantime, one can add words to the words list using the Add word/Import Words options and then use the "Import sentences for selected word".

Another option is to implement a language-specific function in ja.py (or any language file for that matter) that reads sentences from a local file, parses them according to the language's rules (maybe using some external library). The function can then be added to the PROVIDERS list for the add-on to use it. The tr.py file for example contains a function to fetch sentences from a local file downloaded from Tatoeba.

having it look at your deck and fetch from there?

That would be nice to have! Added to the TODO list.