protegeproject / swrlapi

Java API for working with the SWRL rule and SQWRL query languages
Other
99 stars 40 forks source link

org.swrlapi.parser.SWRLParseException: Invalid SWRL atom predicate 'Person' #37

Closed ChristophB closed 7 years ago

ChristophB commented 7 years ago

Hello,

i get an org.swrlapi.parser.SWRLParseException when i try to create an SWRLRule.

Minimal example:

private static final String ONT_IRI = "http://example.org/example#";

// ...

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(IRI.create(ONT_IRI));

manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(factory.getOWLDataProperty(IRI.create(ONT_IRI, "hasAge"))));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(factory.getOWLClass(IRI.create(ONT_IRI, "Person"))));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(factory.getOWLClass(IRI.create(ONT_IRI, "Adult"))));

SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
SWRLAPIRule rule = ruleEngine.createSWRLRule(
    "IsAdult-Rule",
    "Person(?p) ^ hasAge(?p, ?age) ^ swrlb:greaterThan(?age, 17) -> Adult(?p)"
); // Exception is thrown here

It seams that the SWRLRuleEngine does not recognize the Person class.

Dependencies:

Do you have any hints to resolve this issue?

Thanks, Christoph

martinjoconnor commented 7 years ago

If you will need to set a default namespace for the ontology (in this case http://example.org/example#) in order to use the unqualified name.

ChristophB commented 7 years ago

Thanks, manager.getOntologyFormat(ontology).asPrefixOWLOntologyFormat().setDefaultPrefix(ONT_IRI); solved the problem.