我已经运行(在 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>
我收到以下错误:
线程“主”中的异常 org.swrlapi.parser.SWRLParseException:在 org.swrlapi.parser.SWRLParser.generateEndOfRuleException(SWRLParser.java:479) 在 org.swrlapi.parser.SWRLParser.parseSWRLAtom(SWRLParser) 的 SWRL 原子谓词“Person”无效.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) at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.createSWRLRule(DefaultSWRLRuleAndQueryEngine.java:249) at ilc.cnr.it.swrl4morphology.SimpleToSWRL.main(SimpleToSWRL.java:450)
但是,如果我将本体保存在文件中,然后重新加载它,我就不会再收到错误了。似乎在第一次保存期间添加了默认前缀。这对我来说听起来很奇怪......
拜托,你能帮我理解我做错了什么吗?
在此先感谢,安德里亚