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

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


                    }
                } else if (!texts.isEmpty()) {
                    // NOTE: This will use OR over all texts. To enforce AND one
                    // would need to parse a single string with all values e.g. by
                    // using StringUtils.join(texts," ")
                    query.setConstraint(property.getName(), new TextConstraint(texts));
                    if (ids.size() != propertyEntry.getValue().size()) {
                        log.info("Only some of the parsed values of the field {} are"
                                 + "of type String -> will ignore non-string values");
                    }
                } else if(!values.isEmpty()){
                    query.setConstraint(property.getName(), new ValueConstraint(values));
                } //else no values ... ignore property
            }
            //clean up
            ids.clear();
            texts.clear();
            values.clear();
        }
        //now add constraints for the collected special properties
        if(!references.isEmpty()){
            //add references constraint
            ReferenceConstraint refConstraint = new ReferenceConstraint(references, MODE.all);
            query.setConstraint(SpecialFieldEnum.references.getUri(), refConstraint);
        }
        if(!fullText.isEmpty()){
            TextConstraint textConstraint = new TextConstraint(fullText);
            query.setConstraint(SpecialFieldEnum.fullText.getUri(), textConstraint);
            //add full text constraint
        }
        if(similarityContext.length() > 0 && !similarityFields.isEmpty()){
            //add similarity constraint
View Full Code Here


                if(value != null && value.getValue() instanceof String){
                    values.add((String)value.getValue());
                }
            }
        }
        query.setConstraint(NAME_FIELD, new TextConstraint(values));
    }
View Full Code Here

            }
            if(langs.length<1){
                log.warn("Unable to parse a language form \"%s\"! A language filter MUST define at least a singel language. No filter will be used."+filterString);
                return null;
            } else {
                return new TextConstraint((String)null,langs);
            }
        } else {
            log.warn(String.format("Filters need to start with \"p=\" (dataType) or \"@=\" (language). Parsed filter: \"%s\".",filterString));
            return null;
        }
View Full Code Here

            Collection<String> selectedFields = new ArrayList<String>();
            selectedFields.add(field); //select also the field used to find entities
            query.addSelectedFields(selectedFields);
        }
        if (language == null || language.trim().isEmpty()) {
            query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false));
        } else {
            query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false, language));
        }
        if (limit != null && limit > 0) {
            query.setLimit(limit);
        }
        if(offset != null && offset > 0) {
View Full Code Here

                message.append("Parsed TextConstraint doese not define a valid (none empty) value for the 'text' property !\n");
                message.append("Parsed Constraint: \n");
                message.append(jConstraint.toString(4));
                throw new IllegalArgumentException(message.toString());
            }
            constraint = new TextConstraint(textConstraints,
                patternType,caseSensitive,
                languages == null?null:languages.toArray(new String[languages.size()]));
        } else {
            StringBuilder message = new StringBuilder();
            message.append("Parsed TextConstraint doese not define the required field 'text'!\n");
View Full Code Here

                 *    mappings that define no language filter
                 * b) calculate the mapped fields. Possible there are no mappings
                 *    left. Than we need not to process all the values
                 */
                Set<String> targetFields = new HashSet<String>();
                TextConstraint globalFilter = null;
                Collection<Object> globalFiltered = null;
                /*
                 * NOTE: the mappings are sorted in the way, that the most
                 *   prominent one will be at index 0. The wildcard "*" will
                 *   be always the last.
View Full Code Here

            case value:
                ValueConstraint valueConstraint = (ValueConstraint)mapping.getFilter();
                processFilter(valueConstraint,filtered,valueFactory);
                break;
            case text:
                TextConstraint textConstraint = (TextConstraint)mapping.getFilter();
                //for wildcard mappings only filter TextValues. if the mapping is
                //for a specific field filter also non text values.
                processFilter(textConstraint,filtered,!mapping.usesWildcard());
                break;
            default:
View Full Code Here

        test2.add(field, "This is the text content of a field with value2.");
        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2));
        assertNotNull(updatedIterable);

        FieldQuery query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("text content")));
        QueryResultList<Representation> results = yard.find(query);
        assertEquals(2, results.size());

        // fetch the light / minimal representation
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("value2")));
        results = yard.find(query);
        assertEquals(1, results.size());
        Representation result = results.iterator().next();
        assertEquals("urn:yard.test.testFieldQuery:representation.id2", result.getId());
        assertEquals(null, result.getFirst(field));
View Full Code Here

        // assertEquals(0.80, first.getFirst("http://www.iks-project.eu/ontology/rick/query/score"));

        // combine similarity with traditional filtering
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
        query.setConstraint(filterfield, new TextConstraint(Arrays.asList("other")));
        results = yard.find(query);
        assertEquals(1, results.size());
        it = results.iterator();
        first = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2", first.getId());
View Full Code Here

    /**
     * @param indexConstraint
     * @param textConstraint
     */
    private void initTextConstraint(IndexConstraint indexConstraint) {
        TextConstraint textConstraint = (TextConstraint)indexConstraint.getConstraint();
        ConstraintValue constraintValue = new ConstraintValue();
        for(String text : textConstraint.getTexts()){
            constraintValue.getValues().add(indexValueFactory.createIndexValue(
                valueFactory.createText(text)));
        }
        //use a index field for DataType, Languages and the Field
        indexConstraint.setIndexFieldConstraints(
            new IndexField(indexConstraint.getPath(),
                IndexDataTypeEnum.TXT.getIndexType(),
                textConstraint.getLanguages()));
        //add the value for the constraint
        switch (textConstraint.getPatternType()) {
            case none:
                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.EQ, constraintValue);
                break;
            case wildcard:
                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.WILDCARD, constraintValue);
                break;
            case regex:
                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.REGEX, constraintValue);
                break;
            default:
                indexConstraint.setInvalid(String.format(
                    "PatterType %s not supported for Solr Index Queries!", textConstraint.getPatternType()));
        }
    }
View Full Code Here

TOP

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

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.