Back

heisigify.py - Add Heisig info to Anki deck

#1
Hello,

I finished Heisig a while ago and have been doing Core6k sorted since. Sometimes while doing Core I still felt unsure about certain kanji, especially distinguishing between multiple ones with the same big primitive (確、権、観 etc). So I thought it would be nice to have the keyword of the kanji easily accessible while reviewing, to reinforce the link between character and story if needed (I built ON mnemonics on top of the Heisig story that I already had. Extremely effective and fast.)

So, I've finally decided to write the software to do so, here's a tiny script called heisigify.py. It takes a Heisig deck and any arbitrary deck and adds info about the kanji.
Example:

Deck TARGET <Eg. Core2k Sorted Japanese Vocabulary>:
[Card 1]
Field Vocab-Kanji: 生命
Field Kanji-Info: (empty)

Deck HEISIG <Eg. Heisig's Remembering the Kanji>:
[Card 1]
Field Kanji: 生
Field Keyword: Life
[Card 2]
Field Kanji: 命
Field Keyword: Fate

After running the script, in deck TARGET, card 1 becomes:
[Card 1]
Field Vocab-Kanji: 生命
Field Kanji-Info: 生: Life[NEWLINE]命: Fate[NEWLINE]

You can then add the field {{ Kanji-Info }} to your deck model wherever you see fit.

Disclaimer:
PLEASE DO A BACKUP AS INSTRUCTED. This software comes with absolutely no guarantee of correct functionality or preservation of data. It has only suffered very limited testing. It, basically, 'worked for me'. DO A REAL BACKUP OF YOUR DECKS, DO NOT COUNT ON THE ONLINE SYNC FOR THE BACKUP - YOU MIGHT ACCIDENTALLY SYNC A BROKEN DECK AND IT WILL NOT BE RECOVERABLE.

Instructions:
0) Install Python; add it to your system path so you can run python.exe from any folder
1) Make a backup copy of your TARGET deck from %USERFOLDER%\My Documents\Anki\. DO NOT COUNT ON THE ONLINE SYNC. MAKE A REAL COPY SOMEWHERE ELSE ON YOUR HARD DRIVE.
2) In anki, add a field called 'Kanji-Info' in your desired model in the TARGET deck.
2.1) Take note of the name of the field which contains your vocab. The program assumes it to be Vocab-Kanji. If it's different, remember this name as VOCABFIELD.
3) Make a folder wherever you want on your computer, let's say WORKDIR. Download heisigify.py to WORKDIR. Copy your TARGET deck and your HEISIG deck to WORKDIR.
4) Open a command prompt in WORKDIR. On Windows, shift+rightclick>Open Command Window Here
4)
Type python heisigify.py NAME-OF-TARGET-DECK.anki NAME-OF-HEISIG-DECK.anki

If your vocab field is not called 'Vocab-Kanji', use this syntax instead:
python heisigify.py --vocab-field VOCABFIELD NAME-OF-TARGET-DECK.anki NAME-OF-HEISIG-DECK.anki

The system assumes that in the HEISIG deck, the fields are called Kanji and Keyword respectively, and that you have already created a field called Kanji-Info in your TARGET deck. If any of these are non-default, you can configure them using additional parameters. Use python heisigify.py --help for more info.
5) Wait a bit. The deck should be ready soon. Copy the resulting deck back to Anki's folder. DON'T FORGET TO MAKE A BACKUP.

You should now have the additional kanji info in the Kanji-Info field.

I hope this helps someone. Sorry if there are any bugs. I just made it for myself and thought to post it back. I will try to keep it working.





I can't seem to attach a file to this post. Here is the source code, just copy and paste into a text file, and save as heisigify.py. Use the Download button, do not copy paste directly from the browser to avoid the line numbers. http://pastebin.com/nXSAjUaA
Reply
#2
Nice build Smile If I were you, I would perhaps port this to the Anki plugin API, since the vast majority of people are very reluctant to get to grips with terminals or command prompt, and you would have a far wider audience!
Reply
#3
Actually there is already an anki plugin that adds the heisig keywords. I think it was called Kanji Info or something like that.
Reply
May 16 - 30 : Pretty Big Deal: Save 31% on all Premium Subscriptions! - Sign up here
JapanesePod101
#4
Ah. Sorry avelicu.

Edit: However there probably isn't one for Anki 2 yet (open for correction)
Edited: 2012-08-02, 4:22 pm
Reply
#5
fyi: This tool doesn't add fields to the deck, but brianobush made an anki plugin called RTKize which displays the RTK keywords if you hover over the kanji. I don't know if it will work with anki2.

Language learners are indebted to all you generous programming wizards. Thanks.
Reply
#6
Thora Wrote:fyi: This tool doesn't add fields to the deck, but brianobush made an anki plugin called RTKize which displays the RTK keywords if you hover over the kanji. I don't know if it will work with anki2.

Language learners are indebted to all you generous programming wizards. Thanks.
I was wondering if RTKize has the option to reflect the 6th edition order? If not the order, at least have the included 196 new kanji approved by the government in 2010 as “general-use” kanji.

