@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Entity other = (Entity) obj; if (lexemes == null) { if (other.lexemes != null) { return false; } } else if (!lexemes.equals(other.lexemes)) { return false; } if (pos == null) { if (other.pos != null) { return false; } } else if (!pos.equals(other.pos)) { return false; } return true; }
@Override public int hashCode() { final int PRIME = 31; int result = 1; result = PRIME * result + ((lexemes == null) ? 0 : lexemes.hashCode()); result = PRIME * result + ((pos == null) ? 0 : pos.hashCode()); return result; }
@Override public String convert(String senseId) { Matcher m = sensePattern.matcher(senseId); if (m.find()) { char pos; if (m.group(2).equals(PoS.n.toString())) { pos = 'n'; } else if (m.group(2).equals(PoS.v.toString())) { pos = 'v'; } else if (m.group(2).equals(PoS.adj.toString())) { pos = 'a'; } else if (m.group(2).equals(PoS.adv.toString())) { pos = 'r'; } else { throw new IllegalArgumentException("Unknown part of speech for sense " + senseId); } return String.format("%08d%c", Integer.valueOf(m.group(1)), pos); } else { return null; } } }
else if (pos.equals(Entity.UNKNOWN_POS)) {
else if (pos.equals(Entity.UNKNOWN_POS)) {
public static Set<POS> mapPos(PoS lsrPos) { Set<POS> pos = new LinkedHashSet<POS>(); if (lsrPos.equals(PoS.n)) { pos.add(POS.NOUN); } else if (lsrPos.equals(PoS.v)) { pos.add(POS.VERB); } else if (lsrPos.equals(PoS.adj)) { pos.add(POS.ADJECTIVE); } else if (lsrPos.equals(PoS.adv)) { pos.add(POS.ADVERB); } else { // defaults to noun pos.add(POS.NOUN); } return pos; }
public static Set<PartOfSpeech> mapPos(PoS pos) { Set<PartOfSpeech> returnPos = new HashSet<PartOfSpeech>(); if (pos.equals(PoS.n)) { returnPos.add(PartOfSpeech.NOUN); returnPos.add(PartOfSpeech.PROPER_NOUN); } else if (pos.equals(PoS.v)) { returnPos.add(PartOfSpeech.VERB); } else if (pos.equals(PoS.adj)) { returnPos.add(PartOfSpeech.ADJECTIVE); } else if (pos.equals(PoS.adv)) { returnPos.add(PartOfSpeech.ADVERB); } else { returnPos.add(PartOfSpeech.UNKNOWN); } return returnPos; }
@Override public Entity getEntityById(String id) throws LexicalSemanticResourceException { String splitter = "\\" + Entity.conceptSeparator + Entity.posSeparator; String[] conceptsPosParts = id.split(splitter); if (conceptsPosParts.length != 2) { throw new LexicalSemanticResourceException("Invalid id: " + id); } String concepts = conceptsPosParts[0]; String pos = conceptsPosParts[1]; String[] lexemeSensePairs = concepts.split("\\" + Entity.conceptSeparator); Map<String, String> lexemes = new HashMap<String,String>(); for (String lexemeSensePair : lexemeSensePairs) { String[] lexemeSenseSplit = lexemeSensePair.split(Entity.senseSeparator); if (lexemeSenseSplit.length != 2) { throw new LexicalSemanticResourceException("Invalid id: " + id); } lexemes.put(lexemeSenseSplit[0], lexemeSenseSplit[1]); } return getEntity(lexemes, PoS.valueOf(pos)); }
public static Set<POS> mapPos(PoS lsrPos) { Set<POS> pos = new HashSet<POS>(); if (lsrPos.equals(PoS.n)) { pos.add(POS.NOUN); } else if (lsrPos.equals(PoS.v)) { pos.add(POS.VERB); } else if (lsrPos.equals(PoS.adj)) { pos.add(POS.ADJECTIVE); } else if (lsrPos.equals(PoS.adv)) { pos.add(POS.ADVERB); } else { // defaults to noun pos.add(POS.NOUN); } return pos; }
public static POS getJwnlPos(PoS lsrPos) { if (lsrPos.equals(PoS.n)) { return POS.NOUN; } else if (lsrPos.equals(PoS.v)) { return POS.VERB; } else if (lsrPos.equals(PoS.adj)) { return POS.ADJECTIVE; } else if (lsrPos.equals(PoS.adv)) { return POS.ADVERB; } else { // defaults to noun return POS.NOUN; } }
@Override public Entity getRoot(PoS pos) throws LexicalSemanticResourceException { if (pos.equals(PoS.n)) { return getRoot(); } else { return null; } }
@Override public Entity getRoot(PoS pos) throws LexicalSemanticResourceException { if (pos.equals(PoS.n)) { return getRoot(); } else { return null; } }
@Override public Entity getMostFrequentEntity(String lexeme) throws LexicalSemanticResourceException { for (PoS pos : PoS.values()) { Entity e = WordNetUtils.getMostFrequentEntity(dict, lexeme, pos, isCaseSensitive); if (e != null) { return e; } } return null; }
@Override public Entity getRoot(PoS pos) throws LexicalSemanticResourceException { if (pos.equals(PoS.n)) { return getRoot(); } else { return null; } }
public static Set<Synset> toSynset(Dictionary dict, String lexeme, boolean isCaseSensitive) throws LexicalSemanticResourceException { Set<Synset> resultsSynsets = new LinkedHashSet<Synset>(); for (PoS pos : PoS.values()) { resultsSynsets.addAll(toSynset(dict, lexeme, pos, isCaseSensitive)); } return resultsSynsets; }