migaku-official / Migaku-Kanji-Addon

Learn kanji within the context of the vocab in your Anki collection. Comes with a powerful lookup browser.
https://migaku.io
GNU General Public License v3.0
57 stars 12 forks source link

Some heisig primitives cannot be displayed #175

Open MinmoTech opened 1 year ago

MinmoTech commented 1 year ago

These character require a custom font that we can use:

image image

Ideally we would have a design for each of our existing fonts. Example with all fonts: image

MinmoTech commented 1 year ago

image This doesn't have a stroke order diagram

MinmoTech commented 1 year ago

image

MinmoTech commented 1 year ago

image

This one has a very similar kanji: image

MinmoTech commented 1 year ago

image

MinmoTech commented 1 year ago

image

MinmoTech commented 1 year ago

http://rtkelements.blogspot.com/

MinmoTech commented 1 year ago

image

MinmoTech commented 1 year ago

image

mjuhanne commented 1 year ago

@MinmoTech I also could be interested in working with this.

The Migaku Kanji Database Excel sheet lists each primitive as a single Unicode character so to use also non-Unicode primitives we would need a way to address them in the database and then map those into custom font for viewing.

I propose to use brackets to enclose a keyword assigned to the primitive. Example: For character 倍 (double) the primitive list would be '人[muzzle]' instead of '人立口'

I haven't looked yet how the font files are composed and indexed. Do we need a separate custom font file for each new primitive?

mjuhanne commented 1 year ago

@MinmoTech I've made some progress using the great RTK index and copying their list of primitives and associated SVGs, and then filtering out all of those that have Unicode representation. This leaves us a collection of 65 non-Unicode primitives that we have now nice images for.

With few modifications I'm able to now create distinct cards for these missing primitives and reference those from other kanjis that use them. This is possible with the [primitive_name] addressing scheme explained above. If a character has this format, it will be converted to a image link for visual representation.

The SVGs are a bit too small though..

Screenshot 2023-07-15 at 12 04 16

.. and currently show up in wrong color.

Screenshot 2023-07-15 at 11 42 36

I've made a script that modifies kanji.db with external .tsv file to add these missing primitives and then recalculates references from kanjis to primitives. I've manually added few select kanjis (such as for the 'tribe' above), but a lot of manual work has to be done to go through the main list and add all the rest.

I'll need to do some tidying but I'll put the code later into my repository.

mjuhanne commented 1 year ago

Here's the code for testing

MAKE COPY OF kanji.db BEFORE TESTING db_merge_tsv.py !! :) python tools/db_merge_tsv.py addon/kanji-ext.tsv addon/kanji.db

MinmoTech commented 1 year ago

@mjuhanne Sorry for taking so long to respond, this looks pretty great!

I actually started working on fixing this issue myself a while ago, but I was simply copying the Private Use Area code of a custom font into the google sheet, your solution is way better!

While working on it I noticed how large the effort that still needs to go in and couldn't justify the time commitment at the time so the work had kinda stalled again.

This is the font I used in case it helps you out: Pangolin_font für Heisig Primitive.zip (not sure if it's the same one you are using)

Are you on our discord server btw? :) https://discord.gg/JR5NrTTFhF

You can find me on there as "Julius", you can contact me there if you ever want quicker feedback from me about something.

Also do you want to open a PR with your changes? I'd be very interested in getting those merged :grinning:

calculuschild commented 1 year ago

Here's the code for testing

MAKE COPY OF kanji.db BEFORE TESTING db_merge_tsv.py !! :) python tools/db_merge_tsv.py addon/kanji-ext.tsv addon/kanji.db

How would I go about testing this? Are there any good resources on how to build it into an Anki plugin or perhaps a pre-compiled plugin I can install somehow?

mjuhanne commented 1 year ago

Here's the code for testing MAKE COPY OF kanji.db BEFORE TESTING db_merge_tsv.py !! :) python tools/db_merge_tsv.py addon/kanji-ext.tsv addon/kanji.db

