问题
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 Builtin
s 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