Code Monkey home page Code Monkey logo

wudao-dict's Introduction

无道词典

pyplat


无道词典,是一个简洁优雅的有道词典命令行版本。支持英汉互查的功能,包含释义、词组、例句等有助于学习的内容。

无道词典致力于做最好的命令行词典,随着我们优化排版、显示,增加生词本和补全功能,提供了良好的用户体验,并在不断改进中。

英汉:

En_Zh Demo

汉英:

Zh_En Demo

功能特性

  1. 基础词典,同时支持离线和在线查询(20w英汉查询 + 10w汉英查询 + 网络词库)
  2. 词组查询功能(例如直接输入wd in order to)
  3. 自动补全功能(按Tab自动补全单词,包含1w个最热的词)
  4. 生词本(自动把历史记录存为生词本,wd -h查看生词本文件位置)
  5. 交互模式(wd -i进入,可以连续查词)

安装说明

遇到任何问题,或者有任何改善建议请联系作者。

邮箱: [email protected]

issue: 创建新的 issue

Linux 环境

  1. 安装环境: 需要python3和bs4, lxml(在线搜索用)

    Debian/Ubuntu

    sudo apt-get install python3
    sudo apt-get install python3-pip
    sudo pip3 install bs4
    sudo pip3 install lxml
    

    OpenSUSE

    sudo zypper install python3-pip
    sudo pip3 install bs4
    sudo pip3 install lxml
    

    CentOS

    sudo yum install python34
    sudo yum install python34-pip
    sudo pip3 install bs4
    sudo pip3 install lxml
    

    MacOS

    brew install python3
    sudo easy_install pip
    sudo pip install bs4
    sudo pip install lxml
    brew install bash-completion
    
  2. 运行

    git clone https://github.com/chestnutheng/wudao-dict
    cd ./wudao-dict/wudao-dict
    sudo bash setup.sh #或者sudo ./setup.sh

    看到出现Setup Finished!表明安装成功。如果发生由于移动安装文件不能使用的情况,只需再次运行该脚本即可。

无法clone的,可以下载 https://github.com/ChestnutHeng/Wudao-dict/archive/master.zip ,然后解压安装使用。

Note: 注意python的版本,只支持python3

使用说明

运行wd -h查看使用说明。

$ wd -h
Usage: wd [OPTION]... [WORD]
Youdao is wudao, a powerful dict.
-k, --kill             kill the server process       (退出服务进程)
-h, --help             display this help and exit    (查看帮助)
-s, --short            do or dont show sentences     (简明/完整模式)
-i, --inter            interaction mode              (交互模式)
-n, --note             save/not save to notebook     (保存/不保存到生词本)
-v, --version          version info                  (版本信息)
生词本文件: ... some path .../notebook.txt
查询次数: ... some path .../usr_word.json

查词时可以直接使用wd 词语查汉英词典,或wd word查英汉词典(可以自动检测)。

小贴士

  1. ./wd_monofile 是本词典的在线查询的单文件版本, 可以复制到/usr/bin下直接使用.(需要安装bs4)
  2. 如果您不想看到例句, 请使用wd -s关闭。可以再次运行该命令打开。
  3. 有的用户反馈字体颜色看不清的问题, 你可以找到./wudao-dict/wudao-dict/src/CommandDraw.py, 可以看到释义,读音等采用的颜色, 直接修改即可.
  4. 查询词组直接键入类似wd take off即可.

Release Notes

Ver 1.0 (Oct 10, 2016)

  • 提供了基础的英汉互查的功能
  • 提供了在线查询的功能,并且查过后会缓存

Ver 1.1 (Dec 1, 2016)

  • 提供了可以单独运行的单文件版本wd_monofile

Ver 1.2 (Nov 22, 2017)

  • 在线查询修复了不显示被查词的bug

Ver 2.0 (Dec 3, 2018)

  • 修复了文件夹过大的问题,由263M缩小到80M左右。 issue #1: 文件夹大小
  • 添加了更多的常用词和单复数形式
  • 取消了网络搜索功能,没有在本地找到时会自动进行网络搜索
  • 添加了bash终端的tab补全的支持,对常用的1w词进行tab补全 issue #15: 模糊查询的支持
  • 添加了生词本功能,自动把查过的词和释义添加到生词本文件中
  • 优化了排版,同一单词不再截断换行了 #该功能因为转移字符的问题搁置 issue #16:避免在单词内换行

