Giter Club home page Giter Club logo

japanese's Introduction

AJT Japanese

Rate on AnkiWeb Chat Channel Patreon GitHub

The purpose of this add-on is to automatically generate and bulk-generate furigana readings. To do its job, the add-on relies on mecab_controller. Additionally, the add-on allows you to look up Japanese pitch accents of a particular expression and add them to your cards.

Furigana Pitch accent
demo demo

For example, if you have fields named VocabKanji, VocabFurigana and VocabPitchPattern on your notes, the lookups will be performed on the VocabKanji field, furigana will be added to the VocabFurigana field, and the accents will be added to the VocabPitchPattern field. To generate readings or accents, focus in the VocabKanji field and press "Tab" or switch focus away from the field.

You can change field names or add more source and destination fields in the config.

Features

  • Furigana. After you type in a word or phrase into the SentKanji or VocabKanji fields and hit Tab, Anki will automatically generate furigana for you and place it in SentFurigana and VocabFurigana fields respectfully. Field names can be configured in settings.
  • Furigana when a note is added. Automatic furigana generation when a new note gets created with AnkiConnect.
  • Furigana from selection. You can convert any selected text to furigana by clicking Furigana for selection in the context menu while using the note editor.
  • Bulk-add. To add furigana to multiple cards in bulk, open the Anki Browser and press "Edit" > "Bulk-add furigana".
  • Toolbar button. You can replace the content of any selected field with furigana by pressing on the toolbar.
  • Compound words properly split. Words like 取って置き or 言い方 produce correct furigana, unlike the previous add-on.

Installation

Install from AnkiWeb, or manually with git:

git clone 'https://github.com/Ajatt-Tools/Japanese.git' ~/.local/share/Anki2/addons21/ajt_japanese

Configuration

To configure the add-on, open the Anki and select "AJT" > "Japanese Options...".

To edit the config file, open the Anki Add-on Menu via "Tools" > "Add-ons" and select "AJT Japanese". Then click the "Config" button on the right-side of the screen.

Caveats

Mecab is not perfect and sometimes generates incorrect readings. There's nothing that can be done about it in a big picture, so make sure you check the generated text and adjust it if necessary.

The add-on can perform additional dictionary lookups independently of Mecab and add multiple furigana readings for one word. This may help you notice words with multiple readings and edit your card to learn the right one.

Usage

Note: It is preferable to use a compatible Note Type with this addon. Our recommended example deck contains Note Types for Japanese, Japanese fonts and the helpful templates to properly show the generated kanji readings.

When adding cards with AnkiConnect, pronunciations and readings are automatically looked-up and added to the cards. When adding cards manually, fill the VocabKanji field and press "Tab" to trigger generation.

There's a context menu item. Select the expression you would like to look up, then right-click and choose "NHK pitch accent lookup". Alternatively, go to "Tools" > "NHK pitch accent lookup".

When using the Anki Browser, you can mass-generate pitch accents and readings in bulk. To do this, select several notes first, and then choose "Edit" > "AJT: Bulk-generate". By default, the "bulk generate" feature will not overwrite the destination fields if they are already filled, but you can change this by setting overwrite readings on per-profie basis.

If the add-on can't find any pitch accent data for the word spelled in kanji, it tries searching using the kana reading of the word. This behavior can be toggled off in settings.

If the add-on detects furigana reading in the source field, it will add pitch accents for the specified reading and skip other readings if they're present in the pitch accent database.

Pitch accent, what is that?

For more information on the Japanese pitch accent, I would like to refer you to http://en.wikipedia.org/wiki/Japanese_pitch_accent.

In short, the following notations can be found:

  • Overline: Indicates "High" pitch (see "Binary pitch" in Wikipedia article).
  • Downfall arrow: usually means stressing the mora/syllable before.
  • Red circle mark: Nasal pronunciation、e.g. would be a nasal .
  • Blue color: barely pronounced at all.

For example, a blue would be closer to h than hi. Likewise, a blue would be more like a k than ku.

I can't speak for someone else, but for me, just knowing about the pitch accent and how it might affect the meaning has helped me a great deal. There are some tricky words like はし and じどう, where different pronunciations have wildly varying meanings. Aside from that, knowing about these rules might help you avoid speaking with a distinct foreign accent.

Pitch accent data

This add-on uses two databases to generate pronunciations from:

  1. NHK data from NHK日本語発音アクセント辞典.
  2. Kanjium data. The repository can be found here.

The two databases produce 229295 entries total.

Acknowledgements

Some code of this add-on is based off of:

japanese's People

Contributors

homocomputeris avatar javdejong avatar jlloyola avatar maschmi avatar nairyosangha avatar naitreey avatar tatsumoto-ren avatar tomtung avatar weirdalsuperfan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

japanese's Issues

Pitch CSS Style breaks after 9/25/2023 update

The settings that I was using for the Pitch CSS Style no longer works after the 09/25/2023 update. Did something change that I need to update my CSS style for? Below is an example:

