Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.Entity


                    .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
            }
        }
       
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity mapping;
        try {
            mapping = entityhub.getMappingBySource(entity);
        } catch (EntityhubException e) {
            throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
        }
View Full Code Here


            log.info("No Referenced Site registered for Entity {}",entityId);
            log.debug("Registered Prefixes {}",prefixList);
            return null;
        }
        for(ReferencedSite site : sites){
            Entity entity;
            try {
                entity = site.getEntity(entityId);
                if(entity != null){
                    log.debug("Return Representation of Site {} for Entity {}",
                        site.getConfiguration().getName(),entityId);
View Full Code Here

                try {
                    //When using the Cache, directly get the representations!
                    QueryResultList<Representation> representations = cache.findRepresentation((query));
                    results = new ArrayList<Entity>(representations.size());
                    for(Representation result : representations){
                        Entity entity = new EntityImpl(getId(),result,null);
                        results.add(entity);
                        initEntityMetadata(entity,true);
                    }
                    return new QueryResultListImpl<Entity>(query, results, Entity.class);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
                            siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
                    }
                }
            } else {
                if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                    throw new ReferencedSiteException(String.format("Unable to execute query on Cache %s because it is currently not active",
                        siteConfiguration.getCacheId()));
                } else {
                    log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
                        siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
                }
            }
        }
        QueryResultList<String> entityIds;
        if(entitySearcher == null) {
            throw new ReferencedSiteException(
                String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
                    siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(),entitySearcher.getClass());
        try {
            entityIds = entitySearcher.findEntities(query);
        } catch (IOException e) {
            throw new ReferencedSiteException(String.format("Unable to execute query on remote site %s with entitySearcher %s!",
                    siteConfiguration.getQueryUri(),siteConfiguration.getEntitySearcherType()), e);
        }
        int numResults = entityIds.size();
        List<Entity> entities = new ArrayList<Entity>(numResults);
        int errors = 0;
        ReferencedSiteException lastError = null;
        for(String id : entityIds){
            Entity entity;
            try {
                entity = getEntity(id);
                if(entity == null){
                    log.warn("Unable to create Entity for ID that was selected by an FieldQuery (id="+id+")");
                }
                entities.add(entity);
                //use the position in the list as resultSocre
                entity.getRepresentation().set(RdfResourceEnum.resultScore.getUri(), Float.valueOf((float)numResults));
            } catch (ReferencedSiteException e) {
                lastError = e;
                errors++;
                log.warn(String.format("Unable to get Representation for Entity %s. -> %d Error%s for %d Entities in QueryResult (Reason:%s)",
                        id,errors,errors>1?"s":"",entityIds.size(),e.getMessage()));
View Full Code Here

        }
    }
    @Override
    public Entity getEntity(String id) throws ReferencedSiteException {
        Cache cache = getCache();
        Entity entity = null;
        long start = System.currentTimeMillis();
        if (cache != null) {
            try {
                Representation rep = cache.getRepresentation(id);
                if(rep != null){
View Full Code Here

                    .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
            }
        }
        ReferencedSiteManager referencedSiteManager = ContextHelper.getServiceFromContext(
            ReferencedSiteManager.class, servletContext);
        Entity sign = referencedSiteManager.getEntity(id);
        if (sign != null) {
            ResponseBuilder rb = Response.ok(sign);
            rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType+"; charset=utf-8");
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
View Full Code Here

        }
        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();
    }
View Full Code Here

    @Override
    public Representation get(String id,Set<String> includeFields) {
        if(id == null || id.isEmpty()){
            return null;
        }
        Entity entity;
        Site site = getSearchService();
        if(site == null){
            throw new IllegalStateException("ReferencedSite "+siteId+" is currently not available");
        }
        try {
            entity = site.getEntity(id);
        catch (SiteException e) {
            throw new IllegalStateException("Exception while getting "+id+
                " from the ReferencedSite "+site.getId(),e);
        }
        return entity == null ? null : entity.getRepresentation();
    }
View Full Code Here

                            .valueOf(perf.recall))));
                    metadata.add(new TripleImpl(enhancement, f1, lf.createTypedLiteral(Double
                            .valueOf(perf.f1))));
                }
                // fetch concept label from the entityhub or a referenced site if available
                Entity entity = entityhub.getEntity(topic.conceptUri);
                if (entity == null) {
                    entity = referencedSiteManager.getEntity(topic.conceptUri);
                }
                if (entity != null) {
                    Representation representation = entity.getRepresentation();
                    // TODO: extract all languages based on some configuration instead of hardcoding English
                    Text label = representation.getFirst(NamespaceEnum.skos + "prefLabel", "en", "en-US",
                        "en-GB");
                    if (label == null) {
                        label = representation.getFirst(NamespaceEnum.rdfs + "label", "en", "en-US", "en-GB");
View Full Code Here

            case ADD_VALUES:
                while(redirects.hasNext()){
                    Reference redirect = redirects.next();
                    if(redirect != null){
                        try {
                            Entity redirectedEntity = site != null ?
                                    site.getEntity(redirect.getReference()) :
                                        entityhub.getEntity(redirect.getReference());
                            if(redirectedEntity != null){
                                for(String field: fields){
                                    rep.add(field, redirectedEntity.getRepresentation().get(field));
                                }
                            }
                        } catch (EntityhubException e) {
                            log.info(String.format("Unable to follow redirect to '%s' for Entity '%s'",
                                redirect.getReference(),rep.getId()),e);
                        }
                    }
                }
                return rep;
            case FOLLOW:
                while(redirects.hasNext()){
                    Reference redirect = redirects.next();
                    if(redirect != null){
                        try {
                            Entity redirectedEntity = site != null ?
                                    site.getEntity(redirect.getReference()) :
                                        entityhub.getEntity(redirect.getReference());
                            if(redirectedEntity != null){
                                return redirectedEntity.getRepresentation();
                            }
                        } catch (EntityhubException e) {
                            log.info(String.format("Unable to follow redirect to '%s' for Entity '%s'",
                                redirect.getReference(),rep.getId()),e);
                        }
View Full Code Here

     */
    private MGraph populateWithEntity(String entityURI, MGraph target) {
        log.debug("Requesting signature of entity {}", entityURI);
        MGraph graph = target != null ? target : new IndexedMGraph();
        // Query the Entity Hub
        Entity signature = referencedSiteManager.getEntity(entityURI);
        if (signature != null) {
            RdfRepresentation rdfSignature = RdfValueFactory.getInstance().toRdfRepresentation(
                signature.getRepresentation());
            graph.addAll(rdfSignature.getRdfGraph());
        }
        return graph;
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.