我试图创建一个包含两个类的简单本体:class1和class2,以及两个具有相同名称的简单文本数据属性的实例(hasName:" string1" ^^ xsd:string和hasName" string2" ^^ xsd:string respectivly)。我想基于正则表达式将这些实例与推理器分类到相应的类(例如,类1的限制将是hasName some xsd:string [pattern" string1"],等等,推理器应该推断instance1属于class1,但instance2不属于class1。怎么办呢?
答案 0 :(得分:0)
使用Openllet(2.6.2-SNAPSHOT)可以执行以下操作:
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)));
如您所见:
OWL.restrict(XSD.STRING, OWL._factory.getOWLFacetRestriction(OWLFacet.PATTERN, OWL.constant("A.A"))))));
是添加" regexp"分类算法。
此处的模式是' A.A',模式遵循' java-regexp' enter link description here规则。