This seems like a great plugin ^_^
Reply
#7
So, following up a few months later Smile..

A guy named Ian Worthington contacted me by email to ask me why this script isn't working in Anki 2.0.. and I just told him that it wasn't written for anki 2.0. So he said thanks and two days later he came up with a plugin written specifically for that which does this and a bit more.

He said forum registrations are closed so he can't post, and asked me to share his link.

Please check out his plugin here https://ankiweb.net/shared/info/1139060204

Isn't that awesome ^^?
Reply
#8
For registration click here: http://kanji.koohii.com/account/create
Reply
#9
delta Wrote:For registration click here: http://kanji.koohii.com/account/create
That's an account for the SRS, not for the forum. Forum registrations are still closed, see Fabrice's blog post on the news page: http://kanji.koohii.com/
Reply
#10
Code:
python heisigfy.py --vocab-field Expression JpcorePLUS.anki KanjiDMGRORDplusULTKANJD.anki
python heisigfy.py --vocab-field Expression JpcorePLUS.apkg KanjiDMGRORDplusULTKANJD.apkg

I've tried both of these but it gives me an error

Code:
Traceback <most recent call last>:
   File "heisigfy.py", line 52, in <module>
      targetcur.execute<"SELECT id FROM fieldModels WHERE name=?", <argsvocabfield,>>
sqlite3.DatabaseError: file is encrypted or is not a database

Did I use the vocab field argument correctly? or does it have to do with the newer format for decks?
-----------
Related: How about this (http://forum.koohii.com/thread-3626.html), does it still work? Does anyone have a backup if it does?
I could use the Kanji Info plugin but the thing I can't carry it over to my mobile devices :/
Edited: 2015-12-26, 9:28 am
Reply
#11
finally! was about to have to code this myself. The 2.0 plugin doesn't exist anymore sadly though.
Edited: 2015-12-26, 2:13 pm
Reply
#12
I made plugin like this for my personal use, feel free to grab it.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip

Just drop the extracted file in your anki plugin folder and change following lines to fit your needs:

srcFields = ['Expression'] --> field(s) where your Japanese word is
dstFields = ['Keyword'] --> field(s) for RTK keywords to be inserted
rtkModel = 'Heisigs RTK 6th Best' --> name of the model of the RTK deck you want your keywords to be taken from
rtkKanjiField = 'kanji' --> field in RTK model containing the kanji
rtkKeywordField = 'keyword' --> field int RTK model containing the keyword

It works like the Japanese support plugin without the bulk mode. When you leave the Expression field, the Keyword field will be filled with keyword(s).

I didn't add bulk mode because I did not need it yet.
Edited: 2015-12-26, 4:03 pm
Reply
#13
(2015-12-26, 4:02 pm)Robik Wrote: I made plugin like this for my personal use, feel free to grab it.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip

Just drop the extracted file in your anki plugin folder and change following lines to fit your needs:

srcFields = ['Expression'] --> field(s) where your Japanese word is
dstFields = ['Keyword'] --> field(s) for RTK keywords to be inserted
rtkModel = 'Heisigs RTK 6th Best' --> name of the model of the RTK deck you want your keywords to be taken from
rtkKanjiField = 'kanji' --> field in RTK model containing the kanji
rtkKeywordField = 'keyword' --> field int RTK model containing the keyword

It works like the Japanese support plugin without the bulk mode. When you leave the Expression field, the Keyword field will be filled with keyword(s).

I didn't add bulk mode because I did not need it yet.
so the only way to use this would be to go through each field manually?
Edited: 2015-12-27, 7:09 pm
Reply
#14
(2015-12-27, 7:08 pm)xtreme1 Wrote:
(2015-12-26, 4:02 pm)Robik Wrote: I made plugin like this for my personal use...

so the only way to use this would be to go through each field manually?

Yes, I am adding words to my own deck right now, so it is not a big deal. For existing decks, missing bulk mode would be an issue though.

If you are interested, I might as well add the bulk mode, I will need it sooner or later anyway.
Reply
#15
(2015-12-28, 12:58 am)Robik Wrote:
(2015-12-27, 7:08 pm)xtreme1 Wrote:
(2015-12-26, 4:02 pm)Robik Wrote: I made plugin like this for my personal use...

so the only way to use this would be to go through each field manually?

Yes, I am adding words to my own deck right now, so it is not a big deal. For existing decks, missing bulk mode would be an issue though.

If you are interested, I might as well add the bulk mode, I will need it sooner or later anyway.

Very interested. This is what I've been looking for, but I'm using a the core decks, so obviously need the bulk solution.
Reply
#16
(2015-12-28, 1:17 am)xtreme1 Wrote:
(2015-12-28, 12:58 am)Robik Wrote:
(2015-12-27, 7:08 pm)xtreme1 Wrote:
(2015-12-26, 4:02 pm)Robik Wrote: I made plugin like this for my personal use...

so the only way to use this would be to go through each field manually?

Yes, I am adding words to my own deck right now, so it is not a big deal. For existing decks, missing bulk mode would be an issue though.

If you are interested, I might as well add the bulk mode, I will need it sooner or later anyway.

Very interested. This is what I've been looking for, but I'm using a the core decks, so obviously need the bulk solution.

Here you go.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip

Bulk mode works like in Japanese support plugin (read as it is ugly)

1) go to ANKI Browser
2) choose the deck
3) select cards, either via Shift+arrows or Ctrl+A for all cards
4) click on Edit->Bulk-add RTK Keywords in menu
5) patiently wait... there is no progress bar or anything fancy like that, don't shoot the app down just because Windows says that app is not responding

