我使用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)
)
在Protege IDE中使用JessTab执行此操作会显示实例,但在Java NetBeans中运行不会考虑make-instance命令断言的事实。我试图在执行make-instance命令后保存本体,然后运行规则,但出现相同的行为,即不考虑新的事实。我必须运行一个特定的JessTab命令吗?
make-instance命令应该包含map关键字:
r.executeCommand("(make-instance test of http://www.owl-ontologies.com/Ontology1431767500.owl#Person map)");