/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/*
Copyright 2010 Joe Robinson
*/
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class bladictionary {
public static void main(String[] args) throws IOException
{
String query = args[0];
String[] parts = null;
//URL which provides XML response
URL url = new URL("http://services.aonaware.com/DictService/DictService.asmx/Define?word="+query);
URLConnection urlc = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String line;
Boolean definition = false;
Boolean definition2 = false;
Boolean wn = false;
String result = "";
//Read every line
while ((line = br.readLine()) != null)
{
//Get rid of whitespace before/after
line = line.trim();
//only read WordNet definitions
if (line.equals("wn"))
{
wn = true;
}
if(wn)
{
//Look for start of a definition
if (line.contains(""))
{
definition = true;
}
//If we found a definition tag
else if (definition)
{
//if it's the end of the word definition, stop reading
if(line.contains(""))
{
definition = false;
}
else
{
if (line.substring(0,1).equals("n") || line.substring(0,1).equals("v")
|| line.substring(0,3).equals("adj") || line.substring(0,3).equals("adv"))
{
definition2 = true;
//System.out.println(line);
}
if(definition2)
{
if(Character.isLetter(line.charAt(0)))
{
parts = line.split("\\[");
if (result.equals(""))
{
result = parts[0];
}
else
{
result = result + "; "+ parts[0];
}
}
else
{
definition2 = false;
}
}
}
}
}
}
if(!result.equals(""))
{
System.out.println(result);
System.exit(0);
}
else
{
System.exit(1);
}
}
}