summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2010-11-04 14:06:57 +0000
committerJoe Robinson <joe@lc8n.com>2010-11-04 14:06:57 +0000
commitc50d1cde5c9a18ed7579cf9f5467e668b63371f1 (patch)
treecd958fb739e5cf77f735645a941e4bc85b728d08
parent07cdd1c101d1aa0cb23cb67165b7dcb977a0563a (diff)
Return tech definitions from foldoc. Also fixes extra semicolons
-rw-r--r--bladictionary.java61
1 files changed, 54 insertions, 7 deletions
diff --git a/bladictionary.java b/bladictionary.java
index 82f6ce8..8f887b2 100644
--- a/bladictionary.java
+++ b/bladictionary.java
@@ -40,6 +40,8 @@ public class bladictionary {
Boolean definition = false;
Boolean definition2 = false;
Boolean wn = false;
+ Boolean foldoc = false;
+ int fcount = 0;
String result = "";
//Read every line
while ((line = br.readLine()) != null)
@@ -52,14 +54,29 @@ public class bladictionary {
{
wn = true;
}
-
- if(wn)
+ else if (line.equals("<Id>foldoc</Id>"))
{
+ //Read tech definitions too
+ foldoc = true;
+ if(result.equals(""))
+ {
+ result = result+"tech: ";
+ }
+ else
+ {
+ result = result+"; tech: ";
+ }
+ fcount++;
+ }
+ if(wn||foldoc)
+ {
+
//Look for start of a definition
if (line.contains("<WordDefinition>"))
{
definition = true;
+ definition2 = true;
}
//If we found a definition tag
@@ -68,16 +85,22 @@ public class bladictionary {
//if it's the end of the word definition, stop reading
if(line.contains("</WordDefinition>"))
{
- definition = false;
+ definition = false;
+ wn = false;
+ foldoc = false;
}
else
{
-
+ if(wn)
+ {
if (line.substring(0,2).equals("n ") || line.substring(0,2).equals("v ")
|| line.substring(0,4).equals("adj ") || line.substring(0,4).equals("adv "))
{
+ if(!result.equals(""))
+ {
+ result = result+"; ";
+ }
definition2 = true;
- //System.out.println(line);
}
if(definition2)
@@ -87,13 +110,37 @@ public class bladictionary {
{
parts = line.split("\\[");
- result = result + parts[0] + "; ";
+ result = result + parts[0];
}
else
{
definition2 = false;
}
}
+ }
+ //We only want one of these definitions
+ else if(foldoc && fcount <=1 && !line.equals("")&&definition2)
+ {
+ //Delete bits in <>s, don't need this
+ line = line.replaceAll("&lt;.*?&gt; ","");
+ //Get rid of {}s around words
+ line = line.replaceAll("\\{","");
+ line = line.replaceAll("\\}","");
+
+ //Split it at a . - We only want the first sentence
+ parts=line.split("\\.");
+
+ if(parts.length>1)
+ {
+ definition2 = false;
+ result = result + parts[0];
+ }
+ else
+ {
+ result = result + line;
+ }
+
+ }
}
}
@@ -112,4 +159,4 @@ public class bladictionary {
}
-} \ No newline at end of file
+}