Search in sources :

Example 1 with BuiltInCall

use of org.apache.clerezza.rdf.core.sparql.query.BuiltInCall in project stanbol by apache.

the class IsBlankAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IsBlankAtom tmp = (org.apache.stanbol.rules.manager.atoms.IsBlankAtom) ruleAtom;
    IObjectAtom uriResource = tmp.getUriResource();
    ClerezzaSparqlObject argumentCSO = (ClerezzaSparqlObject) adapter.adaptTo(uriResource, ConstructQuery.class);
    ;
    Object arg = argumentCSO.getClerezzaObject();
    Expression argumentExpression;
    if (arg instanceof Variable) {
        argumentExpression = (Variable) arg;
    } else if (arg instanceof IRI) {
        argumentExpression = new UriRefExpression((IRI) arg);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    List<Expression> expressions = new ArrayList<Expression>();
    expressions.add(argumentExpression);
    return (T) new ClerezzaSparqlObject(new BuiltInCall("isBLANK", expressions));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) UriRefExpression(org.apache.clerezza.rdf.core.sparql.query.UriRefExpression) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) UriRefExpression(org.apache.clerezza.rdf.core.sparql.query.UriRefExpression) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Example 2 with BuiltInCall

use of org.apache.clerezza.rdf.core.sparql.query.BuiltInCall 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;
    StringFunctionAtom parameterFunctionAtom = tmp.getParameterFunctionAtom();
    URIResource variableUriResource = tmp.getVariable();
    ClerezzaSparqlObject iriArgument;
    iriArgument = (ClerezzaSparqlObject) adapter.adaptTo(parameterFunctionAtom, ConstructQuery.class);
    List<Expression> iriArgumentExpressions = new ArrayList<Expression>();
    iriArgumentExpressions.add((Expression) iriArgument.getClerezzaObject());
    BuiltInCall iriBuiltInCall = new BuiltInCall("IRI", iriArgumentExpressions);
    if (variableUriResource instanceof VariableAtom) {
        String variableName = ((VariableAtom) variableUriResource).getVariableName();
        Variable variable = new Variable(variableName);
        List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
        bindArgumentExpressions.add(iriBuiltInCall);
        bindArgumentExpressions.add(variable);
        BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", iriArgumentExpressions);
        return (T) new ClerezzaSparqlObject(bindBuiltInCall);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) VariableAtom(org.apache.stanbol.rules.manager.atoms.VariableAtom) URIResource(org.apache.stanbol.rules.base.api.URIResource) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) 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) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Example 3 with BuiltInCall

use of org.apache.clerezza.rdf.core.sparql.query.BuiltInCall 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 4 with BuiltInCall

use of org.apache.clerezza.rdf.core.sparql.query.BuiltInCall 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 5 with BuiltInCall

use of org.apache.clerezza.rdf.core.sparql.query.BuiltInCall 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)

Aggregations

ArrayList (java.util.ArrayList)6 BuiltInCall (org.apache.clerezza.rdf.core.sparql.query.BuiltInCall)6 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)6 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)6 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)5 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)4 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)4 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)2 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)2 IRI (org.apache.clerezza.commons.rdf.IRI)1 UnaryOperation (org.apache.clerezza.rdf.core.sparql.query.UnaryOperation)1 UriRefExpression (org.apache.clerezza.rdf.core.sparql.query.UriRefExpression)1 URIResource (org.apache.stanbol.rules.base.api.URIResource)1 VariableAtom (org.apache.stanbol.rules.manager.atoms.VariableAtom)1