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

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


            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


     
      Collection<String> selectedFields = new ArrayList<String>();
      selectedFields.add(DEFAULT_AUTOCOMPLETE_SEARCH_FIELD);
      query.addSelectedFields(selectedFields);
      query.setConstraint(DEFAULT_AUTOCOMPLETE_SEARCH_FIELD,
          new TextConstraint(textWithDoubleQuote, patternType, true, "en",null));
      query.setLimit(10);
      query.setOffset(0);
     
      final SparqlFieldQuery sparqlQuery = SparqlFieldQueryFactory.getSparqlFieldQuery(query);
     
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

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

     * @param jConstraint
     * @return
     * @throws JSONException
     */
    private static Constraint parseTextConstraint(JSONObject jConstraint) throws JSONException {
        final TextConstraint constraint;
        boolean caseSensitive = jConstraint.optBoolean("caseSensitive", false);
        //parse patternType
        PatternType patternType;
        String jPatternType = jConstraint.optString("patternType",null);
        if(jPatternType == null){
            patternType = PatternType.none;
        } else {
            try {
                patternType = PatternType.valueOf(jPatternType);
            } catch (IllegalArgumentException e) {
                log.warn("Encountered unknown patternType for TextConstraint!",e);
                patternType = PatternType.none;
                StringBuilder message = new StringBuilder();
                message.append("Illegal value for field 'patternType'.\n");
                message.append("Supported values are: ");
                message.append(Arrays.toString(PatternType.values()));
                message.append('\n');
                message.append("Parsed Constraint: \n");
                message.append(jConstraint.toString(4));
                throw new IllegalArgumentException(message.toString());
            }
        }
        //parse languages
        Collection<String> languages;
        String languageKey = null; //support both "languages" and "language"
        if(jConstraint.has("language")){
            languageKey = "language";
        } else if(jConstraint.has("languages")){
            log.warn("The key \"languages\" is deprecated. Use \"language\" instead.");
            languageKey = "languages";
        }
        if(languageKey != null){
            JSONArray jLanguages = jConstraint.optJSONArray(languageKey);
            if(jLanguages != null && jLanguages.length()>0){
                languages = new ArrayList<String>(jLanguages.length());
                for(int i=0;i<jLanguages.length();i++){
                    String lang = jLanguages.getString(i);
                    if(lang != null && !lang.isEmpty()){
                        languages.add(lang);
                    } else if(!languages.contains(null)){
                        languages.add(null);
                    }
                }
                if(languages.isEmpty()){
                    languages = null; //if no one was successfully added set the list back to null
                }
            } else {
                String language = jConstraint.getString(languageKey);
                if(language.isEmpty()){
                    languages = null;
                } else //add the single language
                    languages = Collections.singletonList(language);
                }
            }
        } else {
            languages = null;
        }
        //parse text and create constraint
        if(jConstraint.has("text") && !jConstraint.isNull("text")){
            List<String> textConstraints;
            JSONArray jTextConstraints = jConstraint.optJSONArray("text");
            if(jTextConstraints != null){
                textConstraints = new ArrayList<String>(jTextConstraints.length());
                for(int i=0;i<jTextConstraints.length();i++){
                    String text = jTextConstraints.getString(i);
                    if(text != null && !text.isEmpty()){
                        textConstraints.add(jTextConstraints.getString(i));
                    }
                }
            } else {
                String text = jConstraint.getString("text");
                if(text == null || text.isEmpty()){
                    textConstraints = Collections.emptyList();
                } else {
                    textConstraints = Collections.singletonList(text);
                }
            }
            if(textConstraints.isEmpty()){
                StringBuilder message = new StringBuilder();
                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()]));
            //finally parse the optional termProximity
            if(jConstraint.has("proximityRanking")){
                constraint.setProximityRanking(jConstraint.optBoolean("proximityRanking", false));
            }
        } else {
            StringBuilder message = new StringBuilder();
            message.append("Parsed TextConstraint doese not define the required field 'text'!\n");
            message.append("Parsed Constraint: \n");
View Full Code Here

        // TODO: make case sensitivity configurable
        boolean casesensitive = false;
        String namedEntityLabel = casesensitive ? namedEntity.getName() : namedEntity.getName().toLowerCase();
        if (language != null) {
            // search labels in the language and without language
            labelConstraint = new TextConstraint(namedEntityLabel, casesensitive, language, null);
        } else {
            labelConstraint = new TextConstraint(namedEntityLabel, casesensitive);
        }
        query.setConstraint(nameField, labelConstraint);
        if (OntologicalClasses.DBPEDIA_PERSON.equals(namedEntity.getType())) {
            if (personState) {
                if (personType != null) {
View Full Code Here

        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()){
View Full Code Here

        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

            //languages. NOTE that the field might be null. In that case we
            //need just filter literals by language
            //TODO: maybe cache fieldMappers for sets of languages
            fieldMapper = this.fieldMapper != null ? this.fieldMapper.clone() :
                new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
            fieldMapper.addMapping(new FieldMapping(new TextConstraint(
                (String)null, langs.toArray(new String[graph.size()]))));
        } else { //just use the fieldMapper as parsed in the config
            fieldMapper = this.fieldMapper;
        }
        //execute the field mappings
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.