In Config:
"styles": {
"ꜜ": "<span class="downstep"><span class="downstep-inner">ꜜ",
"class="overline"": "style="text-decoration:overline;" class="pitchoverline""
}

Word: 相違[そうい]

Before: ソーイ
After: ソーイ

As you can see I am no longer getting the class to be included when the Pitch CSS is generated. This causes issue for my card type (JPMN), as it relied on having that class to properly determine how to display things.

Undo button doesn't undo

In the browser, if you use the 再 or 振 hotkeys it and then hit the undo it will not undo. This can result in lost data or manual corrections to long definitions of words.

The request would be to use the standard undo mechanism used in anki and other add-ons to put things back to the state before one of these buttons was pressed.

Don't forget to provide:

  1. OS name
    win

  2. OS version
    11

  3. Anki version
    image

  4. Logs

  5. Screenshots, if applicable

Multiple furigana options generated: select only one and selecting the correct reading

image

Instead of generating
術[じゅつ] 式[しき]

The addon generates
術[じゅつ, すべ] 式[しき]

  1. Is it possible to only ever generate one reading? I've been noticing sometimes the tool will generate many readings, which can throw off the spacing inside of anki, as the furigana get's too long. I get that sometimes multiple readings are appropriate and the tool isn't aware of the context and which should be used, but I would still like a way to pick just the first one even if it's inaccurate (like the standard Japanese add-on does).

Ideal spacing
image
AJT Spacing:
image
image

  1. Suggestion: Given how often I see the tool generating the wrong furigana, like 術[じゅつ, すべ] 式[しき], I'm wondering if it would be worth-while to just have a list of words and their reading in the tool, that's ordered by frequency. I did something similar in my Kindle add-on. I get that it's not elegent to have a giant list of words and readings read into the add-on from a text file, but it's been far more accurate than even mecab alone in my experience.

AJT Furigana won't load and displays error upon opening Anki

Just upgraded the AJT Furigana plugin. Restarted Anki, and immediately received two pop-up error windows. Happens each time I open the program.

-Windows 10 x64 Pro
-Anki version 2.1.54

Attached is a screenshot of the two pop-ups I get as soon as the program loads.
image

Issue when i press the "add definition" button in the card browser

  1. OS name: Linux mint
  2. OS version: 21.3 Cinnamon
  3. Anki version: 24.06.2, installed from script. I also encountered the problem in older versions of anki, both flatpak and script.
    When i press the "add definition" button, i get this error: "Connection Error". I have it set up correctly in the settings, as seen in the image
    image
    image

ankiweb version of AJT Japanese cannot generate fields

On the latest version of Anki (24.06.3) and using the latest version of the add-on retrieved from AnkiWeb, the addon fails to generate furigana fields, search for audio, etc. Using Arch Linux 6.9.7-arch-1-1.

Steps to reproduce:

  1. Create a flashcard (I am using the "Japanese sentences" template)
  2. Fill the "VocabKanji" field with a word
  3. Upon attempting to generate furigana (Alt+;), etc., the add-on will stop working.

Log:

