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

sh/bash/dash/ksh/zsh等Shell脚本
回复
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

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

#1

帖子 aBiNg » 2008-01-08 15:16

有关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
上次由 aBiNg 在 2008-01-08 19:01,总共编辑 1 次。
头像
soliton
帖子: 338
注册时间: 2006-05-13 14:00

#2

帖子 soliton » 2008-01-08 15:54

这只是个英英词典? 词汇量也不大
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#3

帖子 iblicf » 2008-01-08 15:54

Very GOOD :) , NEED sudo apt-get install html2text

其实 ubuntu 就有网络字典,面板上那个 ,
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#4

帖子 aBiNg » 2008-01-08 16:25

To soliton:
嗯,是英英的,解释会地道些;词汇量需求只要不很GRE,日常应该没多大问题,呵呵。

To iblicf:
html2text,我以为是自带的,可以加到script中去。
不用gnome,没那个面板widget。:D
头像
fmzw
帖子: 24
注册时间: 2008-01-14 17:30

#5

帖子 fmzw » 2008-05-26 10:29

楼主直接装个wordnet好了
头像
paulcross
帖子: 484
注册时间: 2006-07-23 20:27

#6

帖子 paulcross » 2008-05-31 13:09

遇到词组怎么办 似乎有空格的话 就只认空格前面那部分了
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#7

帖子 aBiNg » 2008-06-02 14:26

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]
没问题。
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#8

帖子 millenniumdark » 2008-06-02 16:57

dict本來就支持命令行下的。stardict也有命令行版的。
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#9

帖子 aBiNg » 2008-06-04 15:17

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

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

weakish兄包涵。 :D
fireshort
帖子: 161
注册时间: 2007-03-08 19:12
联系:

#10

帖子 fireshort » 2008-06-04 16:19

嗯,不错。还可以加上dict.cn的服务。
w3m -dump -no-cookie http://dict.cn/mini.php?q=$input
头像
desper
帖子: 95
注册时间: 2006-10-03 4:28

#11

帖子 desper » 2008-06-07 7:29

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
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#12

帖子 millenniumdark » 2008-06-09 20:38

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


A hacker always build his own tools.
:D [/quote]
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#13

帖子 solcomo » 2008-06-09 20:55

fireshort 写了:嗯,不错。还可以加上dict.cn的服务。
w3m -dump -no-cookie http://dict.cn/mini.php?q=$input
i like this
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
回复