Alas, another 15 years has passed since I’ve last posted. This time it was prompted by a fairly simple need: to lookup a word via the command line. Now, I already had a very simple solution to this using WordNet. That is simple enough:
sudo apt-get install wordnet
Then simply type:
wn hello -over
You should see output similar to this:
Overview of noun hello
The noun hello has 1 sense (first 1 from tagged texts)
1. (1) hello, hullo, hi, howdy, how-do-you-do — (an expression of greeting; “every morning they exchanged polite hellos”)
That’s all well and good, until I typed this:
wn smote -over
And came up empty. Indeed WordNet is useful but it is limited. There are 2 solutions that immediately came to mind.
- Figure out how to get more definitions loaded into my instance of WordNet
- Find a dictionary service that is much more comprehensive than WordNet, and write a client for it
After a couple of quick Google searches I decided on the latter. And, since I’ve been doing a fair amount of Grails work lately, I thought, why not try this in Groovy?
One of those Google searches brought me to http://services.aonaware.com/DictService/. After a few trials with the simple front-end on the page, I was satisfied. Then it was time to find a Groovy example, which I found quickly enough with Groovy WS.
If you look at the code snippet on that page, it is incredibly simple.
@Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.2')
import groovyx.net.ws.WSClient
proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader)
proxy.initialize()
result = proxy.CelsiusToFahrenheit(0)
println "You are probably freezing at ${result} degrees Farhenheit"
I tried this example as is, but seemed to have problems with the annotation at the top. Being rather impatient, I found a Groovy WS Standalone jar here at:
http://snapshots.dist.codehaus.org/groovy/distributions/groovyws/groovyws-standalone-0.5-SNAPSHOT.jar
I dropped it into my $GROOVY_HOME/lib directory, and then removed the annotation from the code. The example worked perfectly.
So, using the WSDL from the service I mentioned earlier, I made a few modifications and named it Pablo.groovy. Why Pablo? Why not? When speed counts, who cares?!
import groovyx.net.ws.WSClient
proxy = new WSClient("http://services.aonaware.com/DictService/DictService.asmx?WSDL", this.class.classLoader)
proxy.initialize()
//Define is a name of the service method, see the service WSDL
result = proxy.Define(args[0])
if(result != null) {
for(defin in result.definitions.definition) {
println "${defin.wordDefinition}"
}
}
I needed to analyze the WSDL to figure out how to interpret the results, but other than that, it was a pleasantly pain-free experience.
Now I type:
groovy Pablo.groovy smote
And I get a much more satisfying result, save the logging garbage at the top!
Jul 18, 2011 5:11:29 PM org.apache.cxf.endpoint.dynamic.DynamicClientFactory outputDebug
INFO: Created classes: com.aonaware.services.webservices.ArrayOfDefinition, com.aonaware.services.webservices.ArrayOfDictionary, com.aonaware.services.webservices.ArrayOfDictionaryWord, com.aonaware.services.webservices.ArrayOfStrategy, com.aonaware.services.webservices.Define, com.aonaware.services.webservices.DefineInDict, com.aonaware.services.webservices.DefineInDictResponse, com.aonaware.services.webservices.DefineResponse, com.aonaware.services.webservices.Definition, com.aonaware.services.webservices.Dictionary, com.aonaware.services.webservices.DictionaryInfo, com.aonaware.services.webservices.DictionaryInfoResponse, com.aonaware.services.webservices.DictionaryList, com.aonaware.services.webservices.DictionaryListExtended, com.aonaware.services.webservices.DictionaryListExtendedResponse, com.aonaware.services.webservices.DictionaryListResponse, com.aonaware.services.webservices.DictionaryWord, com.aonaware.services.webservices.Match, com.aonaware.services.webservices.MatchInDict, com.aonaware.services.webservices.MatchInDictResponse, com.aonaware.services.webservices.MatchResponse, com.aonaware.services.webservices.ObjectFactory, com.aonaware.services.webservices.ServerInfo, com.aonaware.services.webservices.ServerInfoResponse, com.aonaware.services.webservices.Strategy, com.aonaware.services.webservices.StrategyList, com.aonaware.services.webservices.StrategyListResponse, com.aonaware.services.webservices.WordDefinition
Jul 18, 2011 5:11:30 PM groovyx.net.ws.AbstractCXFWSClient getBindingOperationInfo
WARNING: Using SOAP version: 1.1
Smite \Smite\ (sm[imac]t), v. t. [imp. {Smote} (sm[=o]t), rarely
{Smit} (sm[i^]t); p. p. {Smitten} (sm[i^]t”t’n), rarely
{Smit}, or {Smote}; p. pr. & vb. n. {Smiting}
(sm[imac]t”[i^]ng).] [AS. sm[=i]tan to smite, to soil,
pollute; akin to OFries. sm[=i]ta to smite, LG. smiten, D.
smijten, G. schmeissen, OHG. sm[=i]zan to smear, stroke, OSw.
& dial. Sw. smita to smite, Dan. smide to throw, Goth.
bismeitan, to anoint, besmear; cf. Skr. m[=e]d to be fat. The
original sense seems to have been, to daub on, to smear. Cf.
{Smut}.]
1. To strike; to inflict a blow upon with the hand, or with
any instrument held in the hand, or with a missile thrown
by the hand; as, to smite with the fist, with a rod,
sword, spear, or stone.
[1913 Webster]
Now to smote the logging and be rid of it; simply adding these few lines will do:
import java.util.logging.Level
import java.util.logging.LogManager
LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE)
Now the output is as tidy as I want it to be for now.
$ groovy Pablo.groovy smote
Smite \Smite\ (sm[imac]t), v. t. [imp. {Smote} (sm[=o]t), rarely
{Smit} (sm[i^]t); p. p. {Smitten} (sm[i^]t”t’n), rarely
{Smit}, or {Smote}; p. pr. & vb. n. {Smiting}
(sm[imac]t”[i^]ng).] [AS. sm[=i]tan to smite, to soil,
pollute; akin to OFries. sm[=i]ta to smite, LG. smiten, D.
smijten, G. schmeissen, OHG. sm[=i]zan to smear, stroke, OSw.
& dial. Sw. smita to smite, Dan. smide to throw, Goth.
bismeitan, to anoint, besmear; cf. Skr. m[=e]d to be fat. The
original sense seems to have been, to daub on, to smear. Cf.
{Smut}.]
1. To strike; to inflict a blow upon with the hand, or with
any instrument held in the hand, or with a missile thrown
by the hand; as, to smite with the fist, with a rod,
sword, spear, or stone.
[1913 Webster]
Whosoever shall smite thee on thy right cheek, turn
to him the other also. –Matt. v. 39.
[1913 Webster]
And David . . . took thence a stone, and slang it,
and smote the Philistine in his forehead. –1 Sam.
xvii. 49.
[1913 Webster]
2. To cause to strike; to use as an instrument in striking or
hurling.
[1913 Webster]
Prophesy, and smite thine hands together. –Ezek.
xxi. 14.
[1913 Webster]
Saul . . . smote the javelin into the wall. –1 Sam.
xix. 10.
[1913 Webster]
3. To destroy the life of by beating, or by weapons of any
kind; to slay by a blow; to kill; as, to smite one with
the sword, or with an arrow or other instrument.
[1913 Webster]
4. To put to rout in battle; to overthrow by war.
[1913 Webster]
5. To blast; to destroy the life or vigor of, as by a stroke
or by some visitation.
[1913 Webster]
The flax and the barly was smitten. –Ex. ix. 31.
[1913 Webster]
6. To afflict; to chasten; to punish.
[1913 Webster]
Let us not mistake God’s goodness, nor imagine,
because he smites us, that we are forsaken by him.
–Wake.
[1913 Webster]
7. To strike or affect with passion, as love or fear.
[1913 Webster]
The charms that smite the simple heart. –Pope.
[1913 Webster]
Smit with the love of sister arts we came. –Pope.
[1913 Webster]
{To smite off}, to cut off.
{To smite out}, to knock out, as a tooth. –Exod. xxi. 27.
{To smite with the tongue}, to reproach or upbraid; to
revile. [Obs.] –Jer. xviii. 18.
[1913 Webster]
Smite \Smite\ (sm[imac]t), v. t. [imp. {Smote} (sm[=o]t), rarely
{Smit} (sm[i^]t); p. p. {Smitten} (sm[i^]t”t’n), rarely
{Smit}, or {Smote}; p. pr. & vb. n. {Smiting}
(sm[imac]t”[i^]ng).] [AS. sm[=i]tan to smite, to soil,
pollute; akin to OFries. sm[=i]ta to smite, LG. smiten, D.
smijten, G. schmeissen, OHG. sm[=i]zan to smear, stroke, OSw.
& dial. Sw. smita to smite, Dan. smide to throw, Goth.
bismeitan, to anoint, besmear; cf. Skr. m[=e]d to be fat. The
original sense seems to have been, to daub on, to smear. Cf.
{Smut}.]
1. To strike; to inflict a blow upon with the hand, or with
any instrument held in the hand, or with a missile thrown
by the hand; as, to smite with the fist, with a rod,
sword, spear, or stone.
[1913 Webster]
Whosoever shall smite thee on thy right cheek, turn
to him the other also. –Matt. v. 39.
[1913 Webster]
And David . . . took thence a stone, and slang it,
and smote the Philistine in his forehead. –1 Sam.
xvii. 49.
[1913 Webster]
2. To cause to strike; to use as an instrument in striking or
hurling.
[1913 Webster]
Prophesy, and smite thine hands together. –Ezek.
xxi. 14.
[1913 Webster]
Saul . . . smote the javelin into the wall. –1 Sam.
xix. 10.
[1913 Webster]
3. To destroy the life of by beating, or by weapons of any
kind; to slay by a blow; to kill; as, to smite one with
the sword, or with an arrow or other instrument.
[1913 Webster]
4. To put to rout in battle; to overthrow by war.
[1913 Webster]
5. To blast; to destroy the life or vigor of, as by a stroke
or by some visitation.
[1913 Webster]
The flax and the barly was smitten. –Ex. ix. 31.
[1913 Webster]
6. To afflict; to chasten; to punish.
[1913 Webster]
Let us not mistake God’s goodness, nor imagine,
because he smites us, that we are forsaken by him.
–Wake.
[1913 Webster]
7. To strike or affect with passion, as love or fear.
[1913 Webster]
The charms that smite the simple heart. –Pope.
[1913 Webster]
Smit with the love of sister arts we came. –Pope.
[1913 Webster]
{To smite off}, to cut off.
{To smite out}, to knock out, as a tooth. –Exod. xxi. 27.
{To smite with the tongue}, to reproach or upbraid; to
revile. [Obs.] –Jer. xviii. 18.
[1913 Webster]
Smote \Smote\,
imp. (& rare p. p.) of {Smite}.
[1913 Webster]
smite
v 1: inflict a heavy blow on, with the hand, a tool, or a weapon
2: affect suddenly with deep feeling; “He was smitten with love
for this young girl”
3: cause pain or suffering in; “afflict with the plague”; “That
debasement of the verbal currency that afflicts terms used
in advertisement” [syn: {afflict}]
[also: {smote}, {smitten}, {smit}]
smote
See {smite}
The results are lengthy, but for right now, it’s all that I want. And nay, I shan’t complain!
It was quick and easy, and as long as I use it less than several thousand times per day, I am operating well within the terms of service.
Till next time!