use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.
the class ClerezzaAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipeGood, ConstructQuery.class);
for (ConstructQuery constructQuery : constructQueries) {
ConstructQuery cq = (ConstructQuery) QueryParser.getInstance().parse(constructQuery.toString());
System.out.println(cq.toString());
}
Assert.assertTrue(true);
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
} catch (ParseException e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.
the class JenaAdapter method adaptRecipeTo.
@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = null;
if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
RuleList ruleList = recipe.getRuleList();
Iterator<Rule> ruleIterator = ruleList.iterator();
jenaRules = new ArrayList<com.hp.hpl.jena.reasoner.rulesys.Rule>();
for (int i = 0; ruleIterator.hasNext(); i++) {
jenaRules.add((com.hp.hpl.jena.reasoner.rulesys.Rule) adaptRuleTo(ruleIterator.next(), type));
}
} else {
throw new UnsupportedTypeForExportException("The Jena Adapter does not support the selected serialization : " + type.getCanonicalName());
}
return (T) jenaRules;
}
use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.
the class JenaAdapter method adaptRuleTo.
@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleTo(Rule rule, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
AtomList bodyAtomList = rule.getBody();
AtomList headAtomList = rule.getHead();
List<ClauseEntry> headClauseEntries = new ArrayList<ClauseEntry>();
List<ClauseEntry> bodyClauseEntries = new ArrayList<ClauseEntry>();
variableMap = new HashMap<String, Integer>();
Iterator<RuleAtom> it = headAtomList.iterator();
while (it.hasNext()) {
RuleAtom atom = it.next();
ClauseEntry clauseEntry = adaptRuleAtomTo(atom, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
if (clauseEntry instanceof HigherOrderClauseEntry) {
List<ClauseEntry> clauseEntries = ((HigherOrderClauseEntry) clauseEntry).getClauseEntries();
for (ClauseEntry ce : clauseEntries) {
headClauseEntries.add(ce);
}
} else {
headClauseEntries.add(clauseEntry);
}
}
it = bodyAtomList.iterator();
while (it.hasNext()) {
RuleAtom atom = it.next();
ClauseEntry clauseEntry = adaptRuleAtomTo(atom, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
if (clauseEntry instanceof HigherOrderClauseEntry) {
List<ClauseEntry> clauseEntries = ((HigherOrderClauseEntry) clauseEntry).getClauseEntries();
for (ClauseEntry ce : clauseEntries) {
bodyClauseEntries.add(ce);
}
} else {
bodyClauseEntries.add(clauseEntry);
}
}
return (T) new com.hp.hpl.jena.reasoner.rulesys.Rule(rule.getRuleName(), headClauseEntries, bodyClauseEntries);
} else {
throw new UnsupportedTypeForExportException("The adapter " + getClass() + " does not support type : " + type.getCanonicalName());
}
}
use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.
the class SWRLAdapter method adaptRuleTo.
@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleTo(Rule rule, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
if (type == SWRLRule.class) {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
Set<SWRLAtom> bodyAtoms = new HashSet<SWRLAtom>();
Set<SWRLAtom> headAtoms = new HashSet<SWRLAtom>();
for (RuleAtom atom : rule.getBody()) {
bodyAtoms.add((SWRLAtom) adaptRuleAtomTo(atom, SWRLRule.class));
}
for (RuleAtom atom : rule.getHead()) {
headAtoms.add((SWRLAtom) adaptRuleAtomTo(atom, SWRLRule.class));
}
return (T) factory.getSWRLRule(bodyAtoms, headAtoms);
} else {
throw new UnsupportedTypeForExportException("The adapter " + getClass() + " does not support type : " + type.getCanonicalName());
}
}
use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.
the class SWRLAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<SWRLRule> rules = (List<SWRLRule>) ruleAdapter.adaptTo(recipeGood, SWRLRule.class);
StringBuilder sb = new StringBuilder();
for (SWRLRule rule : rules) {
sb.append(rule.toString());
}
Assert.assertNotSame(sb.toString(), "");
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
}
}
Aggregations