Ajatt-Tools / anki.koplugin

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.
49 stars 6 forks source link

Difficulty with multi definition extension #17

Closed ccos89 closed 6 months ago

ccos89 commented 7 months ago

I’ve got the program up and running and it works great, so thank you! When i mine I like to put a lot of definitions on my cards, like three monolingual dictionaries and one bilingual. I’ve gotten the multi-definition extension to run and edited the lua script so that I created “Definition 2,” “Definition 3,” and so on fields on my note type in anki and have each dictionary mapped to send to a particular field in the lua script.

However, when I actually use the program, instead of getting definitions from all of or most of the six custom dictionaries I have installed, I am only getting one to two definitions per card.

I think this is due to the part of the code where there is deconfliction of kana? When I am in koreader and do the lookup I get results for like five dictionaries but they aren’t sending to the card so I’m guessing it must be due to the deconfliction and formatting between dictionaries.

I get why the deconfliction exists but I’d rather get superfluous extra results I can edit out of my card later rather than getting shorted definitions from my other dictionaries. Could you advise if this is an issue I could remedy by commenting out a certain portion of the extension code, or changing something in it so that all the dictionary results that surface in koreader actually get sent to my card?

Thank you!

nairyosangha commented 7 months ago

There's an if/else check in there which indeed checks the kana of the words to know whether dictionary entries actually match the ones you looked up, you could just remove that if/else, and run the code inside always

https://github.com/Ajatt-Tools/anki.koplugin/blob/master/extensions/EXT_multi_def.lua#L43-L55

nairyosangha commented 7 months ago

Another thing you could do is update the dictwrapper.lua file so it actually can parse the kana reading(s) from your dict, if they are there.

https://github.com/Ajatt-Tools/anki.koplugin/blob/1cc0d36c318b9931e1f7157ff8aad9ca453e6e6a/langsupport/ja/dictwrapper.lua#L14

This table contains regexes for dictionaries so it knows how to parse the kana reading. If it's not listed there it falls back on the one listed a bit higher: https://github.com/Ajatt-Tools/anki.koplugin/blob/1cc0d36c318b9931e1f7157ff8aad9ca453e6e6a/langsupport/ja/dictwrapper.lua#L8

This one runs on the headword in the dict, which the custom JMdict one parses it from the actual definition itself.

This works out pretty well for me, usually the kana is in the headword: (So for the example above you would get all 7 definitions on your card without the kana matching)

[~]$ sdcv 罵る
Found 8 items, similar to 罵る.
0)スーパー大辞林 3.0-->ののしる【罵る】
1)スーパー大辞林 3.0-->のる【罵る】
2)明鏡国語辞典 第一版-->ののしる【罵る】
3)広辞苑 第六版-->ののしる【罵る】
4)広辞苑 第六版-->のる【罵る】
5)広辞苑 第六版-->める【罵る】
6)新明解国語辞典 第五版-->ののしる【罵る】
7)JMdict Rev. 1.9-->罵る

But this of course won't be foolproof, it just happens to work for me

ccos89 commented 6 months ago

Thank you, your comments helped me figure it out! Have my cards set up with several definitions now.