use of org.apache.clerezza.rdf.core.sparql.query.Expression in project stanbol by apache.
the class StringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.StringAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringAtom) ruleAtom;
String string = tmp.getString();
Expression exp = null;
if (string.startsWith("\"") && string.endsWith("\"")) {
string = string.substring(1, string.length() - 1);
}
if (string.startsWith(Symbols.variablesPrefix)) {
exp = new Variable(string.replace(Symbols.variablesPrefix, ""));
} else {
exp = new LiteralExpression(new PlainLiteralImpl(string));
}
return (T) new ClerezzaSparqlObject(exp);
}
use of org.apache.clerezza.rdf.core.sparql.query.Expression in project stanbol by apache.
the class SubstringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
StringFunctionAtom argument = tmp.getStringFunctionAtom();
NumericFunctionAtom start = tmp.getStart();
NumericFunctionAtom length = tmp.getLength();
ClerezzaSparqlObject clerezzaArgument = (ClerezzaSparqlObject) adapter.adaptTo(argument, ConstructQuery.class);
ClerezzaSparqlObject clerezzaStart = (ClerezzaSparqlObject) adapter.adaptTo(start, ConstructQuery.class);
ClerezzaSparqlObject clerezzaLength = (ClerezzaSparqlObject) adapter.adaptTo(length, ConstructQuery.class);
List<Expression> argumentExpressions = new ArrayList<Expression>();
argumentExpressions.add((Expression) clerezzaArgument.getClerezzaObject());
argumentExpressions.add((Expression) clerezzaStart.getClerezzaObject());
argumentExpressions.add((Expression) clerezzaLength.getClerezzaObject());
FunctionCall functionCall = new FunctionCall(new IRI("<http://www.w3.org/2005/xpath-functions#substring>"), argumentExpressions);
return (T) new ClerezzaSparqlObject(functionCall);
}
use of org.apache.clerezza.rdf.core.sparql.query.Expression in project stanbol by apache.
the class SubtractionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) 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);
}
use of org.apache.clerezza.rdf.core.sparql.query.Expression in project stanbol by apache.
the class SumAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) 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);
}
use of org.apache.clerezza.rdf.core.sparql.query.Expression in project stanbol by apache.
the class ClerezzaAdapter method adaptRuleTo.
@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleTo(Rule rule, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
List<Expression> expressions = new ArrayList<Expression>();
Iterator<RuleAtom> it = rule.getBody().iterator();
while (it.hasNext()) {
RuleAtom ruleAtom = it.next();
ClerezzaSparqlObject clerezzaSparqlObject = null;
log.debug("Type to adapt {}", type);
clerezzaSparqlObject = (ClerezzaSparqlObject) adaptRuleAtomTo(ruleAtom, type);
Object clerezzaObj = clerezzaSparqlObject.getClerezzaObject();
if (clerezzaObj instanceof TriplePattern) {
triplePatterns.add((TriplePattern) clerezzaObj);
} else if (clerezzaObj instanceof Expression) {
expressions.add((Expression) clerezzaObj);
}
}
SimpleGroupGraphPattern groupGraphPattern = new SimpleGroupGraphPattern();
groupGraphPattern.addTriplePatterns(triplePatterns);
for (Expression expression : expressions) {
groupGraphPattern.addConstraint(expression);
}
triplePatterns = new HashSet<TriplePattern>();
it = rule.getHead().iterator();
while (it.hasNext()) {
RuleAtom ruleAtom = it.next();
ClerezzaSparqlObject clerezzaSparqlObject = (ClerezzaSparqlObject) adaptRuleAtomTo(ruleAtom, type);
triplePatterns.add((TriplePattern) clerezzaSparqlObject.getClerezzaObject());
}
SimpleConstructQuery constructQuery = new SimpleConstructQuery(triplePatterns);
constructQuery.setQueryPattern(groupGraphPattern);
return (T) constructQuery;
}
Aggregations