public int getWordsSize() { return getWords().length; }
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()); } }
@Override public List<SensedWord> getAllSensedWords() throws WordNetException { Word[] objWords = realSynset.getWords(); List<SensedWord> sensedWords = new ArrayList<SensedWord>(objWords.length); for ( Word word : objWords) new JwnlSensedWord(word, this.jwnlDictionary); return sensedWords; }
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 Word[] getWords() { return getSource().getWords(); }
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; }
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 List<String> getBestSynonyms(POS pos, String s) { List<String> synonyms = new ArrayList<>(); try { IndexWord iw = dict.getIndexWord(pos, s);//dict.getMorphologicalProcessor().lookupBaseForm(pos, s) // IndexWord iw = dict.getMorphologicalProcessor().lookupBaseForm(pos, 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(" ") && synonyms.size() < 4) { synonyms.add(c); } } } } catch (JWNLException e) { e.printStackTrace(); } return synonyms; }
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 * @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()); }
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 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()); } } } } }