Plugin for Anki to help with learning Japanese: Syncs information between kanji decks and vocabulary decks.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sync_fields_files
license.txt
readme.md
sync_fields.py

readme.md

Syncing fields between Anki notes.

Overview over my other Anki add-ons

Plugin for Anki, a spaced repetition flashcard program. Some basics: Anki manual.

This Addon requires substantial configuration/adaptation to work for you. Rudimentary knowledge of python will be helpful. Note that the target fields of the target notes will be overwritten, so please be careful!

Use case

This plugin was designed for the following scenario: When learning Japanese, one usually deals with at least two different kinds of notes/decks:

  1. One for the Chinese characters (Kanji), containing information such as meaning, reading (pronounciation) and mnemotics for each of them
  2. One for vocabulary words which are written with Kana (syllable symbols) Kanji (a word can be written with none, or more than one Kanji, see wiki: Japanese writing system)

This addon exchanges information between both sets of notes:

  1. Kanji → Vocabulary: Adds information about the kanji that are used in the writing of the word to a new field of the vocabulary note
  2. Vocabulary → Kanji: Adds exampless of (already learned) words that use this kanji in its writing to a new field of the kanji note

Implemented example

  1. Kanji → Vocabulary: The word 不思議, read ふしぎ (fushigi) is written with three kanji , , and . All three kanji are found in the deck for kanji readings, and mnemotics for the onyomi of , and were found. Those were written to the field in row O by this plugin (prefixed with for Onyomi, 音読み). The examples in the X row are generated by Anki's Japanese plugin.

    kanji2vocab_cropped

  2. Vocabylary → Kanji. My reading card of the kanji . First of all this was one of the notes whose information was transferred to the note 不思議 (the mnemotic for its reading was copied). In my vocabulary decks several already learned words with this kanji were found, e.g. 会議. These were written to the field in the row X by this plugin. The last symbol in square brackets (e.g. [本]) stands for the vocabulary deck where the words were found.

    vocab2kanji_cropped

Code overview

This project has the following structure:

├── sync_fields_files
│   ├── __init__.py         <-- empty (so that this becomes a module)
│   ├── run.py              <-- builds the two Sync objects and 
│   │                           connects them to Anki via hooks
│   ├── sync.py             <-- defines Sync base class
│   ├── example_sync.py     <-- Defines subclass of Sync to sync vocabulary → kanji
│   ├── reading_sync.py     <-- Defines subclass of Sync to sync kanji → vocabulary
│   ├── util.py             <-- useful functions
│   └── log.py              <-- sets up log
└── sync_fields.py          <-- loads run

The top level file sync_fields.py loads the file run.py, which builds an object of type ExampleSync and ReadingSync and connects them to Anki via hooks. Both classes are subclasses of the class Sync, defined in sync.py. The class Sync also contains the database that temporarily stores all information that is nescessary for the sync.

Almost all of the interesting code is already implemented in the Sync class, the subclasses only

  1. Fill in all the parameters (which decks/notes are to be synced to which decks/notes) etc.
  2. Implement the function format_target_field_content, which formats the string that is written to the target field of a target note, based on the database entries that correspond that note's kanji's.

Debugging

This plugin will always save a log sync_fields.log, which should be located in this plugin's directory (sync_fields_files).

There is also a switch dump_database_after_full_loop = False in log.py. If set to True, the full database will be dumped as a string to the log file after Sync.loop_source_notes was called (i.e. after a full loop over all source notes was performed). This may however not perform well (which is why it is disabled by default).

License

The contents of this repository are licensed under the AGPL3 license (to be compatible with the license of Anki and its addons as detailed here).