OWLAPI 中的 SWRL 规则创建 ontology

SWRL rules creation in OWLAPI ontology

我有 运行(在 Neatbeans 8.2 中)以下简单的 java 代码,以试验 SWRL 语言:

String base = "http://www.prova/testont.owl";
IRI ontologyIRI = IRI.create(base);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLDataFactory factory = manager.getOWLDataFactory();

OWLClass adult = factory.getOWLClass(IRI.create(ontologyIRI + "#Adult"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLDataProperty hasAge = factory.getOWLDataProperty(IRI.create(ontologyIRI + "#hasAge"));

OWLNamedIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLNamedIndividual andrea = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Andrea"));

OWLClassAssertionAxiom classAssertion = factory.getOWLClassAssertionAxiom(person, john);
manager.addAxiom(ontology, classAssertion);
classAssertion = factory.getOWLClassAssertionAxiom(person, andrea);
manager.addAxiom(ontology, classAssertion);

OWLDatatype integerDatatype = factory.getOWLDatatype(OWL2Datatype.XSD_INTEGER.getIRI());
OWLLiteral literal = factory.getOWLLiteral("41", integerDatatype);
OWLAxiom ax = factory.getOWLDataPropertyAssertionAxiom(hasAge, andrea, literal);
manager.addAxiom(ontology, ax);

literal = factory.getOWLLiteral("15", integerDatatype);
ax = factory.getOWLDataPropertyAssertionAxiom(hasAge, john, literal);
manager.addAxiom(ontology, ax);

SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
ruleEngine.createSWRLRule("r1", "Person(?p)^hasAge(?p,?age)^swrlb:greaterThan(?age,17) -> Adult(?p)");

manager.saveOntology(ontology, IRI.create(((new File("FILE_PATH")).toURI())));

我使用了具有以下依赖项的 maven:

 <dependency>
     <groupId>edu.stanford.swrl</groupId>
     <artifactId>swrlapi-drools-engine</artifactId>
     <version>1.1.4</version>
  </dependency>

我收到以下错误:

线程 "main" 中出现异常 org.swrlapi.parser.SWRLParseException:SWRL 原子谓词无效 'Person' 在 org.swrlapi.parser.SWRLParser.generateEndOfRuleException(SWRLParser.java:479) 在 org.swrlapi.parser.SWRLParser.parseSWRLAtom(SWRLParser.java:210) 在 org.swrlapi.parser.SWRLParser.parseSWRLRule(SWRLParser.java:106) 在 org.swrlapi.factory.DefaultSWRLAPIOWLOntology.createSWRLRule(DefaultSWRLAPIOWLOntology.java:219) 在 org.swrlapi.factory.DefaultSWRLAPIOWLOntology.createSWRLRule(DefaultSWRLAPIOWLOntology.java:213) 在 org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.createSWRLRule(DefaultSWRLRuleAndQueryEngine.java:249) 在 ilc.cnr.it.swrl4morphology.SimpleToSWRL.main(SimpleToSWRL.java:450)

但是,如果我将 ontology 保存在文件中,然后重新加载它,我就不会再收到错误消息。似乎在第一次保存时添加了默认前缀。这对我来说听起来很奇怪....

拜托,你能帮我理解我做错了什么吗?

提前致谢, 安德里亚

在保存和解析时,相对 IRI(例如“Person”)将被转换为绝对 IRI,使用 ontology IRI 作为基础。