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

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


                    queryString.append("    WHERE { \n");
                }
                first = false;
            }
            String field = fieldConstraint.getKey();
            Constraint constraint = fieldConstraint.getValue();

            log.trace("adding a constraint [type :: {}][field :: {}][prefix :: {}][intent :: {}].",
                new Object[]{constraint.getType(), field, varPrefix, intend});

            switch (constraint.getType()) {
                case value:
                    addValueConstraint(queryString, field, (ValueConstraint) constraint, selectedFields,
                        varPrefix, varNum, intend);
                    break;
                case text:
View Full Code Here


    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);
            }
View Full Code Here

                    queryString.append("    WHERE { \n");
                }
                first = false;
            }
            String field = fieldConstraint.getKey();
            Constraint constraint = fieldConstraint.getValue();

            log.trace("adding a constraint [type :: {}][field :: {}][prefix :: {}][intent :: {}].",
                new Object[]{constraint.getType(), field, varPrefix, intend});

            switch (constraint.getType()) {
                case value:
                    addValueConstraint(queryString, field, (ValueConstraint) constraint, selectedFields,
                        varPrefix, varNum, intend);
                    break;
                case text:
View Full Code Here

        }
        return query;
    }

    private static Constraint parseConstraint(JSONObject jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
        final Constraint constraint;
        if(jConstraint.has("type") && !jConstraint.isNull("type")) {
            String type = jConstraint.getString("type");
            //Event that internally "reference" is not part of the
            //ConstraintType enum it is still present in the serialisation
            //ant the Java API (see ReferenceConstraint class)
            //Value constraints with the dataType Reference and AnyURI are
            //considered to represent reference constraints
            if(type.equals("reference")){
                constraint = parseReferenceConstraint(jConstraint,nsPrefixService);
            } else if (type.equals(ConstraintType.value.name())){
                constraint = parseValueConstraint(jConstraint, nsPrefixService);
            } else if (type.equals(ConstraintType.text.name())){
                constraint = parseTextConstraint(jConstraint);
            } else if (type.equals(ConstraintType.range.name())){
                constraint = parseRangeConstraint(jConstraint,nsPrefixService);
            } else if(type.equals(ConstraintType.similarity.name())){
                constraint = parseSimilarityConstraint(jConstraint, nsPrefixService);
            } else {
                log.warn(String.format("Unknown Constraint Type %s. Supported values are %s",              
                    Arrays.asList("reference",ConstraintType.values())));
                StringBuilder message = new StringBuilder();
                message.append("Parsed Constraint uses an unknown value for 'type'!\n");
                message.append("Supported values: ");
                message.append(ConstraintType.values());
                message.append('\n');
                message.append("Parsed Constraint: \n");
                message.append(jConstraint.toString(4));
                throw new IllegalArgumentException(message.toString());
            }
        } else {
            log.warn(String.format("Earch Constraint MUST HAVE the \"type\" key set to one of the values %s",
                Arrays.asList("reference",ConstraintType.values())));
            StringBuilder message = new StringBuilder();
            message.append("Parsed Constraint does not define a value for the field 'type'!\n");
            message.append("Supported values: ");
            message.append(ConstraintType.values());
            message.append('\n');
            message.append("Parsed Constraint: \n");
            message.append(jConstraint.toString(4));
            throw new IllegalArgumentException(message.toString());
        }
        //finally parse the optional boost
        if(jConstraint.has("boost")){
            double boost = jConstraint.optDouble("boost");
            if(boost == Double.NaN || boost <= 0){
                StringBuilder message = new StringBuilder("The Boost of a Constraint " +
                    "MUST BE a double AND >= 0 (parsed: '");
                message.append(jConstraint.get("boost")).append("')!");
                log.warn(message.toString());
                throw new IllegalArgumentException(message.toString());
            } else {
                constraint.setBoost(boost);
            }
        } //else no boost defined
        return constraint;
    }
View Full Code Here

     * @param jConstraint
     * @return
     * @throws JSONException
     */
    private static Constraint parseRangeConstraint(JSONObject jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
        Constraint constraint;
        boolean inclusive;
        if(jConstraint.has("inclusive")){
            inclusive = jConstraint.getBoolean("inclusive");
        } else {
            log.debug("RangeConstraint does not define the field 'inclusive'. Use false as default!");
View Full Code Here

        FieldQuery query = queryFactory.createFieldQuery();

        // replace spaces with plus to create an AND search for all words in the
        // name!
        Constraint labelConstraint;
        // 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
View Full Code Here

                return null;
            }
        } else {
            fieldPattern = parts[0];
        }
        Constraint filter = null;
        for(int i=1;i<parts.length;i++){
            if("|".equals(parts[i]) && parts.length > i+1){
                filter = parseConstraint(parts[i+1]);
            }
            if(">".equals(parts[i]) && parts.length > i+1){
View Full Code Here

     * @param jConstraint
     * @return
     * @throws JSONException
     */
    private static Constraint parseRangeConstraint(JSONObject jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
        Constraint constraint;
        boolean inclusive;
        if(jConstraint.has("inclusive")){
            inclusive = jConstraint.getBoolean("inclusive");
        } else {
            log.debug("RangeConstraint does not define the field 'inclusive'. Use false as default!");
View Full Code Here

     * @param jConstraint
     * @return
     * @throws JSONException
     */
    private static Constraint parseTextConstraint(JSONObject jConstraint) throws JSONException {
        Constraint constraint;
        boolean caseSensitive = jConstraint.optBoolean("caseSensitive", false);
        //parse patternType
        PatternType patternType;
        String jPatternType = jConstraint.optString("patternType",null);
        if(jPatternType == null){
View Full Code Here

        if(!parts[0].isEmpty() && !parts[0].equals("*")){
            fieldPattern = NamespaceEnum.getFullName(parts[0]);
        } else {
            fieldPattern = parts[0];
        }
        Constraint filter = null;
        for(int i=1;i<parts.length;i++){
            if("|".equals(parts[i]) && parts.length > i+1){
                filter = parseConstraint(parts[i+1]);
            }
            if(">".equals(parts[i]) && parts.length > i+1){
View Full Code Here

TOP

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

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.