@Override public String getSenseDescription(String senseId) throws SenseInventoryException { try { String description = lsr.getGloss(lsr.getEntityById(senseId)); return (description == null) ? "" : description; } catch (LexicalSemanticResourceException e) { throw new SenseInventoryException(e); } }
@Override public Iterable<Entity> getEntities() throws LexicalSemanticResourceException { return lsr.getEntities(); }
@Override public Entity getMostFrequentEntity(String lexeme) throws LexicalSemanticResourceException { return lsr.getMostFrequentEntity(lexeme); }
@Override public String getSenseInventoryName() { return lsr.getResourceName() + "_" + lsr.getResourceVersion() + "_LSR"; }
private String getGloss(Entity e) throws LexicalSemanticResourceException { String gloss; if (usePseudoGlosses) { gloss = getLexicalSemanticResource().getPseudoGloss(e, lexicalRelations, semanticRelations); } else { gloss = getLexicalSemanticResource().getGloss(e); } return gloss; } }
@Override public Set<String> getSenseNeighbours(String senseId) throws SenseInventoryException, UnsupportedOperationException { Set<Entity> entities; try { entities = lsr.getNeighbors(lsr.getEntityById(senseId)); } catch (LexicalSemanticResourceException e) { throw new SenseInventoryException(e); } Set<String> neighbours = new HashSet<String>(); for (Entity entity : entities) { neighbours.add(entity.getId()); } return neighbours; }
@Override public String getGloss(Entity aEntity) throws LexicalSemanticResourceException { return lsr.getGloss(aEntity); }
@Override public Set<Entity> getEntity(String aLexeme) throws LexicalSemanticResourceException { String usLexeme = aLexeme; usLexeme = usLexeme.replace('-', ' '); usLexeme = usLexeme.replace('_', ' '); usLexeme = StringUtils.join(usLexeme.split("[ ]+"), "_"); Set<Entity> result = cache.get(usLexeme+"-ALL"); if (result != null) { return result; } result = lsr.getEntity(usLexeme); if (result.size() > 0) { return result; } result = new HashSet<Entity>(); for (String fragment : usLexeme.split("[_]+")) { result.addAll(lsr.getEntity(fragment)); } if (cache != null) { cache.put(usLexeme+"-ALL", result); } return result; }
@Override public int getShortestPathLength(Entity aE1, Entity aE2) throws LexicalSemanticResourceException { return lsr.getShortestPathLength(aE1, aE2); }
@Override public Entity getEntityById(String aId) throws LexicalSemanticResourceException { return lsr.getEntityById(aId); }
@Override public String getPseudoGloss(Entity aEntity, Set<LexicalRelation> aLexicalRelations, Map<SemanticRelation, Integer> aSemanticRelations) throws LexicalSemanticResourceException { return lsr.getPseudoGloss(aEntity, aLexicalRelations, aSemanticRelations); }
@Override public String getResourceName() { return lsr.getResourceName(); }
@Override public Set<Entity> getNeighbors(Entity aEntity) throws LexicalSemanticResourceException { return lsr.getNeighbors(aEntity); }
@Override public String getResourceVersion() { return lsr.getResourceVersion()+"-"+getClass().getSimpleName(); }
@Override public Set<Entity> getEntity(String aLexeme, PoS aPos) throws LexicalSemanticResourceException { String usLexeme = aLexeme; usLexeme = usLexeme.replace('-', ' '); usLexeme = usLexeme.replace('_', ' '); usLexeme = StringUtils.join(usLexeme.split("[ ]+"), "_"); Set<Entity> result = cache.get(usLexeme+"-"+aPos); if (result != null) { return result; } result = lsr.getEntity(usLexeme, aPos); if (result.size() > 0) { return result; } result = new HashSet<Entity>(); for (String fragment : usLexeme.split("[_]+")) { result.addAll(lsr.getEntity(fragment, aPos)); } if (cache != null) { cache.put(usLexeme+"-"+aPos, result); } return result; }
Entity catEntity1 = new Entity(c1.getTitle().getWikiStyleTitle()); Entity catEntity2 = new Entity(c2.getTitle().getWikiStyleTitle()); int pathLength = wikiCategoryResource.getShortestPathLength(catEntity1, catEntity2); if (pathLength < shortestPathLength) { shortestPathLength = pathLength;
@Override public POS getPos(String senseId) throws SenseInventoryException { Entity entity; try { entity = lsr.getEntityById(senseId); } catch (LexicalSemanticResourceException e) { throw new SenseInventoryException(e); } return LsrSenseInventoryUtil.convertPos(entity.getPos()); }
@Override public Entity getMostFrequentEntity(String lexeme, PoS pos) throws LexicalSemanticResourceException { return lsr.getMostFrequentEntity(lexeme, pos); } }
@Override public List<String> getSenses(String sod) throws SenseInventoryException { try { List<String> senses = new ArrayList<String>(); for (Entity entity : lsr.getEntity(sod)) { senses.add(entity.getId()); } return senses; } catch (LexicalSemanticResourceException e) { throw new SenseInventoryException(e); } }
@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; }