Package org.apache.stanbol.entityhub.servicesapi.query

Examples of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery


        //TODO: The QueryResultList expects that the query as executed is added
        //to the response. However when executing queries on multiple site they
        //might support a different set of features and therefore execute
        //different variants. For now I return simple the query as executed by
        //the first Site that contributes results
        FieldQuery processedQuery = null;
        FieldQuery queryWithResults = null;
        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 {
View Full Code Here


                entity.getRepresentation().getId(),
                entity.getMetadata().getId()));
        }
    }
    private void deleteEntities(Collection<String> ids) throws YardException {
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        Collection<String> toDelete = new HashSet<String>(ids);
        for(String id : ids){
            if(id != null && !id.isEmpty()){
                fieldQuery.setConstraint(RdfResourceEnum.aboutRepresentation.getUri(), new ReferenceConstraint(id));
                for(Iterator<String> it = entityhubYard.findReferences(fieldQuery).iterator();it.hasNext();){
                    toDelete.add(it.next());
                }
            }
        }
View Full Code Here

       
    }

    private void deleteMappingsbyTarget(String id) throws YardException {
        if(id != null && !id.isEmpty()){
            FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
            fieldQuery.setConstraint(RdfResourceEnum.mappingTarget.getUri(), new ReferenceConstraint(id));
            deleteEntities(ModelUtils.asCollection(
                entityhubYard.findReferences(fieldQuery).iterator()));
        }
    }
View Full Code Here

    public Entity getMappingBySource(String reference) throws YardException{
        if(reference == null){
            log.warn("NULL parsed as Reference -> call to getMappingByEntity ignored (return null)");
            return null;
        }
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        fieldQuery.setConstraint(RdfResourceEnum.mappingSource.getUri(), new ReferenceConstraint(reference));
        QueryResultList<Representation> resultList = entityhubYard.findRepresentation(fieldQuery);
        if(!resultList.isEmpty()){
            Iterator<Representation> resultIterator = resultList.iterator();
            Entity mapping = loadEntity(resultIterator.next());
           //print warnings in case of multiple mappings
View Full Code Here

    public Collection<Entity> getMappingsByTarget(String targetId) throws YardException{
        if(targetId == null){
            log.warn("NULL parsed as Reference -> call to getMappingsBySymbol ignored (return null)");
            return null;
        }
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        fieldQuery.setConstraint(RdfResourceEnum.mappingTarget.getUri(), new ReferenceConstraint(targetId));
        QueryResultList<Representation> resultList = entityhubYard.findRepresentation(fieldQuery);
        Collection<Entity> mappings = new HashSet<Entity>();
        for(Representation rep : resultList){
            mappings.add(loadEntity(rep));
        }
View Full Code Here

                            .entity(messsage)
                            .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
                }
            }
        }       
        FieldQuery query = JerseyUtils.createFieldQueryForFindRequest(name, property, language,
            limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset,ldpath);
        return executeQuery(ContextHelper.getServiceFromContext(
            SiteManager.class, servletContext), query, acceptedMediaType, headers);
    }
