How can I create customized builtins in Jena?

2019-07-17 12:17发布

问题:

I just wondering how I can create new custom builtins for Jena. I know that for this purpose it should be used both the class "BaseBuiltin" and the class "BuiltinRegistry" (but how ?).

I have also found out a plugin for Eclipse which is called "SADL" but I am not sure if I can use if for this purpose. If I can...which method is better and why ?

Could anyone of you explain me which way I should take ?

Cheers!

回答1:

In a follow-up to a later question of yours, I provide code demonstrating the answer to this question, as well.

I've duplicated it here for the sake of people who need a quick reference. This builtin has the name example and delegates the majority of it's functionality to BaseBuiltin as per writing Jena builtin-ins and the Official Documentation. Thanks to JT for the reference to his previous question.

BuiltinRegistry.theRegistry.register( new BaseBuiltin() {
    @Override
    public String getName() {
        return "example";
    }
    @Override
    public void headAction( final Node[] args, final int length, final RuleContext context ) {
        System.out.println("Head Action: "+Arrays.toString(args));
    }
} );