From 1e27bc809711659757f8f4a94858d4a42f284def Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 31 Oct 2010 23:10:21 +0000 Subject: Initial commit. Takes 1 argument and outputs 1 result of each word type (noun,verb,adjective,adverb) --- bladictionary.java | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 bladictionary.java (limited to 'bladictionary.java') diff --git a/bladictionary.java b/bladictionary.java new file mode 100644 index 0000000..9f177af --- /dev/null +++ b/bladictionary.java @@ -0,0 +1,105 @@ +/* + 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[] defLines = new String[50]; + int i = 0; + //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("\\["); + System.out.println(parts[0]); + } + else + { + definition2 = false; + } + } + + } + } + } + } + } + +} \ No newline at end of file -- cgit v1.2.3