use of org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin in project jena by apache.
the class TestGenericRuleReasonerConfig method testRuleLoadingWithOverridenBuiltins.
public void testRuleLoadingWithOverridenBuiltins() {
List<Node> savedNode = new ArrayList<>();
Builtin b = new BaseBuiltin() {
@Override
public String getName() {
return "groo";
}
@Override
public int getArgLength() {
return 1;
}
@Override
public void headAction(Node[] args, int length, RuleContext context) {
savedNode.add(getArg(0, args, context));
}
};
BuiltinRegistry r = new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry);
r.register(b);
assertEquals(b, r.getImplementation("groo"));
List<Rule> rules = new ArrayList<>();
//
// note that the head action does not appear to fire unless we put a triple in the head as well.. is
// this expected?
//
rules.add(parseRule("[ (?instance rdf:type ?type) -> groo(?type) ]", r));
GenericRuleReasoner article = new GenericRuleReasoner(rules);
article.setMode(GenericRuleReasoner.FORWARD_RETE);
Model input = ModelFactory.createDefaultModel();
input.add(input.createResource(), RDF.type, input.createResource("http://example.com/Renegade"));
InfModel output = ModelFactory.createInfModel(article, input);
// not optional, inferences are not run if we don't trigger them
output.size();
assertEquals(1, savedNode.size());
assertEquals("http://example.com/Renegade", savedNode.get(0).getURI());
}
Aggregations