Search in sources :

Example 16 with QueryResultListImpl

use of org.apache.stanbol.entityhub.core.query.QueryResultListImpl in project stanbol by apache.

the class EntityhubImpl method findEntities.

@Override
public final QueryResultList<Entity> findEntities(FieldQuery query) throws YardException {
    QueryResultList<String> references = entityhubYard.findReferences(query);
    List<Entity> entities = new ArrayList<Entity>(references.size());
    for (String reference : references) {
        Entity entity = lookupLocalEntity(reference);
        if (entity != null) {
            entities.add(entity);
        } else {
            log.warn("Unable to create Entity for Reference {} in the Yard " + "usd by the entity hub [id={}] -> ignore reference", reference, config.getEntityhubYardId());
        }
    }
    return new QueryResultListImpl<Entity>(references.getQuery(), entities, Entity.class);
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) ArrayList(java.util.ArrayList) QueryResultListImpl(org.apache.stanbol.entityhub.core.query.QueryResultListImpl)

Example 17 with QueryResultListImpl

use of org.apache.stanbol.entityhub.core.query.QueryResultListImpl in project stanbol by apache.

the class MockEntityCorefDbpediaSite method findEntities.

@SuppressWarnings("deprecation")
@Override
public QueryResultList<Entity> findEntities(FieldQuery query) throws SiteException {
    TextConstraint labelConstraint = (TextConstraint) query.getConstraint(RDFS_LABEL.getUnicodeString());
    for (Entity entity : entities.values()) {
        Iterator<Object> entityAttributes = entity.getRepresentation().get(RDFS_LABEL.getUnicodeString());
        while (entityAttributes.hasNext()) {
            Text entityAttribute = (Text) entityAttributes.next();
            if (entityAttribute.getText().equals(labelConstraint.getText())) {
                Collection<Entity> retEntities = new ArrayList<>(1);
                retEntities.add(entity);
                return new QueryResultListImpl<Entity>(null, retEntities, Entity.class);
            }
        }
    }
    return null;
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) ArrayList(java.util.ArrayList) QueryResultListImpl(org.apache.stanbol.entityhub.core.query.QueryResultListImpl) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) TextConstraint(org.apache.stanbol.entityhub.servicesapi.query.TextConstraint)

Aggregations

QueryResultListImpl (org.apache.stanbol.entityhub.core.query.QueryResultListImpl)17 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)7 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)6 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)5 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)4 SiteException (org.apache.stanbol.entityhub.servicesapi.site.SiteException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 EntityImpl (org.apache.stanbol.entityhub.core.model.EntityImpl)3 Site (org.apache.stanbol.entityhub.servicesapi.site.Site)3 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)2 ResultSet (org.apache.clerezza.rdf.core.sparql.ResultSet)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2