Search in sources :

Example 16 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.

the class LetAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LetAtom tmp = (org.apache.stanbol.rules.manager.atoms.LetAtom) ruleAtom;
    String variableArgument = tmp.getVariable().toString().replace(Symbols.variablesPrefix, "");
    StringFunctionAtom argument = tmp.getParameterFunctionAtom();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    String arg = sparqlArgument.getObject();
    String let = "LET (?" + variableArgument + " := " + arg + ")";
    SPARQLObject sparqlObject = new SPARQLFunction(let);
    return (T) sparqlObject;
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)

Example 17 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.

the class LowerCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    StringFunctionAtom argument = ((org.apache.stanbol.rules.manager.atoms.LowerCaseAtom) ruleAtom).getStringFunctionAtom();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "<http://www.w3.org/2005/xpath-functions#lower-case> (" + sparqlArgument.getObject() + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 18 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.

the class DivisionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) ruleAtom;
    NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
    NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
    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 SPARQLFunction(sb.toString());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 19 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.

the class LengthAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LengthAtom tmp = (org.apache.stanbol.rules.manager.atoms.LengthAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getStringFunctionAtom();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    String arg = sparqlArgument.getObject();
    String sparql = "<http://www.w3.org/2005/xpath-functions#string-length> (" + arg + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)

Example 20 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject 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

SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)35 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)16 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)13 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)11 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)10 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)10 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)10 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)7 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)5 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)4 SPARQLTriple (org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)3 ArrayList (java.util.ArrayList)2 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)2 List (java.util.List)1 SPARQLNot (org.apache.stanbol.rules.adapters.sparql.SPARQLNot)1 Rule (org.apache.stanbol.rules.base.api.Rule)1 URIResource (org.apache.stanbol.rules.base.api.URIResource)1 AtomList (org.apache.stanbol.rules.base.api.util.AtomList)1 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)1 Test (org.junit.Test)1