Search in sources :

Example 16 with ClerezzaSparqlObject

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

the class NewLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.NewLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.NewLiteralAtom) ruleAtom;
    StringFunctionAtom bindingAtom = tmp.getBinding();
    IObjectAtom variableAtom = tmp.getNewNodeVariable();
    ClerezzaSparqlObject binding = (ClerezzaSparqlObject) adapter.adaptTo(bindingAtom, ConstructQuery.class);
    ClerezzaSparqlObject variable = (ClerezzaSparqlObject) adapter.adaptTo(variableAtom, ConstructQuery.class);
    List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
    bindArgumentExpressions.add((Expression) binding.getClerezzaObject());
    bindArgumentExpressions.add((Expression) variable.getClerezzaObject());
    BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", bindArgumentExpressions);
    return (T) new ClerezzaSparqlObject(bindBuiltInCall);
}
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) 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)

Example 17 with ClerezzaSparqlObject

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

the class NotAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LowerCaseAtom tmp = (org.apache.stanbol.rules.manager.atoms.LowerCaseAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getStringFunctionAtom();
    ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument, ConstructQuery.class);
    List<Expression> argumentExpressions = new ArrayList<Expression>();
    argumentExpressions.add((Expression) argument1.getClerezzaObject());
    BuiltInCall builtInCall = new BuiltInCall("BOUND", argumentExpressions);
    UnaryOperation unaryOperation = new UnaryOperation("!", builtInCall);
    return (T) new ClerezzaSparqlObject(unaryOperation);
}
Also used : UnaryOperation(org.apache.clerezza.rdf.core.sparql.query.UnaryOperation) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) 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)

Example 18 with ClerezzaSparqlObject

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

the class NumberAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.NumberAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumberAtom) ruleAtom;
    String number = tmp.getNumber();
    Expression exp = null;
    if (number.startsWith("\"") && number.endsWith("\"")) {
        number = number.substring(1, number.length() - 1);
    }
    if (number.startsWith(Symbols.variablesPrefix)) {
        exp = new Variable(number.replace(Symbols.variablesPrefix, ""));
    } else {
        exp = new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(number));
    }
    return (T) new ClerezzaSparqlObject(exp);
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) 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 19 with ClerezzaSparqlObject

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

the class StartsWithAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StartsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.StartsWithAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getArgument();
    StringFunctionAtom term = tmp.getTerm();
    ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument, ConstructQuery.class);
    ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(term, ConstructQuery.class);
    List<Expression> argumentExpressions = new ArrayList<Expression>();
    argumentExpressions.add((Expression) argument1.getClerezzaObject());
    argumentExpressions.add((Expression) argument2.getClerezzaObject());
    FunctionCall functionCall = new FunctionCall(new IRI("<http://www.w3.org/2005/xpath-functions#starts-with>"), argumentExpressions);
    return (T) new ClerezzaSparqlObject(functionCall);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ArrayList(java.util.ArrayList) 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 20 with ClerezzaSparqlObject

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

the class TypedLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom expressionAtom = tmp.getValue();
    Literal literal = null;
    if (expressionAtom instanceof StringAtom) {
        String value = expressionAtom.toString();
        literal = LiteralFactory.getInstance().createTypedLiteral(value);
    } else if (expressionAtom instanceof NumberAtom) {
        Number number = ((NumberAtom) expressionAtom).getNumberValue();
        literal = LiteralFactory.getInstance().createTypedLiteral(number);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    LiteralExpression literalExpression = new LiteralExpression(literal);
    return (T) new ClerezzaSparqlObject(literalExpression);
}
Also used : StringAtom(org.apache.stanbol.rules.manager.atoms.StringAtom) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) NumberAtom(org.apache.stanbol.rules.manager.atoms.NumberAtom) Literal(org.apache.clerezza.commons.rdf.Literal) 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