Search in sources :

Example 31 with SPARQLObject

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

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

the class LocalNameAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    IObjectAtom argument = ((org.apache.stanbol.rules.manager.atoms.LocalNameAtom) ruleAtom).getUriResource();
    SPARQLObject sparqlObject = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "<http://jena.hpl.hp.com/ARQ/function#localname>(" + sparqlObject.getObject() + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 33 with SPARQLObject

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

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String argument1SPARQL = null;
    String argument2SPARQL = null;
    boolean negativeArg = false;
    boolean negativeClass = false;
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    SPARQLObject sparqlArgument1 = adapter.adaptTo(tmp.getArgument1(), SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(tmp.getClassResource(), SPARQLObject.class);
    if (negativeArg || negativeClass) {
        String optional = sparqlArgument1.getObject() + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> " + sparqlArgument2.getObject();
        ArrayList<String> filters = new ArrayList<String>();
        if (negativeArg) {
            filters.add("!bound(" + argument1SPARQL + ")");
        }
        if (negativeClass) {
            filters.add("!bound(" + argument2SPARQL + ")");
        }
        String[] filterArray = new String[filters.size()];
        filterArray = filters.toArray(filterArray);
        return (T) new SPARQLNot(optional, filterArray);
    } else {
        return (T) new SPARQLTriple(sparqlArgument1.getObject() + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> " + sparqlArgument2.getObject());
    }
}
Also used : SPARQLNot(org.apache.stanbol.rules.adapters.sparql.SPARQLNot) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) ArrayList(java.util.ArrayList) SPARQLTriple(org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)

Example 34 with SPARQLObject

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

the class GreaterThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.GreaterThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterThanAtom) 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 35 with SPARQLObject

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

the class LessEqualThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) 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)

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