View Full Code Here

        return results;
    }

    @Override
    public Collection<Object> listSubjects(Object property, Object object) {
        FieldQuery query = createQuery();
        if(this.isURI(object)){
            query.setConstraint(property.toString(), new ReferenceConstraint(object.toString()));
        } else if(object instanceof Text){
            Text text = (Text)object;
            TextConstraint constraint;
            if(text.getLanguage() == null){
                constraint = new TextConstraint(text.getText(), PatternType.none, true);
            } else {
                constraint = new TextConstraint(text.getText(), PatternType.none, true,text.getLanguage());
            }
            query.setConstraint(property.toString(), constraint);
        } else {
            Set<DataTypeEnum> dataTypes = DataTypeEnum.getPrimaryDataTypes(object.getClass());
            if(dataTypes == null || dataTypes.isEmpty()){
                query.setConstraint(property.toString(),
                    new ValueConstraint(object));
            } else {
                Collection<String> types = new ArrayList<String>(dataTypes.size());
                for(DataTypeEnum type : dataTypes){
                    types.add(type.getUri());
                }
                query.setConstraint(property.toString(),
                    new ValueConstraint(object,types));
            }
        }
        query.setLimit(Integer.valueOf(DEFAULT_MAX_SELECT));
        QueryResultList<String> results;
        try {
            results = query(query);
           
        } catch (EntityhubException  e) {
            throw new IllegalStateException("Unable to query for resources with value '"+
                object+"' on property '"+property+"'!",e);
        }
        Collection<Object> references;
        if(results.isEmpty()){
            references = Collections.emptySet();
        } else if(results.size() == 1){ //assuming that a single result is a likely case
            references = Collections.singleton(
                (Object)getValueFactory().createReference(results.iterator().next()));
        } else {
            int offset = 0;
            references = new HashSet<Object>(results.size());
            for(String result : results){
                references.add(getValueFactory().createReference(result));
            }
            while(results.size() >= DEFAULT_MAX_SELECT && references.size() <= DEFAULT_MAX_RESULTS-DEFAULT_MAX_SELECT){
                offset = offset + results.size();
                query.setOffset(offset);
                try {
                    results = query(query);
                } catch (EntityhubException e) {
                    throw new IllegalStateException("Unable to query for resources with value '"+
                        object+"' on property '"+property+"'!",e);
View Full Code Here

        }
        if(search == null || search.isEmpty()){
            throw new IllegalArgumentException("The parsed list of search strings MUST NOT be NULL nor empty");
        }
        //build the query and than return the result
        FieldQuery query = factory.createFieldQuery();
        if(includeFields == null){
            query.addSelectedField(field.getUnicodeString());
        } else {
            if(!includeFields.contains(field.getUnicodeString())){
                query.addSelectedField(field.getUnicodeString());
            }
            for(UriRef select : includeFields){
                query.addSelectedField(select.getUnicodeString());
            }
        }
        //also add the entity rankings
        query.addSelectedField(RdfResourceEnum.entityRank.getUri());
        query.setLimit(20);//TODO make configurable
        //List<String> search2 = new ArrayList<String>(search.size() + 1);
        //Collections.reverse(search);
        //search2.add(StringUtils.join(search, " "));
        //search2.addAll(search);
        TextConstraint tc = new TextConstraint(search, languages);
        tc.setProximityRanking(true); //STANBOL-1104
        query.setConstraint(field.getUnicodeString(),tc);
        return query;
    }
View Full Code Here

                                           Integer limit, Integer offset) throws EntitySearcherException {
        Entityhub entityhub = getSearchService();
        if(entityhub == null){
            throw new EntitySearcherException("The Entityhub is currently not active");
        }
        FieldQuery query = EntitySearcherUtils.createFieldQuery(entityhub.getQueryFactory(),
            field, includeFields, search, languages);
        if(limit != null && limit > 0){
            query.setLimit(limit);
        } else if(this.limit != null){
            query.setLimit(this.limit);
        }
        if(offset != null && offset.intValue() > 0){
            query.setOffset(offset.intValue());
        }
        QueryResultList<Representation> results;
        try {
            results = entityhub.find(query);
        } catch (EntityhubException e) {
View Full Code Here

        Site site = getSearchService();
        if(site == null){
            throw new IllegalStateException("ReferencedSite "+siteId+" is currently not available");
        }
        queryStats.begin();
        FieldQuery query = EntitySearcherUtils.createFieldQuery(site.getQueryFactory(),
            field, includeFields, search, languages);
        if(limit != null && limit > 0){
            query.setLimit(limit);
        } else if(this.limit != null){
            query.setLimit(this.limit);
        }
        if(offset != null && offset.intValue() > 0){
            query.setOffset(offset.intValue());
        }
        QueryResultList<Representation> results;
        try {
            results = site.find(query);
        } catch (SiteException e) {
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery

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.