ohare93 / brain-brew

Automated Anki flashcard creation and extraction to/from Csv
The Unlicense
92 stars 5 forks source link

Note Model Required Fields should be generated #9

Closed ohare93 closed 2 months ago

ohare93 commented 4 years ago

Note Models have a req dictionary that states which fields are required to be filled in to generate each Card Template. See here for a full explanation: https://github.com/ankidroid/Anki-Android/wiki/Database-Structure

This is a very long and useless dictionary for the purposes of having a Note Models in source control, and we should be able to just regenerate it when writing to CrowdAnki. Find where and how it is generated in Anki itself, and replicate that logic.

Example Note Model Yaml:

name: LL Noun
id: 3cc64d88-e410-11e9-960e-d8cb8ac9abf0
css: ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color:\
  \ black;\n background-color: white;\n}\n\n.card1,.card3 { background-color: #B60F2D;\
  \ }\n.card5 { background: linear-gradient(90deg, #999999 0%, #B60F2D 20%, #B60F2D\
  \ 80%, #999999 100%); }\n.card6 { background: linear-gradient(90deg, #999999 0%,\
  \ #2E9017 20%, #2E9017 80%, #999999 100%); }\n.card2,.card4 { background-color:\
  \ #2E9017; }\n.card7 { background: linear-gradient(90deg, #B60F2D 49.9%, #2E9017\
  \ 50.1%); }\n\n.nightMode.card1,.nightMode.card3 { background-color: #700; }\n.nightMode.card5\
  \ { background: linear-gradient(90deg, #999999 0%, #700 20%, #700 80%, #999999 100%);\
  \ }\n.nightMode.card6 { background: linear-gradient(90deg, #999999 0%, #250 20%,\
  \ #250 80%, #999999 100%); }\n.nightMode.card2,.nightMode.card4 { background-color:\
  \ #250; }\n.nightMode.card7 { background: linear-gradient(90deg, #700 49.9%, #250\
  \ 50.1%); }\n\n\n.word {\n font-size:1.5em;\n}\n\n.pronunciation{\n color:blue;\n\
  }\n\n.extrainfo{\n color:lightgrey;\n}"
fields:
- name: Word
  font_size: 12
- name: X Word
- name: Y Word
- name: Picture
  font_size: 6
- name: Extra
- name: X Pronunciation (Recording and/or IPA)
- name: Y Pronunciation (Recording and/or IPA)
- name: Plural
- name: Indefinite Plural
- name: Definite Plural
- name: MorphMan_FocusMorph
templates:
- name: X Comprehension
  question_format: "{{#X Word}}\n\t<span class=\"word\">{{text:X Word}}</span>\n{{/X\
    \ Word}}"
  answer_format: "{{#X Word}}\n\t<span class=\"word\">{{X Word}}</span>\n{{/X Word}}\n\
    \n<hr id=answer>\n\n{{Picture}}\n\n{{#X Pronunciation (Recording and/or IPA)}}\n\
    \t<br><span class=\"pronunciation\">{{X Pronunciation (Recording and/or IPA)}}</span>\n\
    {{/X Pronunciation (Recording and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"\
    extrainfo\">{{Extra}}</span>\n{{/Extra}}"
- name: Y Comprehension
  question_format: "{{#Y Word}}\n\t<span class=\"word\">{{text:Y Word}}</span>\n{{/Y\
    \ Word}}"
  answer_format: "{{#Y Word}}\n\t <span class=\"word\">{{Y Word}}</span>\n{{/Y Word}}\n\
    \n<hr id=answer>\n\n{{Picture}}\n\n{{#Y Pronunciation (Recording and/or IPA)}}\n\
    \t<br><span class=\"pronunciation\">{{Y Pronunciation (Recording and/or IPA)}}</span>\n\
    {{/Y Pronunciation (Recording and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"\
    extrainfo\">{{Extra}}</span>\n{{/Extra}}"
- name: X Production
  question_format: "{{#X Word}}{{#Picture}}\n\t{{Picture}}\n{{/Picture}}{{/X Word}}"
  answer_format: "{{FrontSide}}\n\n<hr id=answer>\n\n<span class=\"word\">{{X Word}}</span>\n\
    \n{{#X Pronunciation (Recording and/or IPA)}}\n\t<br><span class=\"pronunciation\"\
    >{{X Pronunciation (Recording and/or IPA)}}</span>\n{{/X Pronunciation (Recording\
    \ and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"extrainfo\">{{Extra}}</span>\n\
    {{/Extra}}"
- name: Y Production
  question_format: "{{#Y Word}}{{#Picture}}\n\t{{Picture}}\n{{/Picture}}{{/Y Word}}"
  answer_format: "{{FrontSide}}\n\n<hr id=answer>\n\n <span class=\"word\">{{Y Word}}</span>\n\
    \n{{#Y Pronunciation (Recording and/or IPA)}}\n\t<br><span class=\"pronunciation\"\
    >{{Y Pronunciation (Recording and/or IPA)}}</span>\n{{/Y Pronunciation (Recording\
    \ and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"extrainfo\">{{Extra}}</span>\n\
    {{/Extra}}"
- name: X Spelling
  question_format: "{{#X Word}}\n\t<br>Spell this word:<br>\n\n\t<span class=\"word\"\
    >{{type:X Word}}</span>\n\n\t<br>{{Picture}}\n{{/X Word}}"
  answer_format: "{{FrontSide}}\n\n{{#X Pronunciation (Recording and/or IPA)}}\n\t\
    <br><span class=\"pronunciation\">{{X Pronunciation (Recording and/or IPA)}}</span>\n\
    {{/X Pronunciation (Recording and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"\
    extrainfo\">{{Extra}}</span>\n{{/Extra}}"
- name: Y Spelling
  question_format: "{{#Y Word}}\n\t<br>Spell this word:<br>\n\n\t<span class=\"word\"\
    >{{type:Y Word}}</span>\n\n\t<br>{{Picture}}\n{{/Y Word}}"
  answer_format: "{{FrontSide}}\n\n{{#Y Pronunciation (Recording and/or IPA)}}\n\t\
    <br><span class=\"pronunciation\">{{Y Pronunciation (Recording and/or IPA)}}</span>\n\
    {{/Y Pronunciation (Recording and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"\
    extrainfo\">{{Extra}}</span>\n{{/Extra}}"
- name: X and Y Production
  question_format: "{{#X Word}}\n{{#Y Word}}\n\t{{Picture}}\n{{/Y Word}}\n{{/X Word}}\n"
  answer_format: "{{FrontSide}}\n\n<hr id=answer>\n\n<div class=\"word\">{{text:X\
    \ Word}}</div>\n<div class=\"word\">{{text:Y Word}}</div>\n\n{{#X Pronunciation\
    \ (Recording and/or IPA)}}\n\t<br><span class=\"pronunciation\">{{X Pronunciation\
    \ (Recording and/or IPA)}}</span>\n{{/X Pronunciation (Recording and/or IPA)}}\n\
    \n{{#Y Pronunciation (Recording and/or IPA)}}\n\t<br><span class=\"pronunciation\"\
    >{{Y Pronunciation (Recording and/or IPA)}}</span>\n{{/Y Pronunciation (Recording\
    \ and/or IPA)}}\n\n<br>\n{{#Extra}}\n\t<br><span class=\"extrainfo\">{{Extra}}</span>\n\
    {{/Extra}}"
tags:
- LL::Grammar::Noun
required_fields_per_template:
- - 0
  - any
  - - 1
- - 1
  - any
  - - 2
- - 2
  - all
  - - 1
    - 3
- - 3
  - all
  - - 2
    - 3
- - 4
  - all
  - - 1
    - 3
- - 5
  - all
  - - 2
    - 3
- - 6
  - all
  - - 1
    - 2
    - 3
ghost commented 2 years ago

I'm currently looking into using brain-brew. My use case does involve only one way of generating decks: source to anki. With that I run into problems, because I can't build the decks without note_models which come from the CrowdAnki exports, correct? Is this the right issue I'am waiting for?

aplaice commented 2 years ago

(Disclaimer: not the author of BrainBrew, but a happy user of it, at AUG.)

I think that you can write the note_model YAML(s) (one per note type), by hand, without it being too onerous, and in particular, I think that you can skip the required_fields_per_template part?

For comparison, see an example BB starter note_model YAML or one of the AUG note_model YAMLs.

You need to list the fields (e.g. Front, Back) and the cards ("templates") that are generated (e.g. Front-to-back or Back-to-front), and write the HTML and CSS for the templates, but you'd need to do the latter anyway, while the former is lightweight "glue".

AFAICT if required_fields_per_template is missing (as it is in the BB starter note models and in AUG) then the req field in the generated CrowdAnki JSON will be empty (unlike would be the case if you created a CrowdAnki JSON export from Anki), but I don't think that's actually an issue at all, at least not for recent Anki versions (≳ 2.1.30?). AFAIR for earlier versions of Anki req being missing might have lead to a delay in the cards being created (but they would get created once you tried reviewing them — i.e. for old Anki versions it might have lead to slight disorientation, but not serious bugs, and it has no adverse effects now).


FWIW I think that this issue could probably be closed (?).

(It might also be worth visiting the question of whether the req field even needs to be in CrowdAnki...)

ohare93 commented 2 years ago

I'm currently looking into using brain-brew. My use case does involve only one way of generating decks: source to anki. With that I run into problems, because I can't build the decks without note_models which come from the CrowdAnki exports, correct? Is this the right issue I'am waiting for?

I would suggest you do a one time run of anki_to_source (the easiest way being though using the Init command) in order to generate the note models and other such required files :+1: then you can always run it however you like, and delete whatever is not necessary for yourself.