Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一旦我';我已经写了一个内置的,我需要做什么才能让推理者意识到这一点?_Java_Eclipse_Rdf_Jena_Jena Rules - Fatal编程技术网

Java 一旦我';我已经写了一个内置的,我需要做什么才能让推理者意识到这一点?

Java 一旦我';我已经写了一个内置的,我需要做什么才能让推理者意识到这一点?,java,eclipse,rdf,jena,jena-rules,Java,Eclipse,Rdf,Jena,Jena Rules,我已经编写了一个自定义的内置程序,用于我的项目,但我真的不知道如何使用它。 我写了两节课。其中一个是我制作的内置代码(使用BaseBuiltin),另一个是我注册的新内置代码(使用BuiltinRegistry) 我已经尝试过使用默认内置项,编写规则,在一个文本文件中使用默认内置项,该文本文件可以通过Java从Eclipse读取。在这种情况下,我没有任何问题。我怎样才能使用我的内置软件?我应该在一些文件中导入(或包括)一些内容吗?首先定义内置的,通常是通过扩展BaseBuiltin,然后使用Bu

我已经编写了一个自定义的内置程序,用于我的项目,但我真的不知道如何使用它。 我写了两节课。其中一个是我制作的内置代码(使用
BaseBuiltin
),另一个是我注册的新内置代码(使用
BuiltinRegistry


我已经尝试过使用默认内置项,编写规则,在一个文本文件中使用默认内置项,该文本文件可以通过Java从Eclipse读取。在这种情况下,我没有任何问题。我怎样才能使用我的内置软件?我应该在一些文件中导入(或包括)一些内容吗?

首先定义
内置的
,通常是通过扩展
BaseBuiltin
,然后使用
BuiltinRegistry.theRegistry.register(Builtin)
使其可用于基于规则的推理

一旦这样做了,您就需要实际使用一个规则来引用您的
内置代码
,以便触发它

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

final String exampleRuleString =
    "[mat1: (?s ?p ?o)\n\t-> print(?s ?p ?o),\n\t   example(?s ?p ?o)\n]"+
    "";
System.out.println(exampleRuleString);

/* I tend to use a fairly verbose syntax for parsing out my rules when I construct them
 * from a string. You can read them from whatever other sources.
 */
final List<Rule> rules;
try( final BufferedReader src = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(exampleRuleString.getBytes()))) ) {
    rules = Rule.parseRules(Rule.rulesParserFromReader(src));
}

/* Construct a reasoner and associate the rules with it  */
final GenericRuleReasoner reasoner = (GenericRuleReasoner) GenericRuleReasonerFactory.theInstance().create(null);
reasoner.setRules(rules);

/* Create & Prepare the InfModel. If you don't call prepare, then
 * rule firings and inference may be deferred until you query the
 * model rather than happening at insertion. This can make you think
 * that your Builtin is not working, when it is.
 */
final InfModel infModel = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
infModel.prepare();

/* Add a triple to the graph: 
* [] rdf:type rdfs:Class
*/
infModel.createResource(RDFS.Class);

我要试试看!非常感谢你的帮助!你好!我已经试过密码了。我只有一个问题。我在哪里可以使用头部动作法?我的意思是,我的程序打印:1)前向链接规则的字符串2)调用打印内置的结果如何打印最后的结果?干杯如果您的
内置
是前向链接规则的结果/结果,则调用。每当触发规则本身(即:满足所有先行项)时,就会触发它。“结果”是规则的触发和随后的输出<代码>头部动作:…< /代码>。如果这个答案在帮助您解决您的问题方面是令人满意的,您可能希望考虑。这减少了未回答问题的数量。
[mat1: (?s ?p ?o)
    -> print(?s ?p ?o),
       example(?s ?p ?o)
]
-2b47400d:14593fc1564:-7fff rdf:type rdfs:Class 
Head Action: [-2b47400d:14593fc1564:-7fff, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2000/01/rdf-schema#Class]