Search in sources :

Example 11 with SPARQLComparison

use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.

the class LessThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    SPARQLObject sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
    String arg1 = sparqlArgument1.getObject();
    String arg2 = sparqlArgument2.getObject();
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    sb.append(arg1);
    sb.append(" < ");
    sb.append(arg2);
    sb.append(")");
    return (T) new SPARQLComparison(sb.toString());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom)

Example 12 with SPARQLComparison

use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.

the class SumAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) ruleAtom;
    NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
    NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
    try {
        SPARQLObject sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
        SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
        String sparqlFunction1 = sparqlArgument1.getObject();
        String sparqlFunction2 = sparqlArgument2.getObject();
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        sb.append(sparqlFunction1);
        sb.append(" + ");
        sb.append(sparqlFunction2);
        sb.append(")");
        return (T) new SPARQLComparison(sb.toString());
    } catch (UnsupportedTypeForExportException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    } catch (UnavailableRuleObjectException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 13 with SPARQLComparison

use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.

the class StartsWithAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.StartsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.StartsWithAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getArgument();
    StringFunctionAtom term = tmp.getTerm();
    try {
        SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
        SPARQLObject sparqlTerm = adapter.adaptTo(term, SPARQLObject.class);
        String argumentSparql = sparqlArgument.getObject();
        String termSparql = sparqlTerm.getObject();
        return (T) new SPARQLComparison("<http://www.w3.org/2005/xpath-functions#starts-with> (" + argumentSparql + ", " + termSparql + ")");
    } catch (UnsupportedTypeForExportException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    } catch (UnavailableRuleObjectException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Aggregations

SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)13 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)13 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)6 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)5 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)5 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)5 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)3 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)2 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)1