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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations