public static void main(String[] args) { ParseEssay p = new ParseEssay(); ArrayList<Word> sent = new ArrayList<Word>(); sent.add(new Word("These", "o")); // fake POS o and p sent.add(new Word("are", "o")); sent.add(new Word("balls", "p")); ArrayList<String> pars = new ArrayList<String>(); pars.add("p"); System.out.println(p.overhaulSentence(sent, pars)); }
private String findSynonym(ArrayList<Word> sentence, int indexToReplace /*<Word wordIn>*/) { /** * Takes in one String of a word, hopefully only one word(will truncate after space), and * searches for a suitable synonym * * <p>* */ String output = ""; // String word; // word=wordIn.getString(); String word = sentence.get(indexToReplace).getValue(); Synset[] synsets = database.getSynsets(word); synonyms.clear(); if (synsets.length > 0) { for (int i = 0; i < synsets.length; i++) { String[] wordForms = synsets[i].getWordForms(); for (int j = 0; j < wordForms.length; j++) { if (wordForms[j].contains(" ")) { System.out.println(wordForms[j]); } else if (!wordForms[j].equals(word)) synonyms.add(wordForms[j]); } } // FIND IF PLURAL OR NO HERE /////////////////////////// ###########################//////////////////// Collections.sort(synonyms, myLengthComparator); // synonyms is now sorted as longest first // now we have a list of all the terms that can replace the word. // We need to check them in the lexical analyzer // System.out.println("kkkk"); if (synonyms.size() == 0) return word; while (!LexicalAnalyzer(sentence, indexToReplace, synonyms.get(0))) { // System.out.println("1"); synonyms.remove(0); if (synonyms.size() == 0) return word; // did not find synonym if (synonyms.get(0).length() <= word.length()) { return word; // do not replace word, synonyms are shorter } } ////////////// ############# PLACEHOLDER CODE if (synonyms.size() > 0) output = synonyms.get(0); else output = word; ///////////// ################# PLACEHOLDER CODE } else { // There are no other known synonyms in our wordnet database. output = word; } return output; }