/** * @param words * @param wordToLookup * @return */ private Word lookupWordInWords(Word[] words, String wordToLookup) { boolean found = false; Word someWord = null; for (int i = 0; i < words.length && !found; i++) { someWord = words[i]; found = someWord.getLemma().equalsIgnoreCase(wordToLookup); } return someWord; } }
/** returns all the pointers of the synset that contains this word whose source is this word */ public Pointer[] getPointers() { Pointer[] source = getSynset().getPointers(); List list = new ArrayList(source.length); for (int i = 0; i < source.length; ++i) { Pointer pointer = source[i]; if (this.equals(pointer.getSource())) list.add(pointer); } return (Pointer[]) list.toArray(new Pointer[list.size()]); } }
public long getUsageOf(String word) throws WordNetException { long ret = 0; Word[] wordsOfSynset = this.realSynset.getWords(); for (Word wordOfSynset : wordsOfSynset) { if (wordOfSynset.getLemma().equals(word)) { ret = wordOfSynset.getUsageCount(); } } return ret; }
/** * Ctor with an {@link Word} and a dictionary * This Ctor is quicker than the other. * @param jwiDictionary * @throws WordNetException */ JwnlSensedWord(Word objWord, JwnlDictionary jwnlDictionary) throws WordNetException { this.wordObj = objWord; this.synset = new JwnlSynset(jwnlDictionary, objWord.getSynset()); this.word = objWord.getLemma(); this.dictionary = jwnlDictionary; this.pos = JwnlUtils.getWordNetPartOfSpeech( wordObj.getPOS()); }
for(int i=0;i<words.length;i++){ w = words[i]; syn = w.getLemma(); pos = w.getPOS(); for(int j=0;j<words.length;j++){ w = words[j]; lemma = w.getLemma(); pos = w.getPOS(); if(lemma.contains("_")){ String[] parts = lemma.split("_"); lemma = w.getLemma(); pos = w.getPOS(); if(lemma.contains("_")){ String[] parts = lemma.split("_");
IndexWord word = dictionary.lookupIndexWord(POS.NOUN, exampleWord); List<Synset> synset=word.getSenses(); int nums = word.sortSenses(); // for each sense of the word for ( Synset syn : synset) { // get the synonyms of the sense PointerTargetTree s = PointerUtils.getSynonymTree(syn, 2 /*depth*/); List<PointerTargetNodeList> l = s.toList(); for (PointerTargetNodeList nl : l) { for (PointerTargetNode n : nl) { Synset ns = n.getSynset(); if (ns!=null) { List<Word> ws = ns.getWords(); for (Word ww : ws) { // ww.getUseCount() is the frequency of occurance as reported by wordnet engine println(ww.getLemma(), ww.getUseCount()); } } } } }
/** * Ctor * @param synset * @param strWord * @throws WordNetException */ public JwnlSensedWord(JwnlSynset synset, String strWord) throws WordNetException { this.synset = synset; this.word = strWord; String wordToLookup = strWord.replace(' ', '_'); // mimic jwnl, which replaces underscores with spaces when looking up Word[] words = synset.realSynset.getWords(); Word wordObj = lookupWordInWords(words, wordToLookup); if (wordObj == null) throw new WordNetException("\""+ strWord + "\" is not a memeber of the given synset " + synset); this.wordObj = wordObj; dictionary = synset.jwnlDictionary; this.pos = JwnlUtils.getWordNetPartOfSpeech( wordObj.getPOS()); }
/** * If the target is a synset, return it, otherwise it's a word * so return the word's parent synset. */ public Synset getSynset() { if (isLexical()) { return ((Word)_target).getSynset(); } else { return (Synset)_target; } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; JwnlSensedWord other = (JwnlSensedWord) obj; if (wordObj == null) { if (other.wordObj != null) return false; } else if (!wordObj.equals(other.wordObj)) return false; return true; }
protected Word createWord(Synset synset, int index, String lemma) { if (synset.getPOS().equals(POS.VERB)) { return new MutableVerb(synset, index, lemma); } else { return new Word(synset, index, lemma); } }
ret.add(new WordAndUsage(word.getLemma(), word.getUsageCount()));
/** * Get the synset that is a) the target of this pointer, or b) the * synset that contains the target of this pointer. */ public Synset getTargetSynset() throws JWNLException { PointerTarget target = getTarget(); if (target instanceof Word) { return ((Word) target).getSynset(); } else { return (Synset) target; } }
protected Word createWord(Synset synset, int index, String lemma) { if (synset.getPOS().equals(POS.VERB)) { return new MutableVerb(synset, index, lemma); } else { return new Word(synset, index, lemma); } }
private void addSynonymFeature(Set<String> f1, Synset synset, WordNetFeatureClass name, String key) { if (featureClasses.contains(name)) { for (Word w : synset.getWords()) f1.add(key + w.getLemma()); } }
private void addSynonymFeature(Set<String> f1, Synset synset, WordNetFeatureClass name, String key) { if (featureClasses.contains(name)) { for (Word w : synset.getWords()) f1.add(key + w.getLemma()); } }
public Set<String> getWords() throws WordNetException { if (words == null) { words = new HashSet<String>(); for (Word word : this.realSynset.getWords()) { String lemma = word.getLemma(); lemma = lemma.replaceAll("_", " "); // clean words.add(lemma); } } return new HashSet<String>(words); // return a copy }
public static Set<String> getLemmas(final String synsetID) { final Set<String> lemmas = Sets.newLinkedHashSet(); final Synset synset = getSynset(synsetID); if (synset != null) { for (final Word word : synset.getWords()) { lemmas.add(word.getLemma()); } } return lemmas; }