/** * @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; } }
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; }
/** Returns true if <code>lemma</code> is one of the words contained in this synset.*/ public boolean containsWord(String lemma) { for (int i = 0; i < getWordsSize(); i++) { if (getWord(i).getLemma().equals(lemma)) return true; } return false; }
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; }
private void addRelatedWordsFeatures(Set<String> f1, Synset synset, PointerType type, WordNetFeatureClass name, String key) throws JWNLException { if (featureClasses.contains(name)) { Pointer[] pointers = synset.getPointers(type); for (Pointer p : pointers) { Synset target = p.getTargetSynset(); for (Word w : target.getWords()) { f1.add(key + w.getLemma()); } } } }
private void addRelatedWordsFeatures(Set<String> f1, Synset synset, PointerType type, WordNetFeatureClass name, String key) throws JWNLException { if (featureClasses.contains(name)) { Pointer[] pointers = synset.getPointers(type); for (Pointer p : pointers) { Synset target = p.getTargetSynset(); for (Word w : target.getWords()) { f1.add(key + w.getLemma()); } } } }
public synchronized List<String> getSynonyms(String word, POS pos, boolean firstOnly) throws JWNLException { List<String> syns = new ArrayList<>(); IndexWord indexWord = getIndexWord(pos, word); if (indexWord == null) return syns; for (Synset synset : indexWord.getSenses()) { for (Word w : synset.getWords()) { syns.add(w.getLemma()); } if (firstOnly) break; } return syns; }
public synchronized List<String> getSynonyms(String word, POS pos, boolean firstOnly) throws JWNLException { List<String> syns = new ArrayList<>(); IndexWord indexWord = getIndexWord(pos, word); if (indexWord == null) return syns; for (Synset synset : indexWord.getSenses()) { for (Word w : synset.getWords()) { syns.add(w.getLemma()); } if (firstOnly) break; } return syns; }
public List<String> getAttributes(String s) { List<String> result = new ArrayList<>(); try { IndexWord iw = dict.getIndexWord(POS.ADJECTIVE, s); if (iw != null) { Synset[] synsets = iw.getSenses(); Word[] words = synsets[0].getWords(); for (Word w : words) { String c = w.getLemma(); if (!c.equals(s) && !c.contains(" ") && result.size() < 4) { result.add(c); } } } } catch (JWNLException e) { e.printStackTrace(); } return result; }
public String toString() { if (_cachedToString == null) { StringBuffer words = new StringBuffer(); for (int i = 0; i < getWordsSize(); ++i) { if (i > 0) words.append(", "); words.append(getWord(i).getLemma()); } if (getGloss() != null) words.append(" -- (" + getGloss() + ")"); _cachedToString = JWNL.resolveMessage("DATA_TOSTRING_009", new Object[]{new Long(getOffset()), getPOS(), words.toString()}); } return _cachedToString; }
public String toString() { if (_cachedToString == null) { Object[] params = new Object[]{getPOS(), getLemma(), getSynset(), new Integer(getIndex())}; _cachedToString = JWNL.resolveMessage("DATA_TOSTRING_005", params); } return _cachedToString; }
public synchronized List<String> getRelatedWords(String word, POS pos, PointerType type, boolean firstOnly) throws JWNLException { List<String> syns = new ArrayList<>(); IndexWord indexWord = getIndexWord(pos, word); if (indexWord == null) return syns; for (Synset synset : indexWord.getSenses()) { Pointer[] pointers = synset.getPointers(type); for (Pointer p : pointers) { Synset target = p.getTargetSynset(); for (Word w : target.getWords()) { syns.add(w.getLemma()); } } if (firstOnly) break; } return syns; }
public synchronized List<String> getRelatedWords(String word, POS pos, PointerType type, boolean firstOnly) throws JWNLException { List<String> syns = new ArrayList<>(); IndexWord indexWord = getIndexWord(pos, word); if (indexWord == null) return syns; for (Synset synset : indexWord.getSenses()) { Pointer[] pointers = synset.getPointers(type); for (Pointer p : pointers) { Synset target = p.getTargetSynset(); for (Word w : target.getWords()) { syns.add(w.getLemma()); } } if (firstOnly) break; } return syns; }
/** * 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()); }
public void getHyponymsRecursive(List<String> lemmas, Synset sense, int depthToGo) { for (Word w : sense.getWords()) { lemmas.add(w.getLemma()); } if (depthToGo == 0) { return; } try { PointerTargetNodeList directHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); for (Object directHyponym : directHyponyms) { getHyponymsRecursive(lemmas, ((PointerTargetNode) directHyponym).getSynset(), depthToGo - 1); } } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
public void getHyponymsScoredRecursive(List<LemmaScorePair> lemmas, Synset sense, int depthToGo, double score) { for (Word w : sense.getWords()) { lemmas.add(new LemmaScorePair(w.getLemma(), score)); } if (depthToGo == 0) { return; } try { PointerTargetNodeList directHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); for (Object directHyponym : directHyponyms) { getHyponymsScoredRecursive(lemmas, ((PointerTargetNode) directHyponym).getSynset(), depthToGo - 1, score * HYPONYM_FACTOR); } } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
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()); } } } } }