use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class UnionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.UnionAtom tmp = (org.apache.stanbol.rules.manager.atoms.UnionAtom) ruleAtom;
AtomList atomList1 = tmp.getAtomList1();
AtomList atomList2 = tmp.getAtomList2();
String scope1 = "";
for (RuleAtom inGroupRuleAtom : atomList1) {
if (!scope1.isEmpty()) {
scope1 += " . ";
}
try {
SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
scope1 += inGroupSparqlAtom.getObject();
} catch (UnsupportedTypeForExportException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
} catch (UnavailableRuleObjectException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
}
String scope2 = "";
for (RuleAtom inGroupRuleAtom : atomList2) {
if (!scope2.isEmpty()) {
scope2 += " . ";
}
try {
SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
scope2 += inGroupSparqlAtom.getObject();
} catch (UnsupportedTypeForExportException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
} catch (UnavailableRuleObjectException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
}
String sparqlUnion = " { " + scope1 + " } UNION { " + scope2 + " } ";
return (T) new SPARQLFunction(sparqlUnion);
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class RuleImpl method toString.
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(ruleName);
stringBuilder.append("[");
boolean firstLoop = true;
// add the rule body
for (RuleAtom atom : body) {
if (!firstLoop) {
stringBuilder.append(" . ");
} else {
firstLoop = false;
}
stringBuilder.append(atom.toString());
}
// add the rule head
if (head != null) {
stringBuilder.append(" -> ");
firstLoop = true;
for (RuleAtom atom : head) {
if (!firstLoop) {
stringBuilder.append(" . ");
} else {
firstLoop = false;
}
stringBuilder.append(atom.toString());
}
}
stringBuilder.append("]");
return stringBuilder.toString();
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class AtomIterator method next.
public RuleAtom next() {
RuleAtom atom = kReSRuleAtoms[currentIndex];
currentIndex++;
return atom;
}
Aggregations