log.info("[start] Prepare rules for OWLApi ");
// If recipe exists, return it as a list of SWRL rules
rules = new ArrayList<SWRLRule>();
try {
Recipe recipe = null;
synchronized (store) {
recipe = store.getRecipe(IRI.create(recipeId));
}
log.debug("Recipe is: {}", recipe);
RuleList ruleList = recipe.getkReSRuleList();
log.debug("RuleList is: {}",ruleList);
for(org.apache.stanbol.rules.base.api.Rule r : ruleList ){
SWRLRule swrl = r.toSWRL(OWLManager.getOWLDataFactory());
log.debug("Prepared rule: {}",swrl);
rules.add(swrl);
}
} catch (NoSuchRecipeException e) {
log.error("Recipe {} does not exists", recipeId);
throw new IOException(e);
}
long end = System.currentTimeMillis();
log.info("[end] Prepared {} rules for OWLApi in {} ms.", rules.size(), (end - start));
}
if(rules == null){
log.error("No rules have been loaded");
throw new IOException("No rules loaded");
}
final Iterator<SWRLRule> iterator = Collections.unmodifiableList(rules).iterator();
return new Iterator<T>(){
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
log.error("Cannot remove items from this iterator. This may be cused by an error in the program");
throw new UnsupportedOperationException("Cannot remove items from this iterator");
}
};
case Jena:
List<Rule> jenaRules = null;
if (recipeId != null) {
long start = System.currentTimeMillis();
log.info("[start] Prepare rules for Jena ");
try {
Recipe recipe = null;
synchronized (store) {
recipe = store.getRecipe(IRI.create(recipeId));
}
log.debug("Recipe is: {}", recipe);
jenaRules = recipe.toJenaRules();
} catch (NoSuchRecipeException e) {
log.error("Recipe {} does not exists", recipeId);
throw new IOException(e);
}