Anki 24.06.3 (a5c90890) (src) (ao)
Python 3.12.4 Qt 6.7.2 PyQt 6.7.0
Platform: Linux-6.9.7-arch1-1-x86_64-with-glibc2.39

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/aqt/webview.py", line 637, in handler
    cb(val)
  File "/usr/lib/python3.12/site-packages/aqt/editor.py", line 634, in <lambda>
    self.web.evalWithCallback("saveNow(%d)" % keepFocus, lambda res: callback())
                                                                     ^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/editor_toolbar.py", line 80, in decorator
    func(editor)
  File "/home/.../.local/share/Anki2/addons21/1344485230/editor_toolbar.py", line 155, in <lambda>
    ).run()
      ^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/tasks.py", line 170, in run
    changed = self._do_task(task, aud_mgr=session) or changed
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/tasks.py", line 185, in _do_task
    ).run(
      ^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/tasks.py", line 69, in run
    out_text = self._generate_text(src_text)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/tasks.py", line 96, in _generate_text
    search_results = self._aud_src_mgr.search_audio(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/audio.py", line 138, in search_audio
    hits[src_text].extend(self._search_word_variants(src_text))
  File "/home/.../.local/share/Anki2/addons21/1344485230/audio.py", line 197, in _search_word_variants
    yield from self.search_word(src_text)
  File "/home/.../.local/share/Anki2/addons21/1344485230/audio_manager/source_manager.py", line 136, in search_word
    yield self._resolve_file(self._audio_sources[file.source_name], file)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/audio_manager/source_manager.py", line 176, in _resolve_file
    url=source.join(source.media_dir, file.file_name),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.local/share/Anki2/addons21/1344485230/audio_manager/audio_source.py", line 61, in join
    return "/".join(*args)
           ^^^^^^^^^^^^^^^
TypeError: str.join() takes exactly one argument (2 given)

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AJT Japanese ['1344485230', 2024-07-01T19:45, 'None', '']

===IDs of active AnkiWeb add-ons===
1344485230

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AJT Card Management ['1021636467', 2024-03-15T20:51, 'None', '']
AJT Flexible Grading ['1715096333', 2024-06-08T12:08, 'None', '']
AJT Media Converter ['1151815987', 2024-06-29T06:15, 'None', mod]
Advanced Browser ['874215009', 2023-10-21T09:34, 'None', '']
AnkiConnect ['2055492159', 2024-06-17T21:37, 'None', '']
Review Heatmap ['1771074083', 2022-06-29T20:43, 'None', '']
True Retention ['613684242', 2017-11-19T14:43, 'None', '']

As the log shows above I have disabled all other add-ons. It appears the problem occurs because 'args' is being unwrapped into join() on line 61 of audio_manager/audio_source.py. This issue appears to be resolved if the line is replaced with return "/".join(args).

"generate furigana in the field" results with "inconsistent state" for a new note

I have the "Furigana button" (振) enabled, and whenever I press it on the "Add" dialog, Anki throws "your database appears to be in a inconsistent state" message box, and the terminal prints "No such note: '0'". The button works fine if I edit an existing note. It seemed to break on some update as it used to work fine some time ago.

Seems to be related to #9. I use Anki 23.12.1 with the latest AJT from ankiweb.

Audio search can't add audio with warning database in "inconsistent state"

Sorry I'm not familiar with Matrix (I can't seem to join AJT room and not even knowing which room I should join for the purpose of bug report). So pardon me for posting the issue on github.


When adding a new note, I always use the Search Audio dialogue to insert the desired audio file. But after today's update, audio files can't be inserted this way any more. The following is a screencast showing the problem:

CleanShot 2024-02-12 at 21 56 49

You can see the warning popup and the "audio" field remain empty after the dialogue is dismissed.

Actually, simply dismissing the Search Audio dialogue with ESC will trigger the warning.

Checking the stdout output of anki when it's run from CLI, I can see the following error message when the dialogue is dismissed:

No such note: '0'

The Search Audio dialogue still works well if I use it to add an audio file to an existing note. The problem occurs only for new note.

I have already tried "Check Database", which didn't indicate any error. I've also disabled all other add-ons when making these tests.

system info:

  1. OS name: macOS
  2. OS version: 13.5.2
  3. Anki version: 23.12.1 (1a1d4d54)⁩, Python 3.9.15 Qt 6.5.3 PyQt 6.5.3

Crash after updating addon

Anki 23.10.1 (fac9e0ee) Python 3.9.15 Qt 6.6.0 PyQt 6.6.0
Platform: Windows-10-10.0.22621
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-12-01 07:30:09

When loading AJT Japanese:
Traceback (most recent call last):
File "aqt.addons", line 245, in loadAddons
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230_init_.py", line 1, in
from . import tasks, lookup, bulk_add, gui, context_menu, editor_toolbar
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230\tasks.py", line 14, in
from .audio import format_audio_tags, AnkiAudioSourceManager
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230\audio.py", line 19, in
from .config_view import config_view as cfg
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230\config_view.py", line 11, in
from .helpers.audio_manager import AudioSourceConfig
File "C:\Users\rider\AppData\Roaming\Anki2\addons21\1344485230\helpers\audio_manager.py", line 24, in
from .sqlite3_buddy import Sqlite3Buddy, BoundFile
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230\helpers\sqlite3_buddy.py", line 24, in
CURRENT_DB.remove_deprecated_files()
File "C:\Users\xxx\AppData\Roaming\Anki2\addons21\1344485230\helpers\sqlite_schema.py", line 33, in remove_deprecated_files
schema = DbFileSchema(*file.name.split('.'))
TypeError: () missing 1 required positional argument: 'ext'

Mecab issue with path?

  • The add-on stopped working?
    Part of it can't find the path it seems, my pc is in Japanese with UTF8 optional characters enabled that didn't resolve the issue. It generated furigana for the vocab just not the sentence field, all fields are linked to the note type correctly. I did some searching around the web but feel I need some help to resolve this issue. Thanks in advance.
  1. OS name
    エディション Windows 11 Pro
  2. OS version
    バージョン 23H2
    インストール日 ‎18/‎03/‎2024
    OS ビルド 22631.3296
    エクスペリエンス Windows Feature Experience Pack 1000.22687.1000.0
  3. Anki version
    バージョン ⁨23.12.1 (1a1d4d54)⁩
    Python 3.9.15 Qt 6.6.1 PyQt 6.6.1
  4. Logs
    ‪tagger.cpp(151) [load_dictionary_resource(param)] param.cpp(71) [ifs] no such file or directory: C:\Users\RED\AppData\Roaming\Anki2\addons21\1344485230\mecab_controller\support\mecabrc‬
  5. Screenshots, if applicable
スクリーンショット 2024-03-19 172017 スクリーンショット 2024-03-19 172053

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.