java - How to verify if an OWLDataRange object contains a specified value? -
i have ontology created in protege 4.3.0 , stored in owl file. data properties of ontology have ranges defined in following expression:
({"absent"} or {"value1" , "value2" , "value3"})
i search data properties have specified value in ranges, wrote following code sample, not know how query owldatarange
object see if contains specified value (for example string "value1"
).
final owlontologymanager manager = owlmanager.createowlontologymanager(); final owlontology ontology = manager.loadontologyfromontologydocument(file); final owlreasonerfactory rf = new structuralreasonerfactory(); final owlreasoner reasoner = rf.createreasoner(ontology); // ... // iterate on data properties (owldataproperty topdataproperty : reasoner.gettopdatapropertynode()) { for(owldataproperty property: reasoner.getsubdataproperties(topdataproperty, false).getflattened()) { // iterate on data ranges current data property (owldatarange datarange : property.getranges(ontology)) { // check if current data property contains specified value in ranges. // ... } } }
my solution kind of problem use reasoner (this pellet fork ).
the idea create class denote 'individuals have data-property range check' , class denote 'individuals have exaclty property/literal'. using reasoner check if intersection of thoses 2 class non-empty.
as there tricks work correctly here complete solution :
import java.util.function.bifunction; import org.semanticweb.owlapi.model.*; import openllet.owlapi.*; public class rangeinclusiontest { public static void main(final string[] args) { try (final owlmanagergroup group = new owlmanagergroup()) { final owlontologyid ontid = owlhelper.getversion(iri.create("http://test.org#entail-class-restrict-to-some-range"), 1.0); final owlhelper owl = new owlgenerictools(group, ontid, true); // declaration vital since reasoner have problems pure anonymous reasoning. // can remove property after yours tests, (or better use 1 of existing properties). final owldataproperty prop = owl.dataproperty("http://test.org#dummyprop"); owl.addaxiom(owl.declaration(prop)); final owlliteral un = owl.constant(1); final owlliteral deux = owl.constant(2); final owlliteral trois = owl.constant(3); final owlliteral quatre = owl.constant(4); final owldatarange datarange = owl.dataor(owl.oneof(un), owl.oneof(deux), owl.oneof(trois)); final bifunction<owldatarange, owlliteral, boolean> isincludeinrange = // (range, literal) -> owl.getreasoner().issatisfiable(// owl.and(// must of following class owl.some(prop, owl.oneof(literal)), // class of 'literal' owl.some(prop, range), // class of range. owl.max(prop, 1))// can have property once. ); system.out.println("[a] " + (isincludeinrange.apply(datarange, un))); system.out.println("[b] " + (isincludeinrange.apply(datarange, deux))); system.out.println("[c] " + (isincludeinrange.apply(datarange, trois))); system.out.println("[d] " + (isincludeinrange.apply(datarange, quatre))); } catch (final exception e) { e.printstacktrace(); } } }
first must define yours ranges. use 'issatisfiable' method of reasoner. 1 trick enforce usage of 1 instance of property adding restriction "owl.max(prop, 1)" on intersection class.
the output must be
[a] true [b] true [c] true [d] false
because literal 'quatre' isn't include 'datarange' answer '[d]' false. can see solution easilly allow tests inclusions of range in one.
a solution not requiere change on ontology have been create special swrl rule , check if ontology (even empty) entail rule, no dl-reasoner support entailment on swrl.
Comments
Post a Comment