Search in sources :

Example 1 with ClerezzaSparqlObject

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

the class UpperCaseAtom method adapt.

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

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

the class VariableAtom method adapt.

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

use of org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject 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;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom objectProperty = tmp.getObjectProperty();
    IObjectAtom argument2 = tmp.getArgument2();
    ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(objectProperty, ConstructQuery.class);
    ClerezzaSparqlObject argument2CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
    Object arg1 = argument1CSO.getClerezzaObject();
    Object dt = datatypePropertyCSO.getClerezzaObject();
    Object arg2 = argument2CSO.getClerezzaObject();
    UriRefOrVariable subject;
    UriRefOrVariable predicate;
    ResourceOrVariable object;
    if (arg1 instanceof Variable) {
        subject = new UriRefOrVariable((Variable) arg1);
    } else if (arg1 instanceof IRI) {
        subject = new UriRefOrVariable((IRI) arg1);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (dt instanceof Variable) {
        predicate = new UriRefOrVariable((Variable) dt);
    } else if (dt instanceof IRI) {
        predicate = new UriRefOrVariable((IRI) dt);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (arg2 instanceof Variable) {
        object = new UriRefOrVariable((Variable) arg2);
    } else if (dt instanceof IRI) {
        object = new UriRefOrVariable((IRI) arg2);
    } 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)

Example 4 with ClerezzaSparqlObject

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

the class LengthAtom method adapt.

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

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

the class LessEqualThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    ClerezzaSparqlObject clerezzaArgument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject clerezzaArgument2 = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
    Expression lhe = (Expression) clerezzaArgument1.getClerezzaObject();
    Expression rhe = (Expression) clerezzaArgument2.getClerezzaObject();
    return (T) new ClerezzaSparqlObject(new BinaryOperation("<=", lhe, rhe));
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) 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