Create a library for new built-ins Jena

匆匆过客 提交于 2019-12-25 02:22:14

问题


I have made some new built-ins for Jena. I would like to create a library where I can put all of them.

How can I do that ? And how can I create my rules in this case ? Need I to import some files in the rule file?


回答1:


Please note that, as this question is extremely broad, my answer is merely a set of suggestions towards an overall design. First, we'll begin with how Jena does it.

Apache Jena stores its rule files as classpath resources within its distribution jars. jena-core has a package (directory) called etc in which it stores several rules files. The reasoners that Jena has implemented are effectively just the GenericRuleReasoner with a specific rule set. For example, FBRuleReasoner#loadRules() method is used to retrieve the ruleset that this reasoner will utilize. You should look at where it is called from in order to figure out how you would use such a paradigm.

In your system, I'd suggest constructing your own implementation of ReasonerFactory (let's call it MyReasonerFactory). In MyReasonerFactory, you could have a static initialization block that will register the Builtins for your domain-specific reasoner. When someone calls ReasonerFactory#create(Resource), you can load your rules from the classpath and then create a GenericRuleReasoner that utilizes those rules.

Some pseudo-code (that may not compile) follows:

public class MyReasonerFactory implements ReasonerFactory

    private static final String RULE_LOC = "/some/directory/in/my/jar/filename.extensiondoesntmatter";

    static {
        // register your builtins
    }

    @Override
    public RuleReasoner create(Resource r) {
        final GenericRuleReasoner reasoner = new GenericRuleReasoner(this, r);
        reasoner.setRules(FBRuleReasoner.loadRules(RULE_LOC));
        return reasoner;
    }

    @Override
    public String getUri() {
        return "urn:ex:yourReasoner";
    }

    @Override
    public Model getCapabilities() {
        // Your capabilities are identical to GenericRuleReasoner's
        return GenericRuleReasonerFactory.theInstance().getCapabilities();
    }
}


来源:https://stackoverflow.com/questions/23640770/create-a-library-for-new-built-ins-jena

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!