Package org.apache.stanbol.entityhub.core.model

Examples of org.apache.stanbol.entityhub.core.model.EntityImpl


                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 (siteConfiguration.getEntitySearcherType() == null || isOfflineMode()) {
                        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);
                    }
                }
            } else {
                if (siteConfiguration.getEntitySearcherType() == null || isOfflineMode()) {
                    throw new SiteException(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 SiteException(String.format("EntitySearcher %s not available for remote site %s!",
                siteConfiguration.getEntitySearcherType(), siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
        try {
            log.trace("Will use an entity-searcher [type :: {}][query-uri :: {}].", entitySearcher.getClass()
                    .toString(), EntitySearcher.QUERY_URI);
            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
View Full Code Here


        long start = System.currentTimeMillis();
        if (cache != null) {
            try {
                Representation rep = cache.getRepresentation(id);
                if (rep != null) {
                    entity = new EntityImpl(getId(), rep, null);
                    initEntityMetadata(entity, siteMetadata,
                        singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.TRUE));
                } else if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
                    return null; // do no remote lokkups on CacheStrategy.all!!
                }
            } catch (YardException e) {
                if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                    throw new SiteException(String.format("Unable to get Represetnation %s form Cache %s",
                        id, siteConfiguration.getCacheId()), e);
                } else {
                    log.warn(
                        String.format(
                            "Unable to get Represetnation %s form Cache %s. Will dereference from remote site %s",
                            id, siteConfiguration.getCacheId(), siteConfiguration.getAccessUri()), e);
                }
            }
        } else {
            if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                throw new SiteException(String.format(
                    "Unable to get Represetnation %s because configured Cache %s is currently not available",
                    id, siteConfiguration.getCacheId()));
            } else {
                log.warn(String.format(
                    "Cache %s is currently not available. Will use remote site %s to load Representation %s",
                    siteConfiguration.getCacheId(), siteConfiguration.getEntityDereferencerType(), id));
            }
        }
        if (entity == null) { // no cache or not found in cache
            if (dereferencer == null) {
                throw new SiteException(String.format(
                    "Entity Dereferencer %s for accessing remote site %s is not available",
                    siteConfiguration.getEntityDereferencerType(), siteConfiguration.getAccessUri()));
            }
            ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
            Representation rep = null;
            try {
                rep = dereferencer.dereference(id);
            } catch (IOException e) {
                throw new SiteException(String.format(
                    "Unable to load Representation for entity %s form remote site %s with dereferencer %s",
                    id, siteConfiguration.getAccessUri(), siteConfiguration.getEntityDereferencerType()), e);
            }
            // representation loaded from remote site and cache is available
            if (rep != null) {
                Boolean cachedVersion = Boolean.FALSE;
                if (cache != null) {// -> cache the representation
                    try {
                        start = System.currentTimeMillis();
                        // return the the cached version
                        rep = cache.store(rep);
                        cachedVersion = Boolean.TRUE;
                        log.debug("  - cached Representation {} in {} ms", id,
                            (System.currentTimeMillis() - start));
                    } catch (YardException e) {
                        log.warn(String.format(
                            "Unable to cache Represetnation %s in Cache %s! Representation not cached!", id,
                            siteConfiguration.getCacheId()), e);
                    }
                }
                entity = new EntityImpl(getId(), rep, null);
                initEntityMetadata(entity, siteMetadata,
                    singletonMap(RdfResourceEnum.isChached.getUri(), (Object) cachedVersion));
            }
        } else {
            log.debug("  - loaded Representation {} from Cache in {} ms", id,
View Full Code Here

        //now we need to check if the parsed representation is the data or the
        //metadata of the Entity
        ManagedEntity updated;
        if(entity == null || representation.getId().equals(entity.getRepresentation().getId())){
            //update the data or create a new entity
            updated = ManagedEntity.init(new EntityImpl(config.getID(), representation,
                entity != null ? entity.getMetadata() : null),
                config.getDefaultManagedEntityState());
            if(entity == null){ //add creation date
                updated.setCreated(new Date());
            }
        } else {
            //update the metadata
            entity = new EntityImpl(config.getID(), entity.getRepresentation(),
                representation);
            //we need to validate the metadata
            updated = ManagedEntity.init(
                entity, config.getDefaultManagedEntityState());
        }
View Full Code Here

                data = rep;
                entityId = rep.getId(); //needed for logs
            }
            if(data != null){
                metadata = lookupMetadata(entityhubYard, rep.getId(),true);
                return new EntityImpl(config.getID(), data,metadata);
            } else {
                log.warn("Unable find representation for Entity {} (metadata: {}",
                    entityId,metadata);
                return null;
            }
View Full Code Here

                        results.iterator(),
                        new AdaptingIterator.Adapter<Representation,Entity>() {
                            private final String siteId = config.getId();
                            @Override
                            public Entity adapt(Representation value, Class<Entity> type) {
                                Entity entity = new EntityImpl(siteId,value,null);
                                SiteUtils.initEntityMetadata(entity, siteMetadata, null);
                                return entity;
                            }
                        }, Entity.class),Entity.class);
    }
View Full Code Here

            rep = getYard().getRepresentation(id);
        } catch (YardException e) {
            throw new ManagedSiteException(e.getMessage(), e);
        }
        if(rep != null){
            Entity entity = new EntityImpl(config.getId(), rep, null);
            SiteUtils.initEntityMetadata(entity, siteMetadata, null);
            return entity;
        } else {
            return null;
        }
View Full Code Here

        QueryResultList<Representation> results = yard.findRepresentation(query);
        log.info("  ... {} results",results.size());
        Collection<Entity> entities = new ArrayList<Entity>(results.size());
        for(Representation r : results){
            log.info("    > {}",r.getId());
            entities.add(new EntityImpl("dbpedia", r, null));
        }
        return new QueryResultListImpl<Entity>(results.getQuery(),entities,Entity.class);
    }
View Full Code Here

        //now we need to check if the parsed representation is the data or the
        //metadata of the Entity
        ManagedEntity updated;
        if(entity == null || representation.getId().equals(entity.getRepresentation().getId())){
            //update the data or create a new entity
            updated = ManagedEntity.init(new EntityImpl(config.getID(), representation,
                entity != null ? entity.getMetadata() : null),
                config.getDefaultManagedEntityState());
            if(entity == null){ //add creation date
                updated.setCreated(new Date());
            }
        } else {
            //update the metadata
            entity = new EntityImpl(config.getID(), entity.getRepresentation(),
                representation);
            //we need to validate the metadata
            updated = ManagedEntity.init(
                entity, config.getDefaultManagedEntityState());
        }
View Full Code Here

                data = rep;
                entityId = rep.getId(); //needed for logs
            }
            if(data != null){
                metadata = lookupMetadata(rep.getId(),true);
                return new EntityImpl(config.getID(), data,metadata);
            } else {
                log.warn("Unable find representation for Entity {} (metadata: {}",
                    entityId,metadata);
                return null;
            }
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

TOP

Related Classes of org.apache.stanbol.entityhub.core.model.EntityImpl

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.