lujun9972 / anki-vocabulary.el

Help you to create vocabulary card in Anki
10 stars 3 forks source link

Any plan to use mdx dictionaries instead of youdao? #2

Open panmengguan opened 3 years ago

panmengguan commented 3 years ago

Thank you very much! This package is very useful!

However, the definitions from youdao.com is quite simple. Is there any plan to support other mdx dictionaries? If so, this package would be a perfect alternative to online-dictionary-helper.

lujun9972 commented 3 years ago

Here is the way:

  1. install mdx-dictionary.el which needs python3 installed.

  2. configuration like this

    (when (package-installed-p 'mdx-dictionary)
      (setq anki-vocabulary-word-searcher (lambda (word)
                                            (or (when (and (boundp 'mdx-dictionary-server-process) mdx-dictionary-server-process) 
                                                  (mdx-dictionary-request word))
                                                (anki-vocabulary--word-searcher-youdao word)))))))
panmengguan commented 3 years ago

非常感谢您的指导!我这两天进行了尝试,然而还是没有得到正确的结果。麻烦您有空再看一下。

首先,按照说明配置后,emacs 中执行 mdx-dictionary-start-server 后,执行 mdx-dictionary-query 出错,出错信息是 REQUEST [error] Error (error) while connecting to http://localhost:8000/Please, 此时浏览器 http://localhost:8000/test 也无法查询到单词。

进一步检查 mdx-server,目前 github 上主要有三个版本,分别进行了测试。

本仓库 mdx-dictionary.el 中的版本

命令行敲 python .\mdx_server.py 并选择词典后显示: Please specify a valid MDX/MDD file. 经排查,可能是 python 3 os.path.exists 函数处理 windows 10 路径的问题 (https://stackoverflow.com/questions/33145744/python-os-path-exists-returns-false-on-windows-10-and-true-on-windows-7-for-the).

https://github.com/ninja33/mdx-server 版本

命令行敲 python .\mdx_server.py 并选择词典后命令行能显示: Serving HTTP on port 8000, 然而查询单词出错,经排查,似乎这个版本混 =lemma.py= 中混有一些 python 2 的代码,修改后能够正确查询单词。

https://github.com/einverne/mdx-server/tree/morphology 版本

该版本对 =lemma.py= 进行了更新,能够处理单词的形变 (https://github.com/ninja33/mdx-server/issues/9). 经测试,在浏览器能够正确查询到单词,且确实能够很好地处理单词的形变。

不知道能否将 https://github.com/einverne/mdx-server/tree/morphologymdx-servermdx-dictionary.el 相结合?一方面修正了目前可能存在的问题,另一方面,也解决了处理单词形变的问题。我注意到 mdx-dictionary.el 似乎能够处理多 mdx 查询的问题,不知道是否方便修改?

非常感谢!

lujun9972 commented 3 years ago

其实我对Python也不是很熟悉,你能帮忙提个PR吗?谢谢