Ver 2.1 (Nov 27, 2019, lastest)

wudao-dict's People

Contributors

chestnutheng avatar diyer22 avatar idiomaticrefactoring 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wudao-dict's Issues

建议默认只看释义

基本上是查查看某个单词什么意思,例句什么的可以加参数查看,否则像我改成了默认【wd】是【wd -s】的效果,再想看例句就不知道加什么参数了

模糊查询的支持

模糊查询对于查单词来说太重要了,往往记不住的话wd也发挥不出来功用啊啊。
建议起码包括以下几项:

  • 单复数能够正常查询
  • 只输入前半部,后边可以使用Tab补全或者列出候选项之类的

安全问题!

里面太多的http了,很多都可以用https的。我在互联网安全公司工作,安全分析师刚刚给我看我查的每一个词在公司网络上都看得到。现在全公司都知道我英语不好了!泪...
而且代码里有把在线查到的词上传到你的服务器数据库是吗?这至少应该提前说一声啊。这也是隐私保护的一部分。最好应该可以选择愿不愿意上传,而不是只要用了这个工具就上传给你。

git clone 总是到42%以后,就安装失败了

大家看看有没有这种情况的发生

✘ soar@sir  ~/Applications  git clone https://github.com/chestnutheng/wudao-dict Cloning into 'wudao-dict'... remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (8/8), done. error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54 fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed

thanks

感谢!哈哈,终于找到这么可爱的翻译了。

关于安装脚本的/usr/bin/wd脚本生成

  1. 应该可以在wd脚本中保存一下安装路径,然后按照安装路径调用,要修改wdd文件应该可以避免在wd命令中跳转目录了。
  2. 可以最后传给管道(more,less) 分屏,如:wdd $* | more,这个确实很需要,我是本地再写了一个脚本调用命令调用wdd的

查询词汇出错,uninstall 后再安装也无法解决问题

安装好后,任意查询词汇:
xiankun@xiankun-PC:~/Softwares/Wudao-dict/wudao-dict$ wd university
出现如下错误:
Traceback (most recent call last):
File "WudaoCommand.py", line 118, in
main()
File "WudaoCommand.py", line 114, in main
app.query()
File "WudaoCommand.py", line 74, in query
self.history_manager.add_item(self.word)
File "/home/xiankun/Softwares/Wudao-dict/wudao-dict/src/UserHistory.py", line 30, in add_item
self.content = json.load(f)
File "/usr/lib/python3.4/json/init.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.4/json/init.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

运行uninstall.sh后再安装也无法解决问题,是否是我的python版本的问题?

安装失败

系统: Ubuntu 17.10

Wudao-dict git:(master) ✗ sudo ./wudao-dict/setup.sh cp: 无法获取'wd_com' 的文件状态(stat): 没有那个文件或目录 ./wudao-dict/setup.sh: 行 23: /etc/bash_completion.d/wd: 没有那个文件或目录 Setup Finished! use wd [OPTION]... [WORD] to query the word. 自动补全会在下次打开命令行时启用 或者手动运行 source ~/.bashrc
➜ ~ wd /usr/bin/wd: 行 4: ./wdd: 没有那个文件或目录
单文件可以运行
➜ ~ ./Downloads/Wudao-dict/wd_monofile task task 英 [tɑːsk] 美 [tæsk] vt. 分派任务 n. 工作,作业;任务 CET4 TEM4 ( tasking, tasked, tasks )

增加zsh补全

可以在原本在bash的补全文件的基础上修改,然后通过.zshrc source加载,不知道可不可以在setup.sh中安装时进行自动设置。

# ~/.oh-my-zsh/completions/_wd
_wudao()
{
    optl=(
the
of
...
admitting
)
    compadd ${optl[@]}
}
compdef _wudao wd
# ~/.zshrc
source /home/yourname/.oh-my-zsh/completions/_wd

理论上~/.oh-my-zsh/completions/是在$fpath中,每次启动zsh时会该目录下的文件自动加载,但不知道为什么我的始终不行,最后在.zshrc中加了source

在kali下无法使用, 错误信息如下, 请问如何解决?

