Search in sources :

Example 21 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject in project stanbol by apache.

the class StrAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StrAtom tmp = (org.apache.stanbol.rules.manager.atoms.StrAtom) ruleAtom;
    IObjectAtom uriResource = tmp.getUriResource();
    ClerezzaSparqlObject clerezzaSparqlObject = (ClerezzaSparqlObject) adapter.adaptTo(uriResource, ConstructQuery.class);
    List<Expression> expressions = new ArrayList<Expression>();
    expressions.add((Expression) clerezzaSparqlObject.getClerezzaObject());
    return (T) new ClerezzaSparqlObject(new BuiltInCall("STR", expressions));
}
Also used : ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 22 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject in project stanbol by apache.

the class StringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.StringAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringAtom) ruleAtom;
    String string = tmp.getString();
    Expression exp = null;
    if (string.startsWith("\"") && string.endsWith("\"")) {
        string = string.substring(1, string.length() - 1);
    }
    if (string.startsWith(Symbols.variablesPrefix)) {
        exp = new Variable(string.replace(Symbols.variablesPrefix, ""));
    } else {
        exp = new LiteralExpression(new PlainLiteralImpl(string));
    }
    return (T) new ClerezzaSparqlObject(exp);
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 23 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject in project stanbol by apache.

the class SubstringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getStringFunctionAtom();
    NumericFunctionAtom start = tmp.getStart();
    NumericFunctionAtom length = tmp.getLength();
    ClerezzaSparqlObject clerezzaArgument = (ClerezzaSparqlObject) adapter.adaptTo(argument, ConstructQuery.class);
    ClerezzaSparqlObject clerezzaStart = (ClerezzaSparqlObject) adapter.adaptTo(start, ConstructQuery.class);
    ClerezzaSparqlObject clerezzaLength = (ClerezzaSparqlObject) adapter.adaptTo(length, ConstructQuery.class);
    List<Expression> argumentExpressions = new ArrayList<Expression>();
    argumentExpressions.add((Expression) clerezzaArgument.getClerezzaObject());
    argumentExpressions.add((Expression) clerezzaStart.getClerezzaObject());
    argumentExpressions.add((Expression) clerezzaLength.getClerezzaObject());
    FunctionCall functionCall = new FunctionCall(new IRI("<http://www.w3.org/2005/xpath-functions#substring>"), argumentExpressions);
    return (T) new ClerezzaSparqlObject(functionCall);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ArrayList(java.util.ArrayList) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) FunctionCall(org.apache.clerezza.rdf.core.sparql.query.FunctionCall)

Example 24 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject in project stanbol by apache.

the class StringVariableAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StringVariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringVariableAtom) ruleAtom;
    String variableName = tmp.getVariableName();
    Variable variable = new Variable(variableName);
    return (T) new ClerezzaSparqlObject(variable);
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 25 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject in project stanbol by apache.

the class SubtractionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) ruleAtom;
    NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
    NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
    ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom1, ConstructQuery.class);
    ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom2, ConstructQuery.class);
    Expression lhsOperand = (Expression) argument1.getClerezzaObject();
    Expression rhsOperand = (Expression) argument2.getClerezzaObject();
    BinaryOperation binaryOperation = new BinaryOperation("-", lhsOperand, rhsOperand);
    return (T) new ClerezzaSparqlObject(binaryOperation);
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Aggregations

ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)34 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)26 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)25 ArrayList (java.util.ArrayList)13 IRI (org.apache.clerezza.commons.rdf.IRI)13 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)11 BinaryOperation (org.apache.clerezza.rdf.core.sparql.query.BinaryOperation)10 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)10 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)8 FunctionCall (org.apache.clerezza.rdf.core.sparql.query.FunctionCall)7 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)7 BuiltInCall (org.apache.clerezza.rdf.core.sparql.query.BuiltInCall)6 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)6 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)5 LiteralExpression (org.apache.clerezza.rdf.core.sparql.query.LiteralExpression)4 ResourceOrVariable (org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable)4 UriRefOrVariable (org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable)4 SimpleTriplePattern (org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern)4 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)1 Literal (org.apache.clerezza.commons.rdf.Literal)1