@Override public String getPseudoGloss(Entity entity, Set<LexicalRelation> lexicalRelations, Map<SemanticRelation, Integer> semanticRelations) throws LexicalSemanticResourceException { Set<String> pseudoGloss = new HashSet<String>(); for (LexicalRelation lexicalRelation : lexicalRelations) { for (String lexeme : entity.getLexemes()) { pseudoGloss.add(lexeme); pseudoGloss.addAll(this.getRelatedLexemes(lexeme, entity.getPos(), entity.getSense(lexeme), lexicalRelation)); } } for (SemanticRelation semanticRelation : semanticRelations.keySet()) { pseudoGloss.addAll( getSemanticRelationsRecursive(pseudoGloss, semanticRelation, entity, semanticRelations.get(semanticRelation)) ); } return StringUtils.join(pseudoGloss, " ").trim(); }
public Set<Entity> getEntity(String lexeme, PoS pos, String sense) throws LexicalSemanticResourceException { Set<Entity> resultEntities = getEntity(lexeme, pos); Iterator<Entity> entityIter = resultEntities.iterator(); while (entityIter.hasNext()) { Entity e = entityIter.next(); // one of the lexemes must be the given lexeme with the given pos boolean found = false; for (String currentLexeme : e.getLexemes()) { if (currentLexeme.equals(lexeme) && e.getSense(currentLexeme).equals(sense)) { found = true; } } // remove entity from result set, if not found if (!found) { entityIter.remove(); } } return resultEntities; }
@Override public Map<String, List<String>> getSenseInventory() throws SenseInventoryException { System.out.println("Be careful, this is a quite slow operation."); Map<String, List<String>> senseInventory = new HashMap<String, List<String>>(); try { for (Entity entity : lsr.getEntities()) { for (String lexeme : entity.getLexemes()) { if (!senseInventory.containsKey(lexeme)) { senseInventory.put(lexeme, new ArrayList<String>()); } String sense = entity.getId(); List<String> senses = senseInventory.get(lexeme); senses.add(sense); senseInventory.put(lexeme, senses); } } } catch (LexicalSemanticResourceException e) { throw new SenseInventoryException(e); } return senseInventory; }
/** * Recursively selects all lexemes from related entities up to the given depth. * @param rel semantic relation * @param e entity * @param depth The recursive depth * @return The set of string in the pseudo gloss. * @throws UnsupportedOperationException * @throws LexicalSemanticResourceException */ private Set<String> getSemanticRelationsRecursive(Set<String> pseudoGloss, SemanticRelation semanticRelation, Entity entity, int depth) throws LexicalSemanticResourceException { for (Entity e : this.getRelatedEntities(entity, semanticRelation)) { pseudoGloss.addAll(e.getLexemes()); if (depth > 1) { pseudoGloss = getSemanticRelationsRecursive(pseudoGloss, semanticRelation, e, depth-1); } } return pseudoGloss; }
public Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation) throws LexicalSemanticResourceException { Entity entity = WikipediaArticleUtils.lexemeToEntity(wiki, lexeme, isCaseSensitive); Set<String> relatedLexemes = new HashSet<String>(); if (entity == null) { return relatedLexemes; } if (lexicalRelation.equals(LexicalRelation.antonymy)) { logger.warn("Wikipedia contains no antonymy information. Returning empty set."); } else if (lexicalRelation.equals(LexicalRelation.synonymy)) { for (String synonym : entity.getLexemes()) { String plainSynonym = WikipediaArticleUtils.plainString(synonym); if (!plainSynonym.equals(lexeme)) { relatedLexemes.add(plainSynonym); } } } return relatedLexemes; }
public static Set<Synset> entityToSynsets(Dictionary dict, Entity entity, boolean isCaseSensitive) throws LexicalSemanticResourceException { Set<Synset> results = new HashSet<Synset>(); Set<String> lexemes = entity.getLexemes(); PoS pos = entity.getPos(); String sense = entity.getSense(entity.getFirstLexeme());
Set<String> lexemes = entity.getLexemes(); PoS pos = entity.getPos(); String sense = entity.getSense(entity.getFirstLexeme());