private void demonstrateListOperation(IndexWord word) throws JWNLException { // Get all of the hypernyms (parents) of the first sense of <var>word</var> PointerTargetNodeList hypernyms = PointerUtils.getInstance().getDirectHypernyms(word.getSense(1)); System.out.println("Direct hypernyms of \"" + word.getLemma() + "\":"); hypernyms.print(); }
public synchronized Synset[] getAllSenses(String word, POS pos) throws JWNLException { IndexWord iw = getIndexWord(pos, word); if (iw == null) return new Synset[0]; else return iw.getSenses(); }
public int getNumSenses(String lemma, String pos) { try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw == null){ return 0; } return iw.getSenseCount(); } catch (JWNLException e) { return 0; } }
/** Get an array of all the senses of this word.*/ public Synset[] getSenses() throws JWNLException { if (!_synsetsLoaded) { for (int i = 0; i < getSynsetOffsets().length; ++i) loadSynset(i); _synsetsLoaded = true; } return _synsets; }
/** * Looks at whether the target word is one of the words in one of the synsets * of the source word. * @return int the sense of the source word that contains the target word */ public int getImmediateRelationship(IndexWord sourceWord, IndexWord targetWord) throws JWNLException { Synset[] senses = sourceWord.getSenses(); String lemma = targetWord.getLemma(); for (int i = 0; i < senses.length; i++) { if (senses[i].containsWord(lemma)) { return i + 1; } } return -1; }
public Object getKey() { return getLemma(); }
public List<String> getHyponyms(POS pos, String s) { ArrayList<String> result = new ArrayList<>(); try { IndexWord word = dict.getIndexWord(pos, s); if (word == null) { System.err.println("Unable to find index word for " + s); return result; } Synset sense = word.getSense(1); getHyponymsRecursive(result, sense, 3); } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return result; }
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()); } } } } }
public String getSenseKey(String lemma, String pos,int sense) { try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw == null) { return null; } return String.valueOf(iw.getSynsetOffsets()[sense]); } catch (JWNLException e) { e.printStackTrace(); return null; } }
/** Add an IndexWord to this set */ public void add(IndexWord word) { _indexWords.put(word.getPOS(), word); }
public synchronized String getLemma(String word, POS pos) throws JWNLException { IndexWord iw = getIndexWord(pos, word); if (iw == null) return word; else return iw.getLemma(); }
public List<LemmaScorePair> getHyponymsScored(POS pos, String s) { ArrayList<LemmaScorePair> result = new ArrayList<>(); try { IndexWord word = dict.getIndexWord(pos, s); if (word == null) { System.err.println("Unable to find index word for " + s); return result; } Synset sense = word.getSense(1); getHyponymsScoredRecursive(result, sense, 3, SYNONYM_FACTOR); } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return result; }
public String getSenseKey(String lemma, String pos,int sense) { try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw == null) { return null; } return String.valueOf(iw.getSynsetOffsets()[sense]); } catch (JWNLException e) { e.printStackTrace(); return null; } }
public synchronized POS[] getPOS(String s) throws JWNLException { // Look up all IndexWords (an IndexWord can only be one POS) IndexWordSet set = wordnet.lookupAllIndexWords(s); // Turn it into an array of IndexWords IndexWord[] words = set.getIndexWordArray(); // Make the array of POS POS[] pos = new POS[words.length]; for (int i = 0; i < words.length; i++) { pos[i] = words[i].getPOS(); } return pos; }
private void demonstrateTreeOperation(IndexWord word) throws JWNLException { // Get all the hyponyms (children) of the first sense of <var>word</var> PointerTargetTree hyponyms = PointerUtils.getInstance().getHyponymTree(word.getSense(1)); System.out.println("Hyponyms of \"" + word.getLemma() + "\":"); hyponyms.print(); }
protected List<Synset> indexWordToList(net.didion.jwnl.data.IndexWord indexWord) throws JWNLException { List<Synset> ret = null; if (indexWord!=null) { if (indexWord.getSenses()!=null) { ret = new ArrayList<Synset>(indexWord.getSenses().length); for (net.didion.jwnl.data.Synset jwnlRealSynset : indexWord.getSenses()) { ret.add(new JwnlSynset(this, jwnlRealSynset)); } } } if (null==ret) ret = new ArrayList<Synset>(); return ret; }