use of org.apache.clerezza.rdf.core.sparql.query.TriplePattern 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