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

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


    /**
     * @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


        // query.setConstraint(SpecialFieldEnum.fullText.getUri(), new TextConstraint(Arrays.asList(
        // "text value","anothertest","some more values"),true));
        // query.setConstraint("urn:field2a", new TextConstraint(":-]"));
        // //tests escaping of REGEX
        // query.setConstraint("urn:field3", new TextConstraint("language text","en"));
        query.setConstraint("urn:field4", new TextConstraint("multi language text", "en", "de", null));
        // query.setConstraint("urn:field5", new
        // TextConstraint("wildcar*",PatternType.wildcard,false,"en","de"));
        // query.addSelectedField("urn:field5");
        // query.setConstraint("urn:field6", new TextConstraint("^regex",PatternType.REGEX,true));
        // query.setConstraint("urn:field7", new
View Full Code Here

                if(valueConstraint.getMode() != null){
                    jConstraint.put("mode", valueConstraint.getMode());
                }
                break;
            case text:
                TextConstraint textConstraint = (TextConstraint) constraint;
                Collection<String> languages = textConstraint.getLanguages();
                if (languages != null && !languages.isEmpty()) {
                    if(languages.size() == 1){
                        jConstraint.put("language", languages.iterator().next());
                    } else {
                        jConstraint.put("language", new JSONArray(languages));
                    }
                }
                jConstraint.put("patternType", textConstraint.getPatternType().name());
                if (textConstraint.getTexts() != null && !textConstraint.getTexts().isEmpty()) {
                    if(textConstraint.getTexts().size() == 1){ //write a string
                        jConstraint.put("text", textConstraint.getTexts().get(0));
                    } else { //write an array
                        jConstraint.put("text", textConstraint.getTexts());
                    }
                }
                if(textConstraint.isCaseSensitive()){
                    jConstraint.put("caseSensitive", true);
                } //else default is false
                break;
            case range:
                RangeConstraint rangeConstraint = (RangeConstraint) constraint;
View Full Code Here

                    }
                } 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

        FieldQueryFactory qf = DefaultQueryFactory.getInstance();
        FieldQuery fieldQuery = qf.createFieldQuery();
        Collection<String> selectedFields = new ArrayList<String>();
        selectedFields.add(DEFAULT_AUTOCOMPLETE_SEARCH_FIELD);
        fieldQuery.addSelectedFields(selectedFields);
        fieldQuery.setConstraint(DEFAULT_AUTOCOMPLETE_SEARCH_FIELD, new TextConstraint(pattern,
                PatternType.wildcard, false, "en"));
        fieldQuery.setLimit(AUTOCOMPLETED_KEYWORD_NUMBER);
        fieldQuery.setOffset(0);

        List<String> result = new ArrayList<String>();
View Full Code Here

        FieldQueryFactory qf = DefaultQueryFactory.getInstance();
        FieldQuery fieldQuery = qf.createFieldQuery();
        Collection<String> selectedFields = new ArrayList<String>();
        selectedFields.add(RDFS.label.getUnicodeString());
        fieldQuery.addSelectedFields(selectedFields);
        fieldQuery.setConstraint(RDFS.label.getUnicodeString(), new TextConstraint(keyword,
                PatternType.wildcard, false, "en"));
        fieldQuery.setLimit(1);
        fieldQuery.setOffset(0);
        return fieldQuery;
    }
View Full Code Here

            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!",
View Full Code Here

                if(valueConstraint.getMode() != null){
                    jConstraint.put("mode", valueConstraint.getMode());
                }
                break;
            case text:
                TextConstraint textConstraint = (TextConstraint) constraint;
                Collection<String> languages = textConstraint.getLanguages();
                if (languages != null && !languages.isEmpty()) {
                    if(languages.size() == 1){
                        jConstraint.put("language", languages.iterator().next());
                    } else {
                        jConstraint.put("language", new JSONArray(languages));
                    }
                }
                jConstraint.put("patternType", textConstraint.getPatternType().name());
                if (textConstraint.getTexts() != null && !textConstraint.getTexts().isEmpty()) {
                    if(textConstraint.getTexts().size() == 1){ //write a string
                        jConstraint.put("text", textConstraint.getTexts().get(0));
                    } else { //write an array
                        jConstraint.put("text", textConstraint.getTexts());
                    }
                }
                if(textConstraint.isCaseSensitive()){
                    jConstraint.put("caseSensitive", true);
                } //else default is false
                //write the proximity ranking state (if defined)
                if(textConstraint.isProximityRanking() != null){
                    jConstraint.put("proximityRanking", textConstraint.isProximityRanking());
                }
                break;
            case range:
                RangeConstraint rangeConstraint = (RangeConstraint) constraint;
                Set<DataTypeEnum> dataTypes = EnumSet.noneOf(DataTypeEnum.class);
View Full Code Here

    /**
     * @param indexConstraint
     * @param textConstraint
     */
    private void initTextConstraint(IndexConstraint indexConstraint) {
        TextConstraint textConstraint = (TextConstraint)indexConstraint.getConstraint();
        ConstraintValue constraintValue = new ConstraintValue();
        //init the boost
        addBoost(constraintValue, textConstraint);
        //init the Phrase Query based on the ProximityRanking state
        if(textConstraint.isProximityRanking() != null){
            constraintValue.setProperty(QueryConst.PHRASE_QUERY_STATE, textConstraint.isProximityRanking());
        } else {
            //TODO: maybe make the default configureable for the SolrYard
            constraintValue.setProperty(QueryConst.PHRASE_QUERY_STATE, QueryConst.DEFAULT_PHRASE_QUERY_STATE);
        }
        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.