EventSet eventSet = new EventSet();
PorterStemmerWithIrregularEventDriver port = new PorterStemmerWithIrregularEventDriver();
EventSet tmpevent;
URL url = getClass().getResource(JGAAPConstants.JGAAP_RESOURCE_PACKAGE + "wordnet");
IDictionary dict;
if (url.getProtocol().equalsIgnoreCase("jar")) {
throw new EventGenerationException(
"DefinitionsEventDriver is current not able to run using the jar. Please use ant with the source distrodution.");
} else {
dict = new Dictionary(url);
}
try {
dict.open();
} catch (Exception e) {
logger.error("Could not open WordNet Dictionary " + url, e);
throw new EventGenerationException("DefinitionsEventDriver failed to open WordNet");
}
String current = new String(text);
FastTag tagger = new FastTag();
List<String> words = Lists.newArrayList(Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings()
.split(current));
List<String> tagged = tagger.tag(words);
IIndexWord idxWord;
List<IWordID> wordID;
IWord word;
StringBuilder outDef = new StringBuilder();
for (int i = 0; i < words.size(); i++) {
// System.out.println(i);
String definition = "";
if (table.containsKey(tagged.get(i))) {
if (nouns.containsKey(words.get(i))) {
words.set(i, nouns.get(words.get(i)));
}
try {
switch (table.get(tagged.get(i))) {
case (1):
idxWord = dict.getIndexWord(words.get(i), POS.NOUN);
if (idxWord == null)
break;
wordID = idxWord.getWordIDs();
word = dict.getWord(wordID.get(0));
definition = word.getSynset().getGloss();
break;
case (2):
tmpevent = port.createEventSet(words.get(i).toCharArray());
idxWord = dict.getIndexWord(tmpevent.eventAt(0).toString(), POS.VERB);
if (idxWord == null)
break;
wordID = idxWord.getWordIDs();
word = dict.getWord(wordID.get(0));
definition = word.getSynset().getGloss();
break;
case (3):
idxWord = dict.getIndexWord(words.get(i), POS.ADJECTIVE);
if (idxWord == null)
break;
wordID = idxWord.getWordIDs();
word = dict.getWord(wordID.get(0));
definition = word.getSynset().getGloss();
break;
case (4):
idxWord = dict.getIndexWord(words.get(i), POS.ADVERB);
if (idxWord == null)
break;
wordID = idxWord.getWordIDs();
word = dict.getWord(wordID.get(0));
definition = word.getSynset().getGloss();
break;
}
} catch (IllegalArgumentException e) {