Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 16 Apr 2014, 09:48
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
wr-0.0.1 Commandline WordReference Lookup
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Thu 23 Jun 2011, 03:21    Post subject:  wr-0.0.1 Commandline WordReference Lookup  

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

Usage:
Code:
# 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.
wr-0.0.1.pet
Description  md5sum: 7260eccbea97a1b8ceba02e1b0a1363c wr-0.0.1.pet
pet

 Download 
Filename  wr-0.0.1.pet 
Filesize  1.93 KB 
Downloaded  205 Time(s) 
wr-0.0.1.tar.gz
Description  md5sum: 219db2482d7c99ad8fa49a3d6bb6bd60 wr-0.0.1.tar.gz
gz

 Download 
Filename  wr-0.0.1.tar.gz 
Filesize  1.71 KB 
Downloaded  239 Time(s) 
shot.png
 Description   
 Filesize   227 KB
 Viewed   596 Time(s)

shot.png

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Thu 23 Jun 2011, 05:52    Post subject: Re: wr-0.0.1 Commandline WordReference Lookup
Subject description: 1st test
 

Hi neurino,
nice script.
Searching for bugs I have found:
Code:
# ./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.
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Thu 23 Jun 2011, 05:57    Post subject:  

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. Smile

Last edited by neurino on Thu 23 Jun 2011, 07:12; edited 1 time in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Thu 23 Jun 2011, 06:10    Post subject: API key  

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. Smile

Does that mean that your API key is valid for English and Italiano only Question
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Thu 23 Jun 2011, 06:16    Post subject:  

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)
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Thu 23 Jun 2011, 06:35    Post subject:  

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 ?
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Thu 23 Jun 2011, 06:44    Post subject:  

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:

Quote:
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:

{
"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...
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Thu 23 Jun 2011, 07:01    Post subject: wr-0.0.1 Commandline WordReference Lookup
Subject description: the API gives no access to ALL dictionaries, as stared by their API page
 

Yes, I did read the API page and I cannot suggest anything but changing your Subject description. Cool
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Thu 23 Jun 2011, 07:08    Post subject:  

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.
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sat 25 Jun 2011, 16:23    Post subject: Commandline WordReference Lookup  

I am hoping that you will understand this language Cool
Code:
#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
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: Sun 26 Jun 2011, 08:10    Post subject: Re: Commandline WordReference Lookup  

L18L wrote:
I am hoping that you will understand this language Cool


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:

#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
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0629s ][ Queries: 12 (0.0036s) ][ GZIP on ]