#!/usr/bin/perl -w ############### censor.pl ################# # Handle the explanations got from online dictionary. # Inputs: # ARGV[0] -- temparory file containning the explanations # ARGV[1] -- keyword ############################################ use strict; use Encode; my $syntax = Encode::decode('utf8', '语法标注解释 '); my $internet = Encode::decode('utf8', '以下结果来自互联网网络释义'); my $yingyin = Encode::decode('utf8', '英音'); my $meiyin = Encode::decode('utf8', '美音'); my $write_flag=0; open(EXP,$ARGV[0]); while (my $nextline=) { chomp($nextline); $nextline = Encode::decode('utf8', $nextline); if ($nextline =~ m/.*$syntax.*/) { $write_flag=1; $nextline =~ s/$syntax//; } elsif ($nextline =~ m/.*$internet.*/) { $write_flag=0; } if ($write_flag eq 1) { if ($nextline !~ m/.*/*/*/*/*.*/) { # Excluse lines containning **** # Add a space between the keyword and 英音/美音 $nextline =~ s/$ARGV[1]([$yingyin|$meiyin])/$ARGV[1] $1/; print encode("utf8",$nextline),"/r/n"; # In perl, /r/n is needed to add a new line } } }
运行上面的脚本后,可以得到如下的输出:
antiseptic 英音:[,ænti'septik]美音:[,æntə'sɛptɪk] 形容词 a. 1. 抗菌的,防腐的 2. 使用抗菌剂的,使用防腐剂的 antiseptic treatment 防腐处理 3. 未受感染的,无菌的,消过毒的 The technician had on an antiseptic white jacket. 那个技术员穿着消毒白色夹克。 4. 非常整洁的 5. 冷淡的,缺乏热情的 He nodded an antiseptic greeting. 他冷冷地点头打了个招呼。 名词 n. 1. 抗菌剂,防腐剂[C]
另外,如果要自动化查询一批英文单词,可以把它们写到一个文件中,然后用下面的脚本进行自动查询
#!/bin/bash # Command line look up using Google's define feature - command line dictionary WORDS=$(cat ./words) for word in $WORDS do # word=$1 #curl -s -A 'Mozilla/4.0' 'http://www.google.com/dictionary?langpair=zh-CN|en&hl=en&aq=f&q='$word >> test.html curl -s -A 'Mozilla/4.0' "http://dict.baidu.com/s?tn=dict&wd="$word | html2text > tmp 2>/dev/null echo "------------------ $word -------------------" >> mywords ./censor.pl tmp $word >> mywords rm -f tmp done
Update 2011-01-02:
终于找到了查询Google Dictionary的一种方法。
Google Dictionary对于单词abandon的解释可以利用URL:http://www.google.com/dictionary?langpair=en|zh-CN&q=abandon&hl=en&aq=f 得到,而网页的信息如下:
abandon in Chinese (Simplified) - Google Dictionary
"People died for this tournament, others were injured. We can't abandon them and leave like cowards," Alaixys Romao told French sports agency L'Equipe. "If we stay here, it's for them. But also so as not to give satisfaction to the rebels....
"The president would have us believe there are two choices: keep all of our troops in Iraq or abandon these Iraqis," Obama said. "I reject this choice."
give up with the intent of never claiming again; "Abandon your life to God"; "She gave up her children to her ex-husband when she moved to Tahiti"; "We gave the drowning victim up for dead"
The usage examples, images and web definitions on this page were selected automatically by a computer program. They do not necessarily reflect the views of Google Inc. or its employees.
#!/bin/bash # Command line look up using Google's define feature - command line dictionary # gd -i -o [-w ] function query { typeset wd=$1 typeset TMPFILE=tmp.$wd typeset i=0 while ((i<5)) do curl -s -A 'Mozilla/4.0' "http://www.google.com/dictionary?langpair=zh-CN|en&hl=en&aq=f&q=$wd" >$TMPFILE 2>/dev/null if [ -s $TMPFILE ]; then break elif ((i=4)); then echo $wd >> failed.gd.$input fi ((i=i+1)) sleep 1 done perl -i -p -e "print STDOUT /$1,/"/r/n/" if (m/($wd.*:.*)- Google.*/);" $TMPFILE rm -f $TMPFILE } ############################################## # MAIN LINE START HERE ############################################## typeset input= typeset output= typeset word= typeset -i flag=0 while getopts 'i:o:w:' OPT do case $OPT in i) input=${OPTARG};; o) output=${OPTARG};; w) word=${OPTARG};flag=1;; *) echo -u2 "ERROR: Invalid argument [$OPT]" ;; esac done shift `expr $OPTIND - 1` if ((flag==0)); then perl -i.bk -p -e "s/^(/w+).*[/[//].*[/]//]//$1/;" $input # Eliminate the phonetic symbol WORDS=$(cat $input) for word in $WORDS do word_exp=$(query $word) if [ ${#word_exp} != 0 ]; then echo $word_exp >> $output else echo "$word:" >> $output fi done else word_exp=$(query $word) if [ ${#word_exp} != 0 ]; then echo $word_exp else echo "$word:" fi fi
2011-01-03 Update:
奉上完整版的程序:
#!/bin/bash # Command line look up using Google's define feature - command line dictionary # od [-b] [-g]-i -o [-w ] # gd - Query words using Google Dictionary function gd { typeset wd=$1 typeset TMPFILE=tmp.gd.$wd typeset -i i=0 while ((i<5)) do curl -s -A 'Mozilla/4.0' "http://www.google.com/dictionary?langpair=zh-CN|en&hl=en&aq=f&q=$wd" >$TMPFILE 2>/dev/null if [ -s $TMPFILE ]; then break elif ((i=4)); then echo $wd >> failed.gd.$input fi ((i=i+1)) sleep 1 done perl -i -p -e "print STDOUT /$1,/"/r/n/" if (m/($wd.*:.*)- Google.*/);" $TMPFILE rm -f $TMPFILE } # bd - Query words using Baidu Dictionary # function bd { typeset wd=$1 typeset TMPFILE=tmp.bd.$wd typeset -i i=0 while ((i<5)) do curl -s -A 'Mozilla/4.0' "http://dict.baidu.com/s?tn=dict&wd="$word | html2text > $TMPFILE 2>/dev/null if [ -s $TMPFILE ]; then break elif ((i=4)); then echo $wd >> failed.bd.$input fi ((i=i+1)) sleep 1 done ./censor.pl $TMPFILE $wd rm -f $TMPFILE } ############################################## # MAIN LINE START HERE ############################################## typeset input= typeset output= typeset word= typeset dict=z"gd bd" typeset -i word_flag=0 while getopts 'agbi:o:w:' OPT do case $OPT in g) dict=gd;; b) dict=bd;; i) input=${OPTARG};; o) output=${OPTARG};; w) word=${OPTARG};word_flag=1;; *) echo -u2 "ERROR: Invalid argument [$OPT]" ;; esac done shift `expr $OPTIND - 1` if ((word_flag==0)); then # perl -i.bk -p -e "s/^(/w+).*[/[//].*[/]//]//$1/;" $input # Eliminate the phonetic symbols WORDS=$(cat $input) for word in $WORDS do case $dict in *bd*) echo "------------------ $word -------------------" >> $output;; esac for d in $dict do word_exp=$($d $word) if [ ${#word_exp} != 0 ]; then echo $word_exp >> $output else echo "$word:" >> $output fi done done else for d in $dict do $d $word done fi
#!/usr/bin/perl -w ############### censor.pl ################# # Handle the explanations got from online dictionary. # Inputs: # ARGV[0] -- temparory file containning the explanations # ARGV[1] -- keyword ############################################ use strict; use Encode; my $syntax = Encode::decode('utf8', '语法标注解释 '); my $internet = Encode::decode('utf8', '以下结果来自互联网网络释义'); my $yingyin = Encode::decode('utf8', '英音'); my $meiyin = Encode::decode('utf8', '美音'); my $baidu = Encode::decode('utf8', '此内容系百度根据您的指令自动搜索的结果'); my $write_flag=0; open(EXP,$ARGV[0]); while (my $nextline=) { chomp($nextline); $nextline = Encode::decode('utf8', $nextline); if ($nextline =~ m/.*$syntax.*/) { $write_flag=1; $nextline =~ s/$syntax//; } elsif ($nextline =~ m/.*$internet.*/ || $nextline =~ m/.*$baidu.*/) { $write_flag=0; } if ($write_flag eq 1) { if ($nextline !~ m/.*/*/*/*/*.*/) { # Excluse lines containning **** # Add a space between the keyword and 英音/美音 $nextline =~ s/$ARGV[1]([$yingyin|$meiyin])/$ARGV[1] $1/; print encode("utf8",$nextline),"/r/n"; # In perl, /r/n is needed to add a new line } } } close(EXP);
ArcgisEngine实现对地图的放大、缩小和平移:
个人觉得是平移,不过网上的都是漫游,通俗的说就是把一个地图对象从一边拉到另一边而已。就看人说话吧.
具体实现:
一、引入命名空间
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
二、代码实现.
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of th