public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Synset)) return false; final Synset other = (Synset) obj; if (!id.equals(other.getID())) return false; if (!words.equals(other.getWords())) return false; if (!gloss.equals(other.getGloss())) return false; if (isAdjSat != other.isAdjectiveSatellite()) return false; if (!relatedMap.equals(other.getRelatedMap())) return false; return true; }
public int getType() { POS pos = getPOS(); if(pos != POS.ADJECTIVE) return pos.getNumber(); return isAdjectiveSatellite() ? 5 : 3; }
/** * Constructs a new sense entry object. * * @param key * the sense key of the entry * @param offset * the synset offset of the entry * @param num * the sense number of the entry * @param count * the tag count of the entry * @since JWI 2.1.0 */ public SenseEntry(ISenseKey key, int offset, int num, int count){ if(key == null) throw new NullPointerException(); Synset.checkOffset(offset); this.key = key; this.offset = offset; this.num = num; this.count = count; }
public static Map<String,String> getSynsetLexemes(Synset synset) { Map<String,String> result = new HashMap<String,String>(); long sense = synset.getOffset(); List<IWord> words = synset.getWords(); for (IWord word : words) { String lexeme = word.getLemma(); lexeme = cleanLexeme(lexeme); result.put(lexeme, new Long(sense).toString()); } return result; }
@Override public String getGloss(Entity entity) throws LexicalSemanticResourceException { StringBuilder sb = new StringBuilder(); Set<Synset> synsets = WordNetWindowsUtils.entityToSynsets(dict, entity, isCaseSensitive); for (Synset synset : synsets) { sb.append(synset.getGloss()); sb.append(" "); } return sb.toString().trim(); }
/** * @param synset A WordNet synset. * @return Creates an Entity from a synset. */ public static Entity synsetToEntity(Synset synset) { if (synset == null) { return null; } return new Entity(getSynsetLexemes(synset), mapPos(synset.getPOS())); }
newWords.add(new WordBuilder(old, oldWord)); return new Synset(old.getID(), old.getLexicalFile(), old.isAdjectiveSatellite(), old.isAdjectiveHead(), old.getGloss(), newWords, newIDs);
public static Synset toSynset(Dictionary dict, String lexeme, PoS pos, String sense, boolean isCaseSensitive) { Set<Synset> possibleSynsets = toSynset(dict, lexeme, pos, isCaseSensitive); for (Synset synset : possibleSynsets) { Integer senseNumber = synset.getOffset(); // if the sense number matches, then we have found the correct synset if (senseNumber.toString().equals(sense)) { return synset; } } // if we get here, there is no matching synset return null; }
private List<ISynsetID> getNodeListByRelation(Synset synset, SemanticRelation relationType) throws LexicalSemanticResourceException { List<ISynsetID> nodeList = new ArrayList<ISynsetID>(); if (relationType.equals(SemanticRelation.holonymy)) { nodeList.addAll(synset.getRelatedSynsets(Pointer.HOLONYM_MEMBER)); nodeList.addAll(synset.getRelatedSynsets(Pointer.HOLONYM_PART)); nodeList.addAll(synset.getRelatedSynsets(Pointer.HOLONYM_SUBSTANCE)); } else if (relationType.equals(SemanticRelation.hypernymy)) { nodeList.addAll(synset.getRelatedSynsets(Pointer.HYPERNYM)); nodeList.addAll(synset.getRelatedSynsets(Pointer.HYPERNYM_INSTANCE)); } else if (relationType.equals(SemanticRelation.hyponymy)) { nodeList.addAll(synset.getRelatedSynsets(Pointer.HYPONYM)); nodeList.addAll(synset.getRelatedSynsets(Pointer.HYPONYM_INSTANCE)); } else if (relationType.equals(SemanticRelation.meronymy)) { nodeList.addAll(synset.getRelatedSynsets(Pointer.MERONYM_MEMBER)); nodeList.addAll(synset.getRelatedSynsets(Pointer.MERONYM_PART)); nodeList.addAll(synset.getRelatedSynsets(Pointer.MERONYM_SUBSTANCE)); } return nodeList; }
return new Synset(synsetID, lexFile, isAdjSat, isAdjHead, gloss, words, synsetPointerMap);
/** * Constructs a new synset id with the specified offset and part of speech. * * @param offset * the offset * @param pos * the part of speech; may not be <code>null</code> * @throws NullPointerException * if the specified part of speech is <code>null</code> * @throws IllegalArgumentException * if the specified offset is not a legal offset * @since JWI 1.0 */ public SynsetID(int offset, POS pos) { if (pos == null) throw new NullPointerException(); Synset.checkOffset(offset); this.offset = offset; this.pos = pos; }
/** * Takes an integer in the closed range [0,99999999] and converts it into an * eight decimal digit zero-filled string. E.g., "1" becomes "00000001", * "1234" becomes "00001234", and so on. This is used for the generation of * synset and word numbers. * * @param offset * the offset to be converted * @return the zero-filled string representation of the offset * @throws IllegalArgumentException * if the specified offset is not in the valid range of * [0,99999999] * @since JWI 2.1.0 */ public static String zeroFillOffset(int offset){ checkOffset(offset); StringBuilder sb = new StringBuilder(8); String offsetStr = Integer.toString(offset); int numZeros = 8-offsetStr.length(); for(int i = 0; i < numZeros; i++) sb.append('0'); sb.append(offsetStr); return sb.toString(); }