系统: kali-2018.2
终端: gnome-terminal
指令:
root@kali:/wudao-dict/wudao-dict# ./setup.sh
Setup Finished!
use wd [OPTION]... [WORD] to query the word.
自动补全会在下次打开命令行时启用
或者手动运行 source /.bashrc
root@kali:
/wudao-dict/wudao-dict# wd hello
Traceback (most recent call last):
File "WudaoCommand.py", line 10, in
from src.WudaoClient import WudaoClient
File "/root/wudao-dict/wudao-dict/src/WudaoClient.py", line 3, in
import socket
File "/usr/lib/python3.6/socket.py", line 49, in
import _socket
ModuleNotFoundError: No module named '_socket'
Python版本:
root@kali:
/wudao-dict/wudao-dict# python3
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

[1]+ Stopped python3

查词时自动发音

有个epeak的工具可以实现发音,我更熟悉shell,所以编写了如下代码实现查词时自动发音功能。

#!/bin/bash 
filename="/home/zjq/Wudao-dict/`date '+%x'`_words"
case $1 in 
  -b) 
      touch $filename.txt
      echo "`date '+%x'`_words" > $filename.txt
      #创建一个.txt文件用来存查过的单词,文件名是时间戳
      ;;
  -s)
      sed '/^\s*$/d' $filename.txt | s-nail  -s "new words" [email protected]
      #去掉空格,并以 new words 为主题发送邮件至指定你的邮箱 
      ;;
  *)
      word=" "
      for x
      do
          word="$word $x"
      done
      #连接单词和短语
      ;;
esac
wd -o $word 
espeak "$word"
echo $word >> $filename.txt

交互模式 wd -i

wd -i命令进入交互模式,直接输入单词然后回车就能查词,查完后程序不退出,可以接着查下一个词。

BrokenPipeError: [Errno 32] Broken pipe

Error: Connection out of time
Traceback (most recent call last):
File "WudaoCommand.py", line 135, in
main()
File "WudaoCommand.py", line 131, in main
app.query()
File "WudaoCommand.py", line 77, in query
server_context = self.client.get_word_info(self.word).strip()
File "/home/micheallin/Workspace/github/Wudao-dict-master/wudao-dict/src/WudaoClient.py", line 29, in get_word_info
self.client.sendall(word.encode('utf-8'))
BrokenPipeError: [Errno 32] Broken pipe

macOS support

It's really a fantastic tool. Would be great if it can add macOS support. Thanks.

Functioning Abnormally and Canot Be Used Any More

Here below is the screen output after I "wd ####" a word

^CTraceback (most recent call last):
File "WudaoCommand.py", line 118, in
main()
File "WudaoCommand.py", line 114, in main
app.query()
File "WudaoCommand.py", line 68, in query
server_context = self.client.get_word_info(self.word).strip()
File "/home/HOST/wudao-dict/wudao-dict/src/WudaoClient.py", line 27, in get_word_info
self.connect()
File "/home/HOST/wudao-dict/wudao-dict/src/WudaoClient.py", line 17, in connect
self.client.connect(("0.0.0.0", 2376))
KeyboardInterrupt

建议: 用 sqlite3 来储存 dict/en.z, dict/zh.z 里的数据. Migrate the data in "dict/en.z", "dict/zh.z" to a sqlite3 database

由于无道词典的操作方式是开启一个本地服务器 (WudaoServer.py) 随时聆听请求并以 json 格式返回查询单词的语意, 而服务器包含一个 JsonReader (src/JsonReader.py) 物体, 该物体储存了所有中英文单词的索引, 难免有些占用内存 (如图 约 116MB).

image

如果能够讲运用 Python 自带的 sqlite3 建立一个简单的数据库, 必能优化以上问题, 且能有效的加快查询速度.

新版本不能使用

rm掉旧版本,clone新版本安装后不能使用

$ wd fuck
Error: Connection out of time
Traceback (most recent call last):
  File "WudaoCommand.py", line 135, in <module>
    main()
  File "WudaoCommand.py", line 131, in main
    app.query()
  File "WudaoCommand.py", line 77, in query
    server_context = self.client.get_word_info(self.word).strip()
  File "/home/linmei/tools/wudao-dict/wudao-dict/src/WudaoClient.py", line 29, in get_word_info
    self.client.sendall(word.encode('utf-8'))
BrokenPipeError: [Errno 32] Broken pipe

需要一个生成英语文章词汇表的功能

我用你的代码做了一个:https://github.com/xuiv/WuYoudao-dict

你的代码有一些问题,服务器上因为json调用会生成太多异常导致崩溃,服务器上的生僻词提交导致效率低下,你应该把查不出来生僻词提交放到客户端里。

