分页: 1 / 1

基于definr网站的命令行小词典

发表于 : 2008-01-08 15:16
aBiNg
有关definr,看看这里吧。incredibly fast dictionary! :)

definr基于网页形式存放词条,写个script,抓数据很容易。

这个小脚本,尤其在命令行看E文man时很方便,term中新建一个tab,执行:

代码: 全选

definr word_unknown
而不必去启动stardict或者浏览器在线翻译,前提是definr所在文件夹已被export到$PATH中了。

特点:
1、我写的 :D
2、基于网络
3、支持词组,不必加引号
4、抓网页源码于/tmp目录中,有提醒释放空间
5、重复查看一个词组不必重复抓服务器数据

代码: 全选

aBiNg:~ ¶ cat script/definr 
#!/bin/bash

if [ x"$1" = x'' ]
then
	read -p "input one word: " input
else
	input=$*
fi

input=`echo $input | sed 's/ /%20/g'`
base_html="http://definr.com"
word_url="$base_html/$input"
word_file="/tmp/$input.html"

which html2text > /dev/null || sudo apt-get install html2text -y

function output {
	html2text $1 | sed -n '9,$p' | more
}

if [ -f $word_file ]
then
	output $word_file
else
	wget -c -t 3 -q $word_url -O $word_file
	output $word_file
fi

echo ''

html_counter=`ls /tmp/*.html | wc -l`
if [ $html_counter -gt 500 ]
then
	echo 'WARNING:'
	echo -e '\tMany definr-files fill in /tmp.'
	echo -e '\tExecute "rm -f /tmp/*.html" in terminal to free spaces.'
fi

发表于 : 2008-01-08 15:54
soliton
这只是个英英词典? 词汇量也不大

发表于 : 2008-01-08 15:54
iblicf
Very GOOD :) , NEED sudo apt-get install html2text

其实 ubuntu 就有网络字典,面板上那个 ,

发表于 : 2008-01-08 16:25
aBiNg
To soliton:
嗯,是英英的,解释会地道些;词汇量需求只要不很GRE,日常应该没多大问题,呵呵。

To iblicf:
html2text,我以为是自带的,可以加到script中去。
不用gnome,没那个面板widget。:D

发表于 : 2008-05-26 10:29
fmzw
楼主直接装个wordnet好了

发表于 : 2008-05-31 13:09
paulcross
遇到词组怎么办 似乎有空格的话 就只认空格前面那部分了

发表于 : 2008-06-02 14:26
aBiNg
paulcross 写了:遇到词组怎么办 似乎有空格的话 就只认空格前面那部分了

代码: 全选

[abing ~/incoming] $ definr get rid of

get rid of (http://definr.com/get rid of)

     v 1: dispose of; "Get rid of these old shoes!" "The company got
          rid of all the dead wood" [syn: remove]
     2:  terminate or take out; "Let's eliminate the course on
        Akkadian hieroglyphics" [syn: eliminate, do away with]
     3: do away with; "Slavery was abolished in the mid-19th century
        in America and in Russia" [syn: abolish] [ant: establish]
没问题。

发表于 : 2008-06-02 16:57
millenniumdark
dict本來就支持命令行下的。stardict也有命令行版的。

发表于 : 2008-06-04 15:17
aBiNg
millenniumdark 写了:dict本來就支持命令行下的。stardict也有命令行版的。
有些东西,只是在分享写的快乐而已,用不用看个人。我自己也极少用别人的脚本,除非系统自带的,呵呵。

我一直使用自己的这个脚本查找日常工作遇到的生词,自认为还凑合吧,虽然没什么技术含量。

weakish兄包涵。 :D

发表于 : 2008-06-04 16:19
fireshort
嗯,不错。还可以加上dict.cn的服务。
w3m -dump -no-cookie http://dict.cn/mini.php?q=$input

发表于 : 2008-06-07 7:29
desper
html2text $1 | sed -n '9,$p' | more
用了一下,赞。
不过又试了一下

代码: 全选

dict get\ rid\ of | less
得到的内容多一些,而且喜欢less better than more, 呵呵
2 definitions found

From WordNet (r) 2.0 [wn]:

get rid of
v 1: dispose of; "Get rid of these old shoes!"; "The company got
rid of all the dead wood" [syn: {remove}]
2: terminate or take out; "Let's eliminate the course on
Akkadian hieroglyphics" [syn: {eliminate}, {do away with}]
3: do away with; "Slavery was abolished in the mid-19th century
in America and in Russia" [syn: {abolish}] [ant: {establish}]

From Moby Thesaurus II by Grady Ward, 1.0 [moby-thes]:

103 Moby Thesaurus words for "get rid of":
abandon, abjure, abstract, assassinate, cast, cast aside,
cast away, cast off, cast out, cede, chuck, clear, clear away,
clear out, clear the decks, cut off, cut out, cut short, deep-six,
deport, discard, disgorge, dispel, dispense with, dispose of,
ditch, do away with, do without, drop, dump, eighty-six, eject,
elide, eliminate, end, eradicate, escape, exile, expatriate, expel,
exterminate, finish, finish off, fling off, forgo, forswear,
get along without, get clear of, get free of, get out of,
get quit of, get shut of, give away, give up, have done with,
jettison, jilt, kill, kiss good-bye, liquidate, make a sacrifice,
make away with, murder, nip, outlaw, part with, pick out, purge,
put paid to, quitclaim, recant, reject, relinquish, remove,
render up, renounce, resign, retract, root out, root up, sacrifice,
shake off, shoo, slaughter, slough, spare, strike off, strike out,
surrender, swear off, take off, throw away, throw off, throw out,
throw over, throw overboard, throw up, to, toss overboard, vacate,
waive, weed out, yield

发表于 : 2008-06-09 20:38
millenniumdark
aBiNg 写了: 有些东西,只是在分享写的快乐而已,用不用看个人。我自己也极少用别人的脚本,除非系统自带的,呵呵。
因為不會寫腳本,所以比較留心現成的解決方案。


A hacker always build his own tools.
:D [/quote]

发表于 : 2008-06-09 20:55
solcomo
fireshort 写了:嗯,不错。还可以加上dict.cn的服务。
w3m -dump -no-cookie http://dict.cn/mini.php?q=$input
i like this