Anki add-on: Cloze Generator

Some of the excellent features of Anki include the ability to define multiple cards for a single note and support for cloze tests. Unfortunately cloze tests cannot be added to a non-cloze note type. An example of where such a facility would be useful is someone learning English who wishes to master irregular past tenses (such as 'spring', 'sprang', 'sprung'). They may well have created a custom Verb note type with the English and non-English infinitives, as well as fields for the irregular English tenses and then want to use cloze tests to learn the irregular tenses. I'm trying to learn Russian, and wrote this addin for myself to learn verb aspects pairs, and posted it here as I thought it may help others. On startup the addon adds a Generate cloze submenu to the Tools menu. Every cloze mapping in the addon configuration is listed in the submenu, and selecting it will generated the cloze notes defined by the mapping. To illustrate how to configure the mappings I'll provide the example from my own setup of generating cloze cards for aspect pairs. I have 2 cards types for learning verb aspect pairs: - a card type for learning verbs ("Russian vocabulary - verb") - a cloze card type ("Russian cloze") with cloze deletions for aspect pairs The "Russian vocabulary - verb" card type has the following relevant fields: - Russian - Aspect - Pair - English The "Pair" field holds the verb that is [one of] the verb's aspect pair, and the "Aspect" field denotes what aspect this verb has ("imp" for imperfective verbs, "perf" for perfective verbs). The "Russian cloze" card type has 2 fields: - Text - Note The "Text" field is used for the cloze deletions, and for aspect pair cloze deletions the Note field is populated with the English meaning. The Cloze Generator config to do this is: "Verb Aspects": { "Destination": { "Deck": "Grammar::verbs", "Fields": { "Note": "to {{English}}", "Text": "{{c1::{{Pair}}::imp.}} - {{c2::{{Russian}}::perf.}}" }, "Note": "Russian cloze" }, "Source": "Russian vocabulary - verb", "Where": "perf in {{Aspect}}" } This says to search all verb notes that have an Aspect field value of "perf", and use the Pair and Russian fields to make a card with 2 cloze deletions on it. The "Destination" section describes the cloze note that you are creating - what note type it is, what field values it has, and which deck it is placed in. When specifying what field values it has the fields copied from the source note type are enclosed in the usual Anki {{fieldname}} syntax, and use the field names from the source note type. The "Source" element specifies what note type provides the source data, and the optional "Where" element allows you to select only a subset of those notes. The generated card can have a tag set by adding a "Tags" : "tagname" element to the "Destination" section. So, in my setup, for the "Russian vocabulary - verb" card with the following values: - Russian = взять - Aspect = perf - Pair = брать - English = take The following "Russian cloze" card is generated in the "Grammar::verbs" deck: - Text = {{c1::брать::imp.}} - {{c2::взять::perf.}} - Note = to take As duplicate cards are ignored all I have to do to add a cloze card for the aspect pair after adding a verb card is to select the "Tools > Generate cloze > Verb Aspects" menu item. Some points to note: Anki needs to be restarted in order to display a new mapping in the Generate cloze submenu the addon will not generate duplicate notes, so it can be run multiple times against the same source data the addon will not generate notes with an empty cloze element - allowing the addon to be run against notes where cloze notes should only be generated for some notes the addon does not manage cloze notes once generated (eg. deleting them if no longer required as the source data has been deleted) tags can be defined in the mapping to apply to the generated cloze notes