在Java中使用Jess规则:断言的实例不能用于进一步推理

时间:2015-05-16 09:54:36

标签: java rules protege jess

我正在使用JessTab API通过Jess规则在Java中操作本体。以类Person为例的简单本体用作示例。我从Java运行以下代码来为Person类声明新实例:

private final Rete r = new Rete();
Random randomGenerator = new Random();
r.executeCommand("(make-instance test of http://www.owl-ontologies.com/Ontology1431767500.owl#Person)");

列出类Person的个体的简单规则如下所示不会显示新声明的实例测试:

(defrule listPeople
    (object (is-a http://www.owl-ontologies.com/Ontology1431767500.owl#Person)              
        (OBJECT ?p)              
    ) 
=>  
    (printout t "Person instances: " (instance-name ?p) crlf)    
)

使用JessTab在Protege IDE中执行此操作会显示实例,但从Java NetBeans运行时不会考虑make-instance命令声明的事实。我尝试在执行make-instance命令后保存本体,然后运行规则,但出现相同的行为,即不考虑新事实。我是否必须运行特定的JessTab命令?

1 个答案:

答案 0 :(得分:0)

make-instance命令应包含map关键字:

r.executeCommand("(make-instance test of http://www.owl-ontologies.com/Ontology1431767500.owl#Person map)");