为新内置的Jena创建一个库 [英] Create a library for new built-ins Jena

查看:88
本文介绍了为新内置的Jena创建一个库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为耶拿(Jena)制作了一些新的内置插件.我想创建一个可以放置所有库的库.

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?

推荐答案

请注意,由于这个问题非常广泛,我的答案只是对总体设计的一组建议.首先,我们将从耶拿的做法开始.

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将其规则文件作为类路径资源存储在其分发jar中. jena-core有一个名为etc的程序包(目录),其中存储了多个规则文件.耶拿实施的推理程序实际上只是具有特定规则集的GenericRuleReasoner.例如,

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.

在您的系统中,建议您构建自己的ReasonerFactory实现(我们将其称为MyReasonerFactory).在MyReasonerFactory中,您可以有一个静态初始化块,该块将为您的特定于域的推理程序注册Builtin.当有人调用ReasonerFactory#create(Resource)时,您可以从类路径中加载规则,然后创建一个使用这些规则的GenericRuleReasoner.

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();
    }
}

这篇关于为新内置的Jena创建一个库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