wr-0.0.1 Commandline WordReference Lookup

Miscellaneous tools
Post Reply
Message
Author
User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

wr-0.0.1 Commandline WordReference Lookup

#1 Post by neurino »

This is another little Bash script I wrote to get quick terms translations in terminal.

Usage:

Code: Select all

# wr
Usage: wr [-c] dictionary term
Term lookup at wordreference.com

-c	return also compounds
-h	show this help

The dictionary that you want to look up your term in is specified by
a combination of the two-letter code for the original language and
the two-letter code for the target language.

For example, if you are looking up for a word from English to French, the
dictionary would be 'enfr', where 'en' stands for English, and 'fr' for French.
The two letter language abbreviations are below:

Language	Abbreviation
========	============
Arabic		ar
Chinese		zh
Czech		cz
English		en
French		fr
Greek		gr
Italian		it
Japanese	ja
Korean		ko
Polish		pl
Portuguese	pt
Romanian	ro
Spanish		es
Turkish		tr

You can install the pet that will put script in /usr/local/bin or extract it from the tar.gz and put it where you want in your PATH (for example ~/my-apllications/bin) or just call it as ./wr.

Script is compilant with Wordreference API TOS and approved from its staff.
Attachments
wr-0.0.1.pet
md5sum: 7260eccbea97a1b8ceba02e1b0a1363c wr-0.0.1.pet
(1.93 KiB) Downloaded 412 times
wr-0.0.1.tar.gz
md5sum: 219db2482d7c99ad8fa49a3d6bb6bd60 wr-0.0.1.tar.gz
(1.71 KiB) Downloaded 477 times

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: wr-0.0.1 Commandline WordReference Lookup

#2 Post by L18L »

Hi neurino,
nice script.
Searching for bugs I have found:

Code: Select all

# ./wr ende hello
http://www.wordreference.com/ende/hallo
© WordReference.com
# ./wr deen hallo
Unknown dictionary
http://www.wordreference.com/deen/hallo
© WordReference.com
# 
strange:
deen unknown
ende nothing

At the website it is OK.

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#3 Post by neurino »

Hi L18L,

they're not supposed to be bugs: the API gives no access to ALL dictionaries, as stared by their API page too.

As you can see in Usage German dictionary is not available.

The "Unknown dictionary" is a message generated by my script in case of 404 error returned.

My luck is I need it for english-to-italian and back and it works flawlessly.

Thanks for testing anyway. :)
Last edited by neurino on Thu 23 Jun 2011, 11:12, edited 1 time in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

API key

#4 Post by L18L »

neurino wrote:Hi L18L,

they're not supposed to be bugs: the API gives no access to ALL dictionaries, as stared by their API page too.

The "Unknown dictionary" is a message generated by my script in case of 404 error returned.

My luck is I need it for english-to-italian and back and it works flawlessly.

Thanks for testing anyway. :)
Does that mean that your API key is valid for English and Italiano only :?:

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#5 Post by neurino »

Since no one asked me for a dictionary on API registration I'm quite sure it's not...

Also english-to-arabian won't work in that case... (see screenshot)

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#6 Post by L18L »

neurino wrote:Since no one asked me for a dictionary on API registration I'm quite sure it's not...

Also english-to-arabian won't work in that case... (see screenshot)
Do you have an explanation for my results of en to de and de to en ?

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#7 Post by neurino »

L18L wrote: Do you have an explanation for my results of en to de and de to en ?
Yes and it's in my first answer to your post:
the API gives no access to ALL dictionaries.
Didi you read the page I linked?

This is what the API returns for your request "ende hello":

Code: Select all

{
"Lines" : "End Reached", "END" : true
}
Not to mention the API gives an error for "deen hallo" as unknown dictionary.

What am I supposed to return then?

C'mon...

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

wr-0.0.1 Commandline WordReference Lookup

#8 Post by L18L »

Yes, I did read the API page and I cannot suggest anything but changing your Subject description. 8)

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#9 Post by neurino »

I don't expect this script to be widely used but I kindly ask you to not fill this thread with unuseful flames (do you see German dictionary in Usage? I dont so it's not expected to work), thank you.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Commandline WordReference Lookup

#10 Post by L18L »

I am hoping that you will understand this language 8)

Code: Select all

#dictionary is first arg
dict="$1"

#check input language pair
dict1="${dict:0:2} "
OK=0
 [ "`echo 'ar zh cz en fr gr it ja ko pl pt ro es tr ' | grep $dict1 `" != "" ] && OK=1
if [ $OK -ne 1 ]; then
 usage
 exit 2
fi 
dict2=${dict:2:2}
OK=0
 [ "`echo 'ar zh cz en fr gr it ja ko pl pt ro es tr ' | grep $dict2 `" != "" ] && OK=1
if [ $OK -ne 1 ]; then
 usage
 exit 2
fi
 
#remove dictionary from args

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

Re: Commandline WordReference Lookup

#11 Post by neurino »

L18L wrote:I am hoping that you will understand this language 8)
L18L as you can see my script is released under GPL so you are free to fork from it and make your own version, just changing its name, and distribute it as I did.

Also not all possible combinations in usage explained languages are available (I don't expect to work something like tukish to polish but havent tested tho) so your add is overkill to me since it does not guarantee at all that, if test passes, a translation is provided.

I won't add it to my script anyway, as I wrote, you are free to make your own version and release it under GPL rules and, hopefully, start your own thread here on the forum.

Cheers

P.S.: you don't need to bother with grep to check if a string is substring of another:

Code: Select all

#dicts='ar zh cz en fr gr it ja ko pl pt ro es tr '
# [[ "$dicts" =~ "en" ]] && echo yes || echo no
yes
# [[ "$dicts" =~ "de" ]] && echo yes || echo no
no

Post Reply