private void getHyperRecursive(HashSet<String> seen, IWord word, int hyperDepth, int dist) { if (dist > hyperDepth) return; List<ISynsetID> hypernyms = word.getSynset().getRelatedSynsets ( Pointer.HYPERNYM ); List <IWord> hw; for( ISynsetID sid : hypernyms ){ hw = mDict.getSynset(sid).getWords(); for(Iterator <IWord > i = hw.iterator (); i. hasNext () ;){ IWord relWord = i.next(); String wstr = printableName(relWord, mUseLexFileName); if (seen.contains(wstr)) continue; seen.add(wstr); getHyperRecursive(seen, relWord, hyperDepth,dist+1); } } }
Map<IPointer, List<ISynsetID>> oldIDs = old.getRelatedMap(); Map<IPointer, List<ISynsetID>> newIDs = new HashMap<IPointer, List<ISynsetID>>(oldIDs.size()); for(ISynsetID otherID : entry.getValue()){ otherSynset = synsets.get(otherID.getPOS()).get(otherID); newList.add(otherSynset.getID()); List<IWord> oldWords = old.getWords(); List<IWordBuilder> newWords = new ArrayList<IWordBuilder>(oldWords.size()); for(IWord oldWord : old.getWords()) newWords.add(new WordBuilder(old, oldWord)); return new Synset(old.getID(), old.getLexicalFile(), old.isAdjectiveSatellite(), old.isAdjectiveHead(), old.getGloss(), newWords, newIDs);
/** * Constructs a new sense key. * * @param lemma * the lemma for the sense key * @param lexID * the lexical id of the sense key * @param synset * the synset for the sense key * @throws NullPointerException * if either the lemma or synset is <code>null</code> * @since JWI 2.1.0 */ public SenseKey(String lemma, int lexID, ISynset synset){ this(lemma, lexID, synset.getPOS(), synset.isAdjectiveSatellite(), synset.getLexicalFile()); }
public static String printableName(IWord word, boolean bUseLexFileName) { ISynset syn = word.getSynset(); StringBuilder sb = new StringBuilder(); sb.append(word.getLemma()); sb.append(NAME_PART_SEP); sb.append(syn.getPOS().getTag()); sb.append(NAME_PART_SEP); // This is the sense number or name if (bUseLexFileName) sb.append(syn.getLexicalFile().getName().toLowerCase()); else sb.append(syn.getLexicalFile().getNumber()); sb.append(NAME_PART_SEP); sb.append(word.getLexicalID()); String res = sb.toString(); return res.replaceAll("[_]", NAME_PART_SEP); }
public Set<String> getWords() throws WordNetException { Set<String> ret = new HashSet<String>(); for (IWord word : this.realSynset.getWords()) { ret.add(word.getLemma()); } return ret; }
/** * get all the synsets that are at the end of a 'relation' type path of length 'degree' from any one of the given synsetIDs. We don't care that these paths * be minimal * @param remoteHypernymIDs * @param relation must be a transitive relation like hypernym or hyponym * @param degree * @return */ private Set<ISynsetID> findRelatedSynsetsAtLooseDistance( Set<ISynsetID> remoteHypernymIDs, Pointer relation, int degree) { Set<ISynsetID> neighborIDs = remoteHypernymIDs; for(int depth = 0; depth < degree; depth++) { Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>(); for (ISynsetID neighborID : neighborIDs) { ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID); for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation)) secondaryNeighborIDs.add(secondaryNeighborID); } neighborIDs = secondaryNeighborIDs; } return neighborIDs; }
if(!synset.isAdjectiveSatellite()) return; for(ISynsetID simID : synset.getRelatedSynsets(Pointer.SIMILAR_TO)){ headSynset = getSynset(simID); if(headSynset.isAdjectiveHead()){ headWord = headSynset.getWords().get(0); break; for(IWord word : synset.getWords()){ if(word.getSenseKey().needsHeadSet()) word.getSenseKey().setHead(headLemma, headWord.getLexicalID());
public String getGloss() throws WordNetException { return this.realSynset.getGloss(); }
public long getOffset() { return realSynset.getOffset(); }
/** * Ctor * @param synset * @param word * @throws WordNetException */ public JwiSensedWord(JwiSynset synset, String word) throws WordNetException { this.synset = synset; this.word = word; String wordToLookup = word.replace(' ', '_'); // mimic jwnl, which replaces underscores with spaces when looking up IWord iWord = null; boolean found = false; for (int i = 1; i <= synset.realSynset.getWords().size() && !found; i++) { iWord = synset.realSynset.getWord(i); found = iWord.getLemma().equalsIgnoreCase(wordToLookup); } if (!found) throw new WordNetException("\""+ word + "\" is not a memeber of the given synset " + synset); this.iWord = iWord; dictionary = synset.jwiDictionary; this.pos = JwiUtils.getWordNetPartOfSpeech(iWord.getPOS()); }
public void getAllSemanticRelations(ISynset s) { Map<IPointer, List<ISynsetID>> map = s.getRelatedMap(); Set<Entry<IPointer, List<ISynsetID>>> x = map.entrySet(); for (Entry<IPointer, List<ISynsetID>> y : x) { System.out.println(y.getKey()); List<ISynsetID> lis = y.getValue(); for (ISynsetID id : lis) { ISynset syn = dict.getSynset(id); System.out.println("\t" + syn); } } }
/** * @param iSynsets * @param degree * @return */ private Set<ISynsetID> computeRemoteCousinSynsetIDs(ISynset[] iSynsets, int degree) { Set<ISynsetID> synsetIDs = new HashSet<ISynsetID>(); for (ISynset synset : iSynsets) synsetIDs.add(synset.getID()); Set<ISynsetID> remoteHypernymIDs = findRelatedSynsetsAtLooseDistance(synsetIDs, Pointer.HYPERNYM, degree); Set<ISynsetID> remoteCousinSynsetIDs = findRelatedSynsetsAtLooseDistance(remoteHypernymIDs, Pointer.HYPONYM, degree); remoteCousinSynsetIDs.removeAll(synsetIDs); // the initial synsets are not their own cousins return remoteCousinSynsetIDs; }
@Override public LexicographerFileInformation getLexicographerFileInformation() throws WordNetException { ILexFile lexFile = realSynset.getLexicalFile(); return EnglishWordnetLexicographerFileRetriever.get(lexFile.getNumber()); }
public IWord getWord(IWordID id) { if(data != null){ ISynset synset = data.synsets.get(id.getPOS()).get(id.getSynsetID()); return (synset == null) ? null : synset.getWord(id.getWordNumber()); } else { return backing.getWord(id); } }
@Override public List<SensedWord> getAllSensedWords() { List<IWord> objWords = realSynset.getWords(); List<SensedWord> sensedWords = new ArrayList<SensedWord>(objWords.size()); for ( IWord word : objWords) sensedWords.add(new JwiSensedWord(word, this.jwiDictionary)); return sensedWords; }
/** * @param relation must be a transitive relation like hypernym or hyponym * @param degree * @param initialSynsetIDs * @return */ private Set<ISynsetID> findRelatedSynsetsAtExactDistance( Set<ISynsetID> initialSynsetIDs, Pointer relation, int degree) { Set<ISynsetID> neighborIDs = new HashSet<ISynsetID>(initialSynsetIDs); Set<ISynsetID> visitedIDs = new HashSet<ISynsetID>(initialSynsetIDs);; for(int depth = 0; depth < degree; depth++) { Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>(); for (ISynsetID neighborID : neighborIDs) { ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID); for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation)) // if we haven't visited this hypernym yet, add it if (!visitedIDs.contains(secondaryNeighborID)) { secondaryNeighborIDs.add(secondaryNeighborID); visitedIDs.add(secondaryNeighborID); } } neighborIDs = secondaryNeighborIDs; } return neighborIDs; }
public static void main(String args[]) { WordNetUtils utils = WordNetUtils.getInstance(); System.out.println(utils.mapWordSenseToIWord("mouse.n.4")); System.out.println(utils.getSynsetFromOffset("15300051-n").getGloss()); }