summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2010-10-31 23:10:21 +0000
committerJoe Robinson <joe@lc8n.com>2010-10-31 23:10:21 +0000
commit1e27bc809711659757f8f4a94858d4a42f284def (patch)
tree46bf02aceaac3c324d6a5daa051569ed8d5b3a9a
Initial commit. Takes 1 argument and outputs 1 result of each word type (noun,verb,adjective,adverb)
-rw-r--r--bladictionary.java105
1 files changed, 105 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ Copyright 2010 Joe Robinson <joe@lc8n.com>
+*/
+
+
+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("<Id>wn</Id>"))
+ {
+ wn = true;
+ }
+
+ if(wn)
+ {
+
+ //Look for start of a definition
+ if (line.contains("<WordDefinition>"))
+ {
+ 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("</WordDefinition>"))
+ {
+ 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