public WordNet(String configPath) { try { JWNL.initialize(this.getClass().getClassLoader().getResourceAsStream(configPath)); dict = Dictionary.getInstance(); } catch (JWNLException e) { e.printStackTrace(); } }
public WordNet() { try { JWNL.initialize(this.getClass().getClassLoader().getResourceAsStream("wordnet_properties.xml")); dict = Dictionary.getInstance(); } catch (JWNLException e) { e.printStackTrace(); } }
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 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; } }
@SuppressWarnings("unchecked") public String[] getLemmas(String word, String tag) { try { POS pos; if (tag.startsWith("N") || tag.startsWith("n")) { pos = POS.NOUN; } else if (tag.startsWith("V") || tag.startsWith("v")) { pos = POS.VERB; } else if (tag.startsWith("J") || tag.startsWith("a")) { pos = POS.ADJECTIVE; } else if (tag.startsWith("R") || tag.startsWith("r")) { pos = POS.ADVERB; } else { pos = POS.NOUN; } List<String> lemmas = morphy.lookupAllBaseForms(pos,word); return lemmas.toArray(new String[lemmas.size()]); } catch (JWNLException e) { e.printStackTrace(); return null; } }
public WordNet(InputStream propertiesStream) { try { JWNL.initialize(propertiesStream); dict = Dictionary.getInstance(); } catch (JWNLException e) { e.printStackTrace(); } }
public String lemmatize(String word,int pos) { IndexWord indexWord; if(Character.isDigit(word.charAt(word.length()-1))) return word; if(pos>Lemmatiser.LASTPOS || pos<Lemmatiser.FIRSTPOS) return word; try{ indexWord = dict.lookupIndexWord(getPOS(pos), word); if (indexWord != null) return indexWord.getLemma(); else return word; } catch(JWNLException ex) { ex.printStackTrace(); return null; } }
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; }
public String lemmatize(String word) { IndexWord indexWord; int i; if(Character.isDigit(word.charAt(word.length()-1))) return word; for(i=Lemmatiser.FIRSTPOS;i<=Lemmatiser.LASTPOS;i++){ try { indexWord = dict.lookupIndexWord(getPOS(i), word); if (indexWord != null) return indexWord.getLemma(); } catch (JWNLException ex) { ex.printStackTrace(); return null; } } return word; }
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 List<String> getAllSynonyms(POS pos, String s) { List<String> synonyms = new ArrayList<>(); try { IndexWord iw = dict.getIndexWord(pos, s); if (iw != null) { Synset[] synsets = iw.getSenses(); for (Synset synset : synsets) { for (Word w : synset.getWords()) { String lemma = w.getLemma(); if (!lemma.equals(s) && !lemma.contains(" ")) { synonyms.add(lemma); } } } } } catch (JWNLException e) { e.printStackTrace(); } return synonyms; }
public String[] getParentSenseKeys(String lemma, String pos, int sense) { //System.err.println("JWNLDictionary.getParentSenseKeys: lemma="+lemma); try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw != null) { Synset synset = iw.getSense(sense+1); List<String> parents = new ArrayList<String>(); getParents(synset,parents); return parents.toArray(new String[parents.size()]); } else { return empty; } } catch (JWNLException e) { e.printStackTrace(); return null; } }
public String[] getParentSenseKeys(String lemma, String pos, int sense) { //System.err.println("JWNLDictionary.getParentSenseKeys: lemma="+lemma); try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw != null) { Synset synset = iw.getSense(sense + 1); List<String> parents = new ArrayList<>(); getParents(synset,parents); return parents.toArray(new String[parents.size()]); } else { return empty; } } catch (JWNLException e) { e.printStackTrace(); return null; } }
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 List<String> getSisterTerms(POS pos, String s) { List<String> sisterTerms = 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(); //System.out.println(synsets[0]); PointerTarget[] pointerArr = synsets[0].getTargets(); } } catch (JWNLException e) { e.printStackTrace(); } return sisterTerms; }
/** * Returns a list of lemmas for the most frequent synset of the given word. * @param word word to get synonyms for * @param pos POS of the word to look up * @return list of lemmas of the most frequent synset */ public List<String> getWordsForFirstSynset(POS pos, String word) { List<String> result = new ArrayList<>(); IndexWord indexWord = null; Synset sense = null; try { indexWord = dict.getIndexWord(pos, word); sense = indexWord.getSense(1); for (Word w : sense.getWords()) { result.add(w.getLemma()); } } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return result; }
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. } }