Search in sources :

Example 26 with SPARQLObject

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

the class UnionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.UnionAtom tmp = (org.apache.stanbol.rules.manager.atoms.UnionAtom) ruleAtom;
    AtomList atomList1 = tmp.getAtomList1();
    AtomList atomList2 = tmp.getAtomList2();
    String scope1 = "";
    for (RuleAtom inGroupRuleAtom : atomList1) {
        if (!scope1.isEmpty()) {
            scope1 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope1 += inGroupSparqlAtom.getObject();
        } 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());
        }
    }
    String scope2 = "";
    for (RuleAtom inGroupRuleAtom : atomList2) {
        if (!scope2.isEmpty()) {
            scope2 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope2 += inGroupSparqlAtom.getObject();
        } 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());
        }
    }
    String sparqlUnion = " { " + scope1 + " } UNION { " + scope2 + " } ";
    return (T) new SPARQLFunction(sparqlUnion);
}
Also used : AtomList(org.apache.stanbol.rules.base.api.util.AtomList) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Example 27 with SPARQLObject

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

the class ConcatAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ConcatAtom tmp = (org.apache.stanbol.rules.manager.atoms.ConcatAtom) ruleAtom;
    String sparqlConcat = "<http://www.w3.org/2005/xpath-functions#concat>";
    StringFunctionAtom argument1 = tmp.getArgument1();
    StringFunctionAtom argument2 = tmp.getArgument2();
    SPARQLObject sparqlArgument1;
    sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
    String function = sparqlConcat + " (" + sparqlArgument1.getObject() + ", " + sparqlArgument2.getObject() + ")";
    return (T) new SPARQLFunction(function);
}
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 28 with SPARQLObject

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

the class DatavaluedPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
    SPARQLObject sparqlArgument1 = adapter.adaptTo(tmp.getArgument1(), SPARQLObject.class);
    SPARQLObject sparqlDT = adapter.adaptTo(tmp.getDatatypeProperty(), SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(tmp.getArgument2(), SPARQLObject.class);
    return (T) new SPARQLTriple(sparqlArgument1.getObject() + " " + sparqlDT.getObject() + " " + sparqlArgument2.getObject());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLTriple(org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)

Example 29 with SPARQLObject

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

the class GreaterEqualThanAtom method adapt.

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

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

the class IndividualPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom) ruleAtom;
    SPARQLObject sparqlArgument1 = adapter.adaptTo(tmp.getArgument1(), SPARQLObject.class);
    SPARQLObject sparqlDT = adapter.adaptTo(tmp.getObjectProperty(), SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(tmp.getArgument2(), SPARQLObject.class);
    return (T) new SPARQLTriple(sparqlArgument1.getObject() + " " + sparqlDT.getObject() + " " + sparqlArgument2.getObject());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLTriple(org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)

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