Search in sources :

Example 31 with ClerezzaSparqlObject

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

the class NumericVariableAtom method adapt.

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

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

the class SameAtom method adapt.

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

Example 33 with ClerezzaSparqlObject

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

the class ResourceAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.ResourceAtom tmp = (org.apache.stanbol.rules.manager.atoms.ResourceAtom) ruleAtom;
    String unquotedURI = tmp.toUnquotedString();
    IRI uriRef = new IRI(unquotedURI);
    return (T) new ClerezzaSparqlObject(uriRef);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 34 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