How would I go about testing this? Are there any good resources on how to build it into an Anki plugin or perhaps a pre-compiled plugin I can install somehow?

@calculuschild You can just clone my repository and overwrite the 1872210448 directory (in Mac OS it's ~/Library/ApplicationSupport/Anki2/addons21/1872210448) with contents from 'Migaku-Kanji-Addon/addon'.

IMPORTANT! Do make a backup of the 1872210448 and especially its user_files/ directory. Also it's wise to export all your Anki stacks using File | Export.. before testing, just in case something goes horribly wrong :)

calculuschild commented 1 year ago

@mjuhanne Ok, I finally had a chance to download your repository. I backed up the original elsewhere and then overwrote it with yours. Anki goes through a "refreshing cards" step. In all, the cards already look so much cleaner, especially the scrambled primitive references and missing story entries.

Some observations:

image

image

image

mjuhanne commented 1 year ago

@calculuschild Thank you for testing!

Those with existing decks will have a bit nuisance because of the orphan cards (renamed '-'). I would be very hesitant adding code to remove cards from users' decks, so it is just best to Suspend the card whenever one comes across it (there are only a handful of those anyway). It would be possible to implement additional checks for missing cards for the extra primitives in the 'Refresh cards' action, but there's the added complexity. I will think about this.
For the mean time, whenever you see a kanji that references a primitive you haven't got in your deck, just follow the reference link to the aforementioned primitive and click the 'Create recognition/production card' button.

When it comes to the non-Unicode primitives, I don't think KanjiVG database has to stroke order graphic for those. I'll have to research later how to create them. For the other cards, they should work. You aren't seeing this?

Screenshot 2023-08-03 at 22 35 51

You mean the stroke order graphic is broken in EVERY card or just those that use the new primitives?

calculuschild commented 1 year ago

@mjuhanne

...so it is just best to Suspend the card whenever one comes across it (there are only a handful of those anyway).

That's fair.

It would be possible to implement additional checks for missing cards for the extra primitives in the 'Refresh cards' action, but there's the added complexity. I will think about this.

Do you know if the Kanji GOD addon itself has some function to just re-scan for missing cards? I seem to remember if I add new vocab to my vocab deck, Kanji GOD is supposed to detect that and generate new Kanji cards. It just doesn't seem to be happening in this case, or I'm not finding the right button.

You mean the stroke order graphic is broken in EVERY card or just those that use the new primitives?

EVERY card. You can see my screenshot above of the "cottage" card. It doesn't show the stroke order that yours shows. Do I need to install some other dependency?

mjuhanne commented 1 year ago

@calculuschild Ok that is weird, I cannot reproduce your findings.

If you really want to get your hands dirty, you could try the AnkiWebView Inspector to see if there's some weird Javascript error that prevents showing the stroke graphics. The normal version supports inspecting only the card windows, but I've made a patch to enable inspecting also the Lookup window

Screenshot 2023-08-04 at 12 19 05
mjuhanne commented 1 year ago

@calculuschild Hold on, I came across the same problem now. Will investigate.

mjuhanne commented 1 year ago

@calculuschild Ok, found out the culprit. I think you're missing the 'addon/kanjivg' directory and its contents (the actual svg files containing the stroke graphics). I don't know how the installation procedure invokes the command to download the separate kanjivg repository but you can do it manually:

tools/kanjivg_download.sh 
calculuschild commented 1 year ago

@mjuhanne OK, that looks like it was probably the issue; I manually installed using your script, then moved it into the \1872210448 folder since I renamed \addon to overwrite the original extension. Seems the SVGs are being recognized now.

One weird thing; not sure if it matters. In the card browser, there is a weird ]> in the field, see below.

Also, while the cards now show the stroke order on my Android and in the card lookup tool on PC, they don't show up when doing normal study on PC. I assume this is not you but some weird Anki caching issue since Android is working fine.

image

This is honestly really really great. You're doing (Kanji) God's work. Hoping they merge your PR soon.