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

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


        return site == null ? false : site.supportsLocalMode();
    }
   
    @Override
    protected Representation getRepresentation(Site site, String id, boolean offlineMode) throws EntityhubException {
        Entity entity = site.getEntity(id);
        return entity == null ? null : entity.getRepresentation();
    }
View Full Code Here


        return true; //can not be determined here .. return true
    }
   
    @Override
    protected Representation getRepresentation(SiteManager sm, String id, boolean offlineMode) throws EntityhubException {
        Entity entity = sm.getEntity(id);
        return entity == null ? null : entity.getRepresentation();
    }
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, siteMetadata,
                        singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.TRUE));
                }
                return new QueryResultListImpl<Entity>(query, results, Entity.class);
            } catch (YardException e) {
                if (entitySearcher == null) {
                    throw new SiteException("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);
                }
            }
        }
        QueryResultList<String> entityIds;
        if (entitySearcher == null) {
            throw new SiteException(String.format("The ReferencedSite %s does not support queries!",
                getId()));
        }
        try {
            entityIds = entitySearcher.findEntities(query);
        } catch (IOException e) {
            throw new SiteException(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;
        SiteException 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 (SiteException e) {
                lastError = e;
                errors++;
                log.warn(String.format("Unable to get Representation for Entity "
View Full Code Here

                        siteConfiguration.getCacheId()), e);
                }
            }
        }
        if(rep != null){
            Entity entity = new EntityImpl(getId(), rep, null);
            initEntityMetadata(entity, siteMetadata,
                singletonMap(RdfResourceEnum.isChached.getUri(), (Object) cachedVersion));
            return entity;
        } else {
            return null;
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

        if (symbolId == null || symbolId.isEmpty()) {
            // TODO: how to parse an error message
            throw new WebApplicationException(BAD_REQUEST);
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity entity;
        try {
            entity = entityhub.getEntity(symbolId);
        } catch (EntityhubException e) {
            throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
        }
View Full Code Here

            if (reference == null || reference.isEmpty()) {
                // TODO: how to parse an error message
                throw new WebApplicationException(BAD_REQUEST);
            }
            Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
            Entity entity;
            try {
                entity = entityhub.lookupLocalEntity(reference, create);
            } catch (EntityhubException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
View Full Code Here

            return Response.status(Status.BAD_REQUEST).entity("The Request does" +
                    "not provide the id of the Entity to delete (parameter 'id').")
                    .header(HttpHeaders.ACCEPT, accepted).build();
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity entity;
        ResponseBuilder rb;
        try {
            if(id.equals("*")){
                log.info("Deleting all Entities form the Entityhub");
                entityhub.deleteAll();
View Full Code Here

        //for remote Entiteis as suggested by
        // http://incubator.apache.org/stanbol/docs/trunk/entityhub/entityhubandlinkeddata.html
        Map<String,Entity> updated = new HashMap<String,Entity>();
        for(Representation representation : parsed.values()){
            try {
                Entity entity = entityhub.store(representation);
                updated.put(entity.getId(), entity);
            }catch (EntityhubException e) {
                log.error(String.format("Exception while storing Entity %s" +
                        "in the Entityhub.",representation),e);
            }
        }
        //create the response for the Entity
        // for now directly return the added entity. one could also
        // consider returning a seeOther (303) with the get URI for the
        // created/updated entity
        if(updated.isEmpty()){
            // No (valid) data parsed
            ResponseBuilder rb = Response.status(Status.NOT_MODIFIED);
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        } else {
            Entity entity = updated.values().iterator().next();
            if(method.equals(HttpMethod.POST)){
                ResponseBuilder rb = Response.created(uriInfo.getAbsolutePathBuilder()
                    .queryParam("id", "{entityId}")
                    .build(entity.getId()));
                addCORSOrigin(servletContext, rb, headers);
                return rb.build();
            } else {
                //return Response.noContent().build();
                //As alternative return the modified entity
View Full Code Here

                return Response.status(Status.BAD_REQUEST).entity("The mapping id (URI) is missing.\n").header(
                    HttpHeaders.ACCEPT, acceptedMediaType).build();
            }
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity mapping;
        try {
            mapping = entityhub.getMappingById(reference);
        } catch (EntityhubException e) {
            log.error("error while getting the mapping for {}", reference, e);
            return Response.status(Status.INTERNAL_SERVER_ERROR).build();
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.