我用BytesIO把词典文件放到内存里了,生僻词提交的代码我也删除了,希望你能把这个功能合并进来。我没学过python,你自己弄吧。

在线查询时出现错误

wd -o ####

Traceback (most recent call last):
File "WudaoCommand.py", line 118, in
main()
File "WudaoCommand.py", line 114, in main
app.query()
File "WudaoCommand.py", line 85, in query
word_info = get_text(self.word)
File "/home/dolabmoon/Wudao-dict-master/wudao-dict/src/WudaoOnline.py", line 36, in get_text
root = bs4.BeautifulSoup(content, "lxml")
File "/usr/local/lib/python3.5/dist-packages/bs4/init.py", line 165, in init
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

无道词典连不上网

Word not found, auto Online search...
No Internet : Please check your connection or try again.

Ubuntu18.04,电脑已经联网,在终端ping百度这些网站也能ping通,但是无道词典查询报错,连不上网

在线查询网络释义

有些词在线查询查不到,但是在网易的网页版是能查到网络释义的。不知能否考虑在在线查询中加入此释义?

Very, very small problems

First,Thank you!

安装环境: 需要python3和bs4 (在线搜索用)

sudo apt-get install python3
sudo apt-get install python3-pip
pip3 install bs4

need change to:

sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install bs4

无法在线查询

系统:Archlinux
桌面:kde
终端:Konsole
错误信息:
File "WudaoCommand.py", line 135, in
main()
File "WudaoCommand.py", line 131, in main
app.query()
File "WudaoCommand.py", line 103, in query
word_info = get_text(self.word)
File "/home/lkf/gitrepo/wudao_dict/wudao-dict/src/WudaoOnline.py", line 87, in get_text
d = root.select(".wordGroup.def")
TypeError: 'NoneType' object is not callable
注:已安装bs4,lxml。
控制台python
>>>import bs4
>>>import lvml
也没有问题。

wd 运算符 和 wd 算符 报错

执行命令:wd 运算符 报以下错误,wd 算符也是,其余的没发现
Traceback (most recent call last): File "WudaoCommand.py", line 135, in <module> main() File "WudaoCommand.py", line 131, in main app.query() File "WudaoCommand.py", line 81, in query word_info = json.loads(server_context) File "/usr/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

能否支持管道翻译或文本?

我一直在使用您的wd作为日常翻译工具使用,感觉非常好用和方便:+1:。但我最近在使用的时候发现一个翻译场景可能会比较常见但是wd无法支持:hushed:。就是使用wd翻译txt文本,或者说是使用wd翻译linux命令的帮助,因为大多数命令都是英文的,需要去网络上进行查找,效率非常低。如果使用管道结合wd进行翻译例如下面的命令“docker run --help | wd”。这样对命令的使用和学习应该帮助很大,现在的同类软件中都没有这样的支持,如果wd能支持的话相信star应该不会少的:smile:。

有没有web based版本?

比如通过浏览器访问下面的URL

http://URL/querydict?example

然后在浏览器上显示英文单词example的解释。

Input/output error

mashiro@DESKTOP-AB378GP:~$ cd ./wudao-dict/wudao-dict
mashiro@DESKTOP-AB378GP:~/wudao-dict/wudao-dict$ sudo sh setup.sh
[sudo] mashiro 的密码:
mkdir: 无法创建目录"usr": 文件已存在
Unziping...
Archive:  ./dict/dict.zip
error:  cannot create ./dict/dict.index
        Input/output error
error:  cannot create ./dict/dict.json
        Input/output error
error:  cannot create ./dict/zh_dict.index
        Input/output error
error:  cannot create ./dict/zh_dict.json
        Input/output error
Setup Finished!
use wd [OPTION]... [WORD] to query the word.
mashiro@DESKTOP-AB378GP:~/wudao-dict/wudao-dict$ su root
密码:
root@DESKTOP-AB378GP:/home/mashiro/wudao-dict/wudao-dict# sudo sh setup.sh
mkdir: 无法创建目录"usr": 文件已存在
Unziping...
Archive:  ./dict/dict.zip
error:  cannot create ./dict/dict.index
        Input/output error
error:  cannot create ./dict/dict.json
        Input/output error
error:  cannot create ./dict/zh_dict.index
        Input/output error
error:  cannot create ./dict/zh_dict.json
        Input/output error
Setup Finished!
use wd [OPTION]... [WORD] to query the 
```word.

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.