kaegi / MorphMan

Anki plugin that reorders language cards based on the words you know
Other
260 stars 66 forks source link

Issue #162: Add MorphemizerManager and support for Spacy addon. #221

Closed rteabeault closed 3 years ago

rteabeault commented 3 years ago
ianki commented 3 years ago

I'm getting the following exception. Perhaps a missing commit to readability_ui.py?

Caught exception:
Traceback (most recent call last):
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\__init__.py", line 34, in onMorphManReadability
    readability.main()
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\morph\readability.py", line 904, in main
    mw.mm = MorphMan(mw.morphemizerManager, mw)
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\morph\readability.py", line 245, in __init__
    self.ui.setupUi(self)
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\morph\readability_ui.py", line 115, in setupUi
    self.morphemizerComboBox = MorphemizerComboBox(self.frame)
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\morph\UI\morphemizerComboBox.py", line 12, in __init__
    self.setMorphemizerManager(morphemizerManager)
  File "C:\Users\Family\AppData\Roaming\Anki2\addons21\900801631\morph\UI\morphemizerComboBox.py", line 17, in setMorphemizerManager
    morphemizerManager.morphemizer_added.connect(self._add_morphemizer)
AttributeError: 'QFrame' object has no attribute 'morphemizer_added'
rteabeault commented 3 years ago

@ianki I pushed a fix. I also have a fix to the AnkiSpacy addon that was causing pip install of a model package to fail. I was not seeing it before because I had another addon that I was developing that masked the problem. I will update here shortly when that is pushed.

rteabeault commented 3 years ago

@ianki I have a pushed a fix for https://github.com/rteabeault/AnkiSpacy/issues/1.

nlovell1 commented 3 years ago

I'm getting this exception when trying to recalc (just reading one field from a Japanese deck). I get a similar error in Ubuntu. Seems that the English dictionaries worked (large and medium). Slightly odd behavior, though. Recalced once with large, crashed. Restarted and calced using medium, which worked. Tried again to do large, then it worked that time. Morph counts also changed as well, so I assume it worked. Below is when I try to recalc using Japanese dict. I assume it's because it never installed properly in the first place, see the second exception from the Spacy installer.

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2021-01-04 22:26:33

Caught exception:
Traceback (most recent call last):
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\lang\ja\__init__.py", line 31, in try_sudachi_import
    from sudachipy import dictionary, tokenizer
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\sudachipy\__init__.py", line 15, in <module>
    from . import utf8inputtextbuilder
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\sudachipy\utf8inputtextbuilder.py", line 16, in <module>
    from .dictionarylib.categorytype import CategoryType
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\sudachipy\dictionarylib\__init__.py", line 19, in <module>
    from . import doublearraylexicon
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\sudachipy\dictionarylib\doublearraylexicon.py", line 17, in <module>
    from dartsclone import DoubleArray
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\dartsclone\__init__.py", line 1, in <module>
    from dartsclone._dartsclone import DoubleArray
ImportError: DLL load failed while importing _dartsclone: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\__init__.py", line 20, in onMorphManRecalc
    main.main()
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\morph\main.py", line 573, in main
    allDb = mkAllDb(cur)
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\morph\main.py", line 195, in mkAllDb
    ms = getMorphemes(morphemizer, fieldValue, ts)
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\morph\morphemes.py", line 166, in getMorphemes
    ms = morphemizer.getMorphemesFromExpr(expression)
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\morph\morphemizer.py", line 52, in getMorphemesFromExpr
    morphs = self._getMorphemesFromExpr(expression)
  File "C:\Users\AppData\Roaming\Anki2\addons21\MorphMan\morph\deps\spacy\morphemizer.py", line 21, in _getMorphemesFromExpr
    self.nlp = spacy.load(self.model_path)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\__init__.py", line 30, in load
    return util.load_model(name, **overrides)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\util.py", line 172, in load_model
    return load_model_from_path(Path(name), **overrides)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\util.py", line 203, in load_model_from_path
    nlp = cls(meta=meta, **overrides)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\language.py", line 186, in __init__
    make_doc = factory(self, **meta.get("tokenizer", {}))
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\lang\ja\__init__.py", line 274, in create_tokenizer
    return JapaneseTokenizer(cls, nlp, config)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\lang\ja\__init__.py", line 139, in __init__
    self.tokenizer = try_sudachi_import(self.split_mode)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\user_files\packages\spacy\lang\ja\__init__.py", line 43, in try_sudachi_import
    raise ImportError(
ImportError: Japanese support requires SudachiPy and SudachiDict-core (https://github.com/WorksApplications/SudachiPy). Install with `pip install sudachipy sudachidict_core` or install spaCy with `pip install spacy[ja]`.

I also get another when trying to install another dictionary (this is in the SpaCy package manager)

Successfully installed Cython-0.29.21 dartsclone-0.9.0 sortedcontainers-2.1.0 sudachipy-0.5.1
[31mERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\_vendor\pip\_internal\cli\base_command.py", line 224, in _main
    status = self.run(options, args)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\_vendor\pip\_internal\cli\req_command.py", line 180, in wrapper
    return func(self, options, args)
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\_vendor\pip\_internal\commands\install.py", line 452, in run
    self._handle_target_dir(
  File "C:\Users\AppData\Roaming\Anki2\addons21\src\_vendor\pip\_internal\commands\install.py", line 505, in _handle_target_dir
    shutil.rmtree(target_item_dir)
  File "shutil.py", line 730, in rmtree
  File "shutil.py", line 608, in _rmtree_unsafe
  File "shutil.py", line 606, in _rmtree_unsafe
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\AppData\\Roaming\\Anki2\\addons21\\src\\user_files\\packages\\sudachipy\\lattice.cp38-win_amd64.pyd'
rteabeault commented 3 years ago

@ianki There are several issues with the AnkiSpacy addon. They primarily occur in Windows and are caused by the OS not letting files in use be deleted or modified. https://github.com/rteabeault/AnkiSpacy/issues/7. They don't necessarily stop the plugin from getting the job done but the user experience is not great. I am considering other options such as your original idea of just having users need to install the packages themself. Also not a great solution but I think with proper instructions it may not be too bad. Let me know your thoughts. In the meantime I am going to explore this alternative.

rteabeault commented 3 years ago

Closing in favor of https://github.com/kaegi/MorphMan/pull/231