For testing purposes, I generated keywords for Nayr's 5k deck and it took like 20 minutes. Granted, it went through 5k sentences, not just words.

You might want to do it in smaller chunks than entire deck. At least to check if it works fine (fields are correctly set in plugin, etc.) before you run it for the rest of cards.
Reply
#17
(2015-12-28, 4:40 am)Robik Wrote:
(2015-12-28, 1:17 am)xtreme1 Wrote:
(2015-12-28, 12:58 am)Robik Wrote:
(2015-12-27, 7:08 pm)xtreme1 Wrote:
(2015-12-26, 4:02 pm)Robik Wrote: I made plugin like this for my personal use...

so the only way to use this would be to go through each field manually?

Yes, I am adding words to my own deck right now, so it is not a big deal. For existing decks, missing bulk mode would be an issue though.

If you are interested, I might as well add the bulk mode, I will need it sooner or later anyway.

Very interested. This is what I've been looking for, but I'm using a the core decks, so obviously need the bulk solution.

Here you go.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip

Bulk mode works like in Japanese support plugin (read as it is ugly)

1) go to ANKI Browser
2) choose the deck
3) select cards, either via Shift+arrows or Ctrl+A for all cards
4) click on Edit->Bulk-add RTK Keywords in menu
5) patiently wait... there is no progress bar or anything fancy like that, don't shoot the app down just because Windows says that app is not responding

For testing purposes, I generated keywords for Nayr's 5k deck and it took like 20 minutes. Granted, it went through 5k sentences, not just words.

You might want to do it in smaller chunks than entire deck. At least to check if it works fine (fields are correctly set in plugin, etc.) before you run it for the rest of cards.

This works perfect. Thanks so much, ran on a couple and am running on the full core 10k batch now. I'll report back when it's done and I use it a bit.

EDIT:
Yup this is the real deal. Exactly what I was looking for. It took over 3 hours to do my core 10k deck. It did run pretty slow as I had to let it run overnight. My heisig deck is 3000 cards so maybe it ran slower than yours? I've got a pretty decent overclocked gaming build so my PC definitely wasn't the issue.
Edited: 2015-12-29, 9:04 pm
Reply
#18
Thanks for the bulk-add feature, love it.
Reply
#19
Glad you found it useful.

Performance is bad because there are like zero optimizations, not even caching for already found keywords. Your computer is certainly not at fault here.

Still, you pretty much run the batch only once per a deck, so I think it is tolerable.
Reply
#20
Caches all keywords the first time you open the browser:

<See Robik's next post for a better version>

(Also removed the check for 'japanese' in the model name)

Takes less than a second for my 3316-word deck (keywords found for 2711 notes).
Edited: 2015-12-31, 7:39 am
Reply
#21
(2015-12-31, 6:53 am)Vempele Wrote: Caches all keywords the first time you open the browser:

https://www.dropbox.com/s/nl916fz58fcluav/rtkkw.py?dl=1

(Also removed the check for 'japanese' in the model name)

Takes less than a second for my 3316-word deck (keywords found for 2711 notes).

Thanks!

Looks like you are less lazy and / or less patient than me. Smile

I tried your version and it works well. I reverted the call of getKeywords instead of getKeywordsFast in onFocusLost though, because you can add a card without ever opening the ANKI Browser, and speed is not an issue there anyway.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip
Reply
#22
(2015-12-31, 7:38 am)Robik Wrote:
(2015-12-31, 6:53 am)Vempele Wrote: Caches all keywords the first time you open the browser:

https://www.dropbox.com/s/nl916fz58fcluav/rtkkw.py?dl=1

(Also removed the check for 'japanese' in the model name)

Takes less than a second for my 3316-word deck (keywords found for 2711 notes).

Thanks!

Looks like you are less lazy and / or less patient than me. Smile

I tried your version and it works well. I reverted the call of getKeywords instead of getKeywordsFast in onFocusLost though, because you can add a card without ever opening the ANKI Browser, and speed is not an issue there anyway.

https://dl.dropboxusercontent.com/u/18187861/rtkkw.zip

Awesome. Do you plan to put this on the anki plugin site?
Reply
#23
Yeah, I probably will, even though I didn't like their deck purge...
Reply
#24
(2016-01-01, 3:57 am)Robik Wrote: Yeah, I probably will, even though I didn't like their deck purge...

ha, who did? Sadly its still the best option out there and this would give your work a lot more publicity. It's difficult to dig up these old forum posts.
Reply