From c50d1cde5c9a18ed7579cf9f5467e668b63371f1 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 4 Nov 2010 14:06:57 +0000 Subject: Return tech definitions from foldoc. Also fixes extra semicolons --- bladictionary.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 7 deletions(-) (limited to 'bladictionary.java') 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("foldoc")) { + //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("")) { 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("")) { - 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("<.*?> ",""); + //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 +} -- cgit v1.2.3