1+ import $ivy .`net.sourceforge.owlapi:owlapi-distribution:4.5.16`
2+ import $ivy .`com.outr::scribe-slf4j:2.7.12`
3+ import org .semanticweb .owlapi .apibinding .OWLManager
4+ import org .semanticweb .owlapi .model ._
5+ import org .semanticweb .owlapi .vocab .OWLFacet
6+ import java .io .File
7+ import scala .collection
8+ import scala .collection .mutable
9+ import scala .jdk .CollectionConverters ._
10+ @ main
11+ def main (id_range_file : os.Path ) = {
12+ val o = OWLManager .createOWLOntologyManager().loadOntology(IRI .create(id_range_file.toIO))
13+ val allMyFacets = mutable.ListBuffer .empty[MyFacet ]
14+ for (dt <- o.getDatatypesInSignature().asScala) {
15+ val defs = o.getAxioms(dt)
16+ for (ax <- defs.asScala) {
17+ val range = ax.getDataRange()
18+ val f = new MyFacet ()
19+ f.id = dt.toString()
20+ range.accept(new OWLDataRangeVisitor () {
21+ override
22+ def visit (owlDatatype : OWLDatatype ) = ()
23+ override
24+ def visit (owlDataOneOf : OWLDataOneOf ) = ()
25+ override
26+ def visit (owlDataComplementOf : OWLDataComplementOf ) = ()
27+ override
28+ def visit (owlDataIntersectionOf : OWLDataIntersectionOf ) = ()
29+ override
30+ def visit (owlDataUnionOf : OWLDataUnionOf ) = ()
31+ override
32+ def visit (owlDatatypeRestriction : OWLDatatypeRestriction ) = {
33+ for (fr <- owlDatatypeRestriction.getFacetRestrictions().asScala) {
34+ var i = fr.getFacetValue().parseInteger()
35+ if (fr.getFacet().equals(OWLFacet .MIN_INCLUSIVE )) {
36+ f.min = i
37+ } else if (fr.getFacet().equals(OWLFacet .MAX_INCLUSIVE )) {
38+ f.max = i
39+ } else if (fr.getFacet().equals(OWLFacet .MIN_EXCLUSIVE )) {
40+ i += 1
41+ f.min = i
42+ } else if (fr.getFacet().equals(OWLFacet .MAX_EXCLUSIVE )) {
43+ i -= 1
44+ f.max = i
45+ } else {
46+ log(" Unknown range restriction: " + fr)
47+ }
48+ }
49+ }
50+ })
51+ log(" Testing range: " + f)
52+ testFacetViolation(f,allMyFacets)
53+ allMyFacets.append(f)
54+ }
55+ }
56+ }
57+ def testFacetViolation (f : MyFacet , allMyFacets : collection.Seq [MyFacet ]) = {
58+ for (f_p <- allMyFacets) {
59+ if (((f.min <= f_p.max) && (f_p.min <= f.max))) {
60+ throw new IllegalStateException (f + " overlaps with " + f_p + " !" )
61+ }
62+ }
63+ }
64+ def log (o : Object ) = {
65+ println(o.toString())
66+ }
67+ class MyFacet {
68+ var min : Int = _
69+ var max : Int = _
70+ var id : String = _
71+ override
72+ def toString (): String = {
73+ return " Facet{" + id + " }[min:" + min + " max:" + max + " ]"
74+ }
75+ }
0 commit comments