Search in sources :

Example 1 with Entityhub

use of org.apache.stanbol.entityhub.servicesapi.Entityhub in project stanbol by apache.

the class EntityhubSearcher method lookup.

@Override
public Collection<? extends Entity> lookup(IRI field, Set<IRI> includeFields, List<String> search, String[] languages, Integer limit, Integer offset) throws EntitySearcherException {
    Entityhub entityhub = getSearchService();
    if (entityhub == null) {
        throw new EntitySearcherException("The Entityhub is currently not active");
    }
    FieldQuery query = EntitySearcherUtils.createFieldQuery(entityhub.getQueryFactory(), field, includeFields, search, languages);
    if (limit != null && limit > 0) {
        query.setLimit(limit);
    } else if (this.limit != null) {
        query.setLimit(this.limit);
    }
    if (offset != null && offset.intValue() > 0) {
        query.setOffset(offset.intValue());
    }
    QueryResultList<Representation> results;
    try {
        results = entityhub.find(query);
    } catch (EntityhubException e) {
        throw new EntitySearcherException("Exception while searchign for " + search + '@' + Arrays.toString(languages) + "in the Entityhub", e);
    }
    if (!results.isEmpty()) {
        Set<String> languagesSet = new HashSet<String>(Arrays.asList(languages));
        Collection<Entity> entities = new ArrayList<Entity>(results.size());
        for (Representation result : results) {
            entities.add(new EntityhubEntity(result, null, languagesSet));
        }
        return entities;
    } else {
        return Collections.emptyList();
    }
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) Entity(org.apache.stanbol.enhancer.engines.entitylinking.Entity) ArrayList(java.util.ArrayList) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) EntitySearcherException(org.apache.stanbol.enhancer.engines.entitylinking.EntitySearcherException) EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) Entityhub(org.apache.stanbol.entityhub.servicesapi.Entityhub) HashSet(java.util.HashSet)

Example 2 with Entityhub

use of org.apache.stanbol.entityhub.servicesapi.Entityhub in project stanbol by apache.

the class EntityhubSearcher method get.

@Override
public Representation get(String id, Set<String> includeFields) {
    if (id == null || id.isEmpty()) {
        return null;
    }
    Entityhub entityhub = getSearchService();
    if (entityhub == null) {
        throw new IllegalStateException("The Entityhub is currently not active");
    }
    Entity entity;
    try {
        entity = entityhub.getEntity(id);
    } catch (EntityhubException e) {
        throw new IllegalStateException("Exception while getting " + id + " from the Entityhub", e);
    }
    return entity == null ? null : entity.getRepresentation();
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) Entityhub(org.apache.stanbol.entityhub.servicesapi.Entityhub)

Example 3 with Entityhub

use of org.apache.stanbol.entityhub.servicesapi.Entityhub in project stanbol by apache.

the class EntityhubSearcher method lookup.

@Override
public Collection<? extends Representation> lookup(String field, Set<String> includeFields, List<String> search, String... languages) throws IllegalStateException {
    Entityhub entityhub = getSearchService();
    if (entityhub == null) {
        throw new IllegalStateException("The Entityhub is currently not active");
    }
    FieldQuery query = EntitySearcherUtils.createFieldQuery(entityhub.getQueryFactory(), field, includeFields, search, languages);
    QueryResultList<Representation> results;
    try {
        results = entityhub.find(query);
    } catch (EntityhubException e) {
        throw new IllegalStateException("Exception while searchign for " + search + '@' + Arrays.toString(languages) + "in the Entityhub", e);
    }
    return results.results();
}
Also used : FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Entityhub(org.apache.stanbol.entityhub.servicesapi.Entityhub)

Example 4 with Entityhub

use of org.apache.stanbol.entityhub.servicesapi.Entityhub in project stanbol by apache.

the class EntityhubSearcher method get.

@Override
public Entity get(IRI id, Set<IRI> fields, String... languages) throws EntitySearcherException {
    if (id == null || id.getUnicodeString().isEmpty()) {
        return null;
    }
    Entityhub entityhub = getSearchService();
    if (entityhub == null) {
        throw new EntitySearcherException("The Entityhub is currently not active");
    }
    org.apache.stanbol.entityhub.servicesapi.model.Entity entity;
    try {
        entity = entityhub.getEntity(id.getUnicodeString());
    } catch (EntityhubException e) {
        throw new EntitySearcherException("Exception while getting " + id + " from the Entityhub", e);
    }
    if (entity != null) {
        Set<String> languageSet;
        if (languages == null || languages.length < 1) {
            languageSet = null;
        } else if (languages.length == 1) {
            languageSet = Collections.singleton(languages[0]);
        } else {
            languageSet = new HashSet<String>(Arrays.asList(languages));
        }
        return new EntityhubEntity(entity.getRepresentation(), fields, languageSet);
    } else {
        return null;
    }
}
Also used : EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) Entityhub(org.apache.stanbol.entityhub.servicesapi.Entityhub) EntitySearcherException(org.apache.stanbol.enhancer.engines.entitylinking.EntitySearcherException) HashSet(java.util.HashSet)

Aggregations

Entityhub (org.apache.stanbol.entityhub.servicesapi.Entityhub)4 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)4 HashSet (java.util.HashSet)2 EntitySearcherException (org.apache.stanbol.enhancer.engines.entitylinking.EntitySearcherException)2 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)2 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)2 ArrayList (java.util.ArrayList)1 Entity (org.apache.stanbol.enhancer.engines.entitylinking.Entity)1 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)1