public int compareTo(Word other) { return word.compareTo(other.getWord()); }
public void removeWord(String inputWord) { for (Word z : wordlist) { if (z.getWord().equals(inputWord)) { wordlist.remove(z); System.out.println("the word" + inputWord + "is removed"); break; } } System.out.println(wordlist.size()); }
public class Word implements Comparable<Word> { private String word; private TreeSet<Word> synonyms; //getter and setter public void addSynonym(final Word word) { synonyms.add(word); } @Override public int compareTo(final Word other) { if (this.word == null) { return -1; if (other == null || other.getWord() == null) { return 1; } return this.word.compareTo(other.getWord()); } }
public static void main(String[] args) { List<Word> freq = histogram("a brown cat eats a white cat."); for (Word word : freq) { System.out.printf("%4d %s\n", word.getFrequency(), word.getWord()); } } }
public Word put(Word s) { for (Word w : al) { if (w.s.compareTo(s.getWord()) == 0) { w.setfrequency(); // found it, now stop searching return w; } } // didn't find it; insert al.add(s); return s; }
public Word put(Word s) { if (al.contains(s)) { for (Word w : al) { if (w.s.compareTo(s.getWord()) == 0) { s.setfrequency(); }// else { //Remove this else, as you add element outside // al.add(s); //} } } else al.add(s); return s; }
List<Word> ordered = new ArrayList<Word>(histo.values()); Collections.sort(ordered, new Comparator<Word>() { public int compare(Word a, Word b) { int fa = a.getFrequency(); int fb = b.getFrequency(); if (fa < fb) return 1; if (fa > fb) return -1; return a.getWord().compareTo(b.getWord()); } }); return ordered; }
public class WordContainer { public static ArrayList<Word> al = new ArrayList<Word>(); public Word put(Word s) { for (Word w : al) { if (w.s.compareTo(s.getWord()) == 0) { //s.setfrequency(); w.setfrequency(); // <-- set frequency of existing word in al return w; // <-- return word object that is in al } // no need to add new word to list after every failed comparison // unless that's what you want to do. } al.add(s); return s; }
public void spellingError(SpellCheckEvent event) { @SuppressWarnings("unchecked") List<Word> suggestions = (List<Word>) event.getSuggestions(); if (suggestions.size() > 0) { Iterator<Word> suggestedWord = suggestions.iterator(); if (suggestedWord.hasNext()) { String orig = event.getInvalidWord(); String sugg = suggestedWord.next().getWord(); if (_correctionType == SpellCorrectionType.Add) event.replaceWord(sugg + " ( " + orig + " ) ", false); else if (_correctionType == SpellCorrectionType.Replace) event.replaceWord(sugg, false); } } }
JPopupMenu jpm = new JPopupMenu(); for (final Word s : l ) { JMenuItem jmi=new JMenuItem(s.getWord()); jpm.add(jmi); final int f_pos=pos;
String suggestionString = suggestion.getWord(); int cost = suggestion.getCost();
String suggestionString = suggestion.getWord(); int cost = suggestion.getCost();