Creating regex restriction on OWL class

386 Views Asked by At

I'm trying to create a simple ontology that has two classes: class1 and class2,- and two instances that have simple text data property with the same name (hasName: "string1"^^xsd:string and hasName "string2"^^xsd:string respectivly). I want to classify these instances with reasoner to the respective classes based on regular expression (for example, the restriction for class 1 would be hasName some xsd:string[pattern "string1"], and such, the reasoner should infer that instance1 belongs to class1, but instance2 is not). How can it be done?

1

There are 1 best solutions below

0
On

Using Openllet(2.6.2-SNAPSHOT) you can do things like that :

    final OWLNamedIndividual x1 = OWL.Individual("#I1");
    final OWLNamedIndividual x2 = OWL.Individual("#I2");

    owl.addAxiom(OWL.equivalentClasses(ClsA, OWL.some(propB, OWL.restrict(XSD.STRING, OWL._factory.getOWLFacetRestriction(OWLFacet.PATTERN, OWL.constant("A.A"))))));
    owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant("AAA")));
    owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant("BBB")));

    owl.addAxiom(OWL.differentFrom(x1, x2));

    final OpenlletReasoner r = owl.getReasoner();
    assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA)));
    assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA)));

As you can see the line :

OWL.restrict(XSD.STRING, OWL._factory.getOWLFacetRestriction(OWLFacet.PATTERN, OWL.constant("A.A"))))));

is the one that add the "regexp" to the classification algorithm.

Here the pattern is 'A.A', pattern follow 'java-regexp'enter link description here rules.