@Override public Entity getEntity(String entityId) { Collection<Site> sites = getSitesByEntityPrefix(entityId); if(sites.isEmpty()){ log.info("No Referenced Site registered for Entity {}",entityId); log.debug("Registered Prefixes {}",prefixList); return null; } for(Site site : sites){ Entity entity; try { entity = site.getEntity(entityId); if(entity != null){ log.debug("Return Representation of Site {} for Entity {}", site.getConfiguration().getName(),entityId); return entity; } } catch (SiteException e) { log.warn("Unable to access Site "+site.getConfiguration().getName()+ " (id = "+site.getId()+")",e); } } log.debug("Entity {} not found on any of the following Sites {}",entityId,sites); return null; }
@Override public Collection<? extends Representation> lookup(String field, Set<String> includeFields, List<String> search, String... languages) throws IllegalStateException { //build the query and than return the result Site site = getSearchService(); if(site == null){ throw new IllegalStateException("ReferencedSite "+siteId+" is currently not available"); } FieldQuery query = EntitySearcherUtils.createFieldQuery(site.getQueryFactory(), field, includeFields, search, languages); if(limit != null){ query.setLimit(limit); } QueryResultList<Representation> results; try { results = site.find(query); } catch (SiteException e) { throw new IllegalStateException("Exception while searchign for "+ search+'@'+Arrays.toString(languages)+"in the ReferencedSite "+ site.getId(), e); } return results.results(); }
@Override public boolean supportsOfflineMode() { Site site = getSearchService(); //Do not throw an exception here if the site is not available. Just return false return site == null ? false : site.supportsLocalMode(); }
@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(); }
@Override public InputStream getContent(String entityId, String contentType) { Collection<Site> sites = getSitesByEntityPrefix(entityId); if(sites.isEmpty()){ log.info("No Referenced Site registered for Entity {}",entityId); log.debug("Registered Prefixes {}",prefixList); return null; } for(Site site : sites){ InputStream content; try { content = site.getContent(entityId, contentType); if(content != null){ log.debug("Return Content of type {} for Entity {} from referenced site {}", new Object[]{contentType,entityId,site.getConfiguration().getName()}); return content; } } catch (SiteException e) { log.warn("Unable to access Site "+site.getConfiguration().getName()+ " (id = "+site.getId()+")",e); } } log.debug("Entity {} not found on any of the following Sites {}",entityId,sites); return null; } @Override
Set<Entity> entities = new HashSet<Entity>(); for(Site site : referencedSites){ if(site.supportsSearch()){ //do not search on sites that do not support it log.debug(" > query site {}",site.getId()); try { QueryResultList<Entity> results = site.findEntities(query); if(processedQuery == null){ processedQuery = results.getQuery(); rep.getId(),site.getConfiguration().getName()); log.warn("Unable to access Site "+site.getConfiguration().getName()+ " (id = "+site.getId()+")",e); log.debug(" > Site {} does not support queries",site.getId());
FieldQuery queryWithResults = null; for(Site site : referencedSites){ if(site.supportsSearch()){ log.debug(" > query site {}",site.getId()); try { QueryResultList<Representation> results = site.find(query); if(processedQuery == null){ processedQuery = results.getQuery(); log.info("Entity {} found on more than one Referenced Site" + " -> Representation of Site {} is ignored", rep.getId(),site.getConfiguration().getName()); log.warn("Unable to access Site "+site.getConfiguration().getName()+ " (id = "+site.getId()+")",e); log.debug(" > Site {} does not support queries",site.getId());
FieldQueryFactory queryFactory = site == null ? entityhub.getQueryFactory() : site.getQueryFactory(); else log.trace("A query will be sent to a site [id :: {}][type :: {}].", site.getId(), site .getClass()); site.findEntities(query); // else the referenced site log.debug(" - {} results returned by query {}", results.size(), results.getQuery()); if (results.isEmpty()) { // no results nothing to do
protected QueryResultList<Entity> query(Site dbpediaSite, String savedEntityLabel, String language, String extractionContext) throws SiteException { FieldQuery query = dbpediaSite.getQueryFactory().createFieldQuery(); if (savedEntityLabel != null && !savedEntityLabel.isEmpty()) { Constraint labelConstraint; if (language != null) { labelConstraint = new TextConstraint(savedEntityLabel, false, language, null); } else { labelConstraint = new TextConstraint(savedEntityLabel, false); } // TODO: what happens if a recommendation was not based on rdfs:label? query.setConstraint(RDFS_LABEL.getUnicodeString(), labelConstraint); } else { log.warn("parsed label {} was empty or NULL. Will use Similarity constraint only!", savedEntityLabel); } query.setConstraint(SpecialFieldEnum.fullText.getUri(), new SimilarityConstraint(extractionContext)); query.setLimit(25); return dbpediaSite.findEntities(query); }
FieldQuery queryWithResults = null; for(Site site : referencedSites){ if(site.supportsSearch()){ log.debug(" > query site {}",site.getId()); try { QueryResultList<String> results = site.findReferences(query); if(processedQuery == null){ processedQuery = results.getQuery(); log.warn("Unable to access Site "+site.getConfiguration().getName()+ " (id = "+site.getId()+")",e); log.debug(" > Site {} does not support queries",site.getId());
@Override protected Representation getRepresentation(Site site, String id, boolean offlineMode) throws EntityhubException { Entity entity = site.getEntity(id); return entity == null ? null : entity.getRepresentation(); } @Override
resultIt = new AdaptingIterator<Entity,Representation>(site.findEntities(query).iterator(), new AdaptingIterator.Adapter<Entity,Representation>() { @Override } catch (SiteException e) { String message = String.format("Unable to Query Site '%s' (message: %s)", site.getId(),e.getMessage()); log.error(message, e); return Response.status(Status.INTERNAL_SERVER_ERROR)
if (isOfflineMode() && !site.supportsLocalMode()) { log.warn( "Unable to enhance ci {} because OfflineMode is not supported by ReferencedSite {}.", ci .getUri().getUnicodeString(), site.getId()); return;
@Override protected FieldQuery createQuery() { return site.getQueryFactory().createFieldQuery(); } @Override
RdfRepresentation rep = valueFactory.createRepresentation(id); String namespace = NamespaceEnum.entityhub.getNamespace(); rep.add(namespace+"localMode", site.supportsLocalMode()); rep.add(namespace+"supportsSearch", site.supportsSearch()); SiteConfiguration config = site.getConfiguration(); rep.add("http://www.w3.org/2000/01/rdf-schema#label", config.getName()); rep.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", valueFactory.createReference(namespace+"ReferencedSite"));
@Override public boolean equals(Object obj) { if (obj instanceof Site) { SiteConfiguration osc = ((Site) obj).getConfiguration(); // this will return false if one of the two sites is not activated // -> this should be OK return siteConfiguration != null && osc != null && getId().equals(osc.getId()); } else { return false; } }
/** * @param query * @return * @throws SiteException */ protected QueryResultList<Representation> performQuery(@PathParam(value = "site") String siteId, FieldQuery query) throws SiteException { return getSite(siteId).find(query); } @Override
ValueFactory valueFactory) { SiteConfiguration siteConfig = site.getConfiguration(); ManagedEntityState state; state = siteConfig.getDefaultManagedEntityState(); FieldMapper siteMapper = site.getFieldMapper(); FieldMapper mapper = this.fieldMapper.clone(); for(FieldMapping siteMapping : siteMapper.getMappings()){ managedEntity.addAttributionLink(site.getConfiguration().getAttributionUrl()); managedEntity.addAttributionText(site.getConfiguration().getAttribution(), null); managedEntity.addContributorName(site.getConfiguration().getName());