Search in sources :

Example 6 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject 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 7 with ClerezzaSparqlObject

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject 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 8 with ClerezzaSparqlObject

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

the class LowerCaseAtom 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());
    FunctionCall functionCall = new FunctionCall(new IRI("<http://www.w3.org/2005/xpath-functions#lower-case>"), 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 9 with ClerezzaSparqlObject

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

the class MultiplicationAtom method adapt.

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

Example 10 with ClerezzaSparqlObject

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

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom classResource = tmp.getClassResource();
    ClerezzaSparqlObject argumentCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject classCSO = (ClerezzaSparqlObject) adapter.adaptTo(classResource, ConstructQuery.class);
    UriRefOrVariable subject;
    UriRefOrVariable predicate = new UriRefOrVariable(RDF.type);
    ResourceOrVariable object;
    Object arg = argumentCSO.getClerezzaObject();
    Object cl = classCSO.getClerezzaObject();
    if (arg instanceof Variable) {
        subject = new UriRefOrVariable((Variable) arg);
    } else if (arg instanceof IRI) {
        subject = new UriRefOrVariable((IRI) arg);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (cl instanceof Variable) {
        object = new ResourceOrVariable((Variable) cl);
    } else if (cl instanceof IRI) {
        object = new ResourceOrVariable((IRI) cl);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) SimpleTriplePattern(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

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