Skip to content

Commit f7317a5

Browse files
committed
ontapi: [#55] add axiomsIgnoreAnnotations(OWLAxiom, imports) & referencingAxioms(OWLPrimitive, imports) impls
1 parent 75a4bb8 commit f7317a5

File tree

2 files changed

+111
-14
lines changed

2 files changed

+111
-14
lines changed

src/main/java/com/github/owlcs/ontapi/BaseOntologyModelImpl.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,25 @@ public Stream<OWLAxiom> axiomsIgnoreAnnotations(OWLAxiom axiom) {
11801180
return axioms(axiom.getAxiomType()).map(OWLAxiom.class::cast).filter(ax -> ax.equalsIgnoreAnnotations(axiom));
11811181
}
11821182

1183+
@Override
1184+
public Stream<OWLAxiom> axiomsIgnoreAnnotations(OWLAxiom axiom, Imports imports) {
1185+
return axioms(axiom.getAxiomType(), imports)
1186+
.map(OWLAxiom.class::cast).filter(ax -> ax.equalsIgnoreAnnotations(axiom));
1187+
}
1188+
11831189
@Override
11841190
public Stream<OWLAxiom> referencingAxioms(OWLPrimitive primitive) {
11851191
return base.listOWLAxioms(primitive);
11861192
}
11871193

1194+
@Override
1195+
public Stream<OWLAxiom> referencingAxioms(OWLPrimitive primitive, Imports imports) {
1196+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
1197+
return getFullGraphModel().listOWLAxioms(primitive);
1198+
}
1199+
return imports.stream(this).flatMap(o -> o.referencingAxioms(primitive));
1200+
}
1201+
11881202
@Override
11891203
public Stream<OWLSubAnnotationPropertyOfAxiom> subAnnotationPropertyOfAxioms(OWLAnnotationProperty property) {
11901204
return base.listOWLSubAnnotationPropertyOfAxiomsBySubject(property);
@@ -1269,20 +1283,6 @@ public boolean contains(OWLAxiomSearchFilter filter, Object key, Imports imports
12691283
return imports.stream(this).anyMatch(o -> o.contains(filter, key));
12701284
}
12711285

1272-
@Override
1273-
public Stream<OWLAxiom> axiomsIgnoreAnnotations(OWLAxiom axiom, Imports imports) {
1274-
if (Imports.EXCLUDED == imports) {
1275-
return axiomsIgnoreAnnotations(axiom);
1276-
}
1277-
return imports.stream(this).flatMap(o -> o.axiomsIgnoreAnnotations(axiom));
1278-
}
1279-
1280-
/*
1281-
* ===============================================================================
1282-
* The overridden default methods from org.semanticweb.owlapi.model.OWLAxiomIndex:
1283-
* ===============================================================================
1284-
*/
1285-
12861286
@Override
12871287
public Stream<OWLDeclarationAxiom> declarationAxioms(OWLEntity subject) {
12881288
return base.listOWLDeclarationAxioms(subject);

src/test/java/com/github/owlcs/ontapi/tests/model/InfOntModelTest.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,103 @@ void testListAxiomsByObjectAndPosition() {
251251
);
252252
}
253253

254+
@Test
255+
void listBoxAxioms() {
256+
OntologyManager om = OntManagers.createDirectManager();
257+
om.getOntologyConfigurator().setSpecification(OntSpecification.OWL2_FULL_MEM_RDFS_INF);
258+
259+
OntModel m1 = om.createGraphModel("http://a#A");
260+
OntModel m2 = om.createGraphModel("http://b#B");
261+
m1.addImport(m2);
262+
263+
m2.createOntClass("http://b#C1")
264+
.addEquivalentClass(
265+
m2.createOntClass("http://b#C2")
266+
);
267+
m1.createOntClass("http://a#C1");
268+
269+
m2.createIndividual("http://b#i1");
270+
m1.createOntClass("http://a#C1");
271+
m1.createObjectProperty("http://a#p2");
272+
m1.createAnnotationProperty("http://a#p3").addSubProperty(
273+
m1.createAnnotationProperty("http://a#p4")
274+
);
275+
m1.createDataProperty("http://a#p3").addSubProperty(
276+
m2.createDataProperty("http://b#p1")
277+
);
278+
OntIndividual i1 = m1.createIndividual("http://b#i1", m2.getOntClass("http://b#C2"));
279+
OntIndividual i2 = m2.createIndividual(null, m2.getOntClass("http://b#C1"));
280+
i1.addSameAsStatement(i2);
281+
OntDataRange d1 = m2.createDataOneOf(m2.createTypedLiteral(1), m2.createTypedLiteral(2));
282+
m1.createDatatype("1&2").addEquivalentClass(d1);
283+
284+
Ontology o1 = Objects.requireNonNull(om.getOntology(IRI.create("http://a#A")));
285+
286+
// EquivalentClasses(<http://b#C1> <http://b#C2>)
287+
// DatatypeDefinition(<1&2> DataOneOf("1"^^xsd:int "2"^^xsd:int))
288+
Assertions.assertEquals(2, o1.tboxAxioms(Imports.INCLUDED).count());
289+
// SameIndividual(<http://b#i1> _:8f7080cb-5bb6-4097-bb2d-d678fed3cd7b)
290+
// ClassAssertion(<http://b#C2> <http://b#i1>)
291+
// ClassAssertion(<http://b#C1> _:8f7080cb-5bb6-4097-bb2d-d678fed3cd7b)
292+
Assertions.assertEquals(3, o1.aboxAxioms(Imports.INCLUDED).count());
293+
// SubDataPropertyOf(<http://b#p1> <http://a#p3>)
294+
// SubDataPropertyOf(<http://a#p3> <http://a#p3>)
295+
// SubDataPropertyOf(<http://b#p1> <http://b#p1>)
296+
Assertions.assertEquals(3, o1.rboxAxioms(Imports.INCLUDED).count());
297+
}
298+
299+
@Test
300+
void listAxiomsIgnoreAnnotations() {
301+
OntologyManager om = OntManagers.createDirectManager();
302+
DataFactory df = om.getOWLDataFactory();
303+
om.getOntologyConfigurator().setSpecification(OntSpecification.OWL2_FULL_MEM_RDFS_INF);
304+
305+
OntModel m1 = om.createGraphModel("http://a#A");
306+
OntModel m2 = om.createGraphModel("http://b#B");
307+
m1.addImport(m2);
308+
309+
m2.createOntClass("http://b#C1")
310+
.addEquivalentClassStatement(
311+
m2.createOntClass("http://b#C2")
312+
).addAnnotation(m2.getRDFSComment(), "xxx");
313+
m1.createOntClass("http://a#C1").addAnnotation(m2.getRDFSLabel(), "qqq");
314+
315+
Ontology o1 = Objects.requireNonNull(om.getOntology(IRI.create("http://a#A")));
316+
317+
// EquivalentClasses(Annotation(rdfs:comment "xxx"^^xsd:string) <http://b#C1> <http://b#C2>)
318+
Assertions.assertEquals(1,
319+
o1.axiomsIgnoreAnnotations(
320+
df.getOWLEquivalentClassesAxiom(df.getOWLClass("http://b#C1"), df.getOWLClass("http://b#C2")),
321+
Imports.INCLUDED
322+
).count());
323+
}
324+
325+
@Test
326+
void listReferencingAxioms() {
327+
OntologyManager om = OntManagers.createDirectManager();
328+
DataFactory df = om.getOWLDataFactory();
329+
om.getOntologyConfigurator().setSpecification(OntSpecification.OWL2_FULL_MEM_RDFS_INF);
330+
331+
OntModel m1 = om.createGraphModel("http://a#A");
332+
OntModel m2 = om.createGraphModel("http://b#B");
333+
m1.addImport(m2);
334+
335+
m1.createOntClass("http://a#C1").addSuperClass(
336+
m2.createOntClass("http://b#C1")
337+
.addEquivalentClass(
338+
m2.createOntClass("http://b#C2")
339+
)
340+
);
341+
342+
Ontology o1 = Objects.requireNonNull(om.getOntology(IRI.create("http://a#A")));
343+
344+
// SubClassOf(<http://a#C1> <http://b#C1>)
345+
// Declaration(Class(<http://a#C1>))
346+
// SubClassOf(<http://a#C1> <http://a#C1>)
347+
// SubClassOf(<http://a#C1> <http://a#C1>)
348+
Assertions.assertEquals(4, o1.referencingAxioms(df.getOWLClass("http://a#C1"), Imports.INCLUDED).count());
349+
}
350+
254351
@Test
255352
void testListSignature1() {
256353
OntologyManager om = OntManagers.createDirectManager();

0 commit comments

Comments
 (0)