Skip to content

Commit 362980b

Browse files
committed
ontapi: [#55] support raw axioms(type, imports), logicalAxioms(imports), getAxiomsCount(imports), getAxiomsCount(type, imports), getLogicalAxiomsCount(imports)
1 parent 29e4d96 commit 362980b

File tree

2 files changed

+71
-23
lines changed

2 files changed

+71
-23
lines changed

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@ public <T extends OWLAxiom> Stream<T> axioms(AxiomType<T> axiomType) {
515515
return base.listOWLAxioms(axiomType);
516516
}
517517

518+
@Override
519+
public <T extends OWLAxiom> Stream<T> axioms(AxiomType<T> axiomType, Imports imports) {
520+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
521+
return getFullGraphModel().listOWLAxioms(axiomType);
522+
}
523+
return imports.stream(this).flatMap(o -> o.axioms(axiomType));
524+
}
525+
518526
/**
519527
* Gets the axioms that form the definition/description of a class.
520528
* The results include:
@@ -931,6 +939,14 @@ public Stream<OWLLogicalAxiom> logicalAxioms() {
931939
return base.listOWLLogicalAxioms();
932940
}
933941

942+
@Override
943+
public Stream<OWLLogicalAxiom> logicalAxioms(Imports imports) {
944+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
945+
return getFullGraphModel().listOWLLogicalAxioms();
946+
}
947+
return imports.stream(this).flatMap(OWLOntology::logicalAxioms);
948+
}
949+
934950
@Override
935951
public Stream<OWLClassAxiom> generalClassAxioms() {
936952
Stream<OWLSubClassOfAxiom> subClassOfAxioms = base.listOWLAxioms(OWLSubClassOfAxiom.class)
@@ -977,16 +993,40 @@ public int getAxiomCount() {
977993
return (int) base.getOWLAxiomCount();
978994
}
979995

996+
@Override
997+
public int getAxiomCount(Imports imports) {
998+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
999+
return (int) getFullGraphModel().getOWLAxiomCount();
1000+
}
1001+
return imports.stream(this).mapToInt(OWLAxiomCollection::getAxiomCount).sum();
1002+
}
1003+
9801004
@Override
9811005
public <T extends OWLAxiom> int getAxiomCount(AxiomType<T> axiomType) {
9821006
return (int) axioms(axiomType).count();
9831007
}
9841008

1009+
@Override
1010+
public <T extends OWLAxiom> int getAxiomCount(AxiomType<T> axiomType, Imports imports) {
1011+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
1012+
return (int) getFullGraphModel().listOWLAxioms(axiomType).count();
1013+
}
1014+
return imports.stream(this).mapToInt(o -> o.getAxiomCount(axiomType)).sum();
1015+
}
1016+
9851017
@Override
9861018
public int getLogicalAxiomCount() {
9871019
return (int) logicalAxioms().count();
9881020
}
9891021

1022+
@Override
1023+
public int getLogicalAxiomCount(Imports imports) {
1024+
if (imports == Imports.INCLUDED && !config.useContentCache()) {
1025+
return (int) getFullGraphModel().listOWLLogicalAxioms().count();
1026+
}
1027+
return imports.stream(this).mapToInt(OWLAxiomCollection::getLogicalAxiomCount).sum();
1028+
}
1029+
9901030
@Override
9911031
public boolean containsAxiom(OWLAxiom axiom) {
9921032
return base.contains(axiom);
@@ -1076,21 +1116,6 @@ public Stream<OWLAxiom> axiomsIgnoreAnnotations(OWLAxiom axiom, Imports imports)
10761116
return imports.stream(this).flatMap(o -> o.axiomsIgnoreAnnotations(axiom));
10771117
}
10781118

1079-
@Override
1080-
public int getAxiomCount(Imports imports) {
1081-
return imports.stream(this).mapToInt(OWLAxiomCollection::getAxiomCount).sum();
1082-
}
1083-
1084-
@Override
1085-
public <T extends OWLAxiom> int getAxiomCount(AxiomType<T> axiomType, Imports imports) {
1086-
return imports.stream(this).mapToInt(o -> o.getAxiomCount(axiomType)).sum();
1087-
}
1088-
1089-
@Override
1090-
public int getLogicalAxiomCount(Imports imports) {
1091-
return imports.stream(this).mapToInt(OWLAxiomCollection::getLogicalAxiomCount).sum();
1092-
}
1093-
10941119
/*
10951120
* ===============================================================================
10961121
* The overridden default methods from org.semanticweb.owlapi.model.OWLAxiomIndex:

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.jena.vocabulary.XSD;
1212
import org.junit.jupiter.api.Assertions;
1313
import org.junit.jupiter.api.Test;
14+
import org.semanticweb.owlapi.model.AxiomType;
1415
import org.semanticweb.owlapi.model.IRI;
1516
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
1617
import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom;
@@ -20,6 +21,8 @@
2021
import org.semanticweb.owlapi.model.OWLDatatype;
2122
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
2223
import org.semanticweb.owlapi.model.OWLEntity;
24+
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
25+
import org.semanticweb.owlapi.model.OWLLogicalAxiom;
2326
import org.semanticweb.owlapi.model.OWLNamedIndividual;
2427
import org.semanticweb.owlapi.model.OWLObjectProperty;
2528
import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
@@ -31,16 +34,18 @@
3134
public class InfOntModelTest {
3235

3336
@Test
34-
void testListAllAxioms() {
37+
void testListAllAxiomsAndGetCounts() {
3538
OntologyManager om = OntManagers.createDirectManager();
3639
om.getOntologyConfigurator().setSpecification(OntSpecification.OWL2_FULL_MEM_RDFS_INF);
3740

3841
OntModel m1 = om.createGraphModel("http://a#A");
3942
OntModel m2 = om.createGraphModel("http://b#B");
4043
m1.addImport(m2);
4144

42-
m2.createOntClass("http://b#C1");
43-
m2.createOntClass("http://b#C2");
45+
m2.createOntClass("http://b#C1")
46+
.addEquivalentClass(
47+
m2.createOntClass("http://b#C2")
48+
);
4449
m1.createOntClass("http://a#C1");
4550

4651
Ontology o1 = Objects.requireNonNull(om.getOntology(IRI.create("http://a#A")));
@@ -49,16 +54,34 @@ void testListAllAxioms() {
4954
// Declaration(Class(<http://b#C2>))
5055
// Declaration(Class(<http://b#C1>))
5156
// Declaration(Datatype(rdf:XMLLiteral))
57+
// EquivalentClasses(<http://b#C1> <http://b#C2>)
5258
// SubAnnotationPropertyOf(rdfs:isDefinedBy rdfs:isDefinedBy)
5359
// SubAnnotationPropertyOf(rdfs:isDefinedBy rdfs:seeAlso)
5460
// SubAnnotationPropertyOf(rdfs:seeAlso rdfs:seeAlso)
5561
// AnnotationPropertyRange(rdfs:label <http://www.w3.org/2000/01/rdf-schema#Literal>)
5662
// AnnotationPropertyRange(rdfs:comment <http://www.w3.org/2000/01/rdf-schema#Literal>)
57-
List<OWLAxiom> actual = o1.axioms(Imports.INCLUDED).toList();
58-
Assertions.assertEquals(9, actual.size());
59-
Assertions.assertEquals(4, actual.stream().filter(it -> it instanceof OWLDeclarationAxiom).count());
60-
Assertions.assertEquals(3, actual.stream().filter(it -> it instanceof OWLSubAnnotationPropertyOfAxiom).count());
61-
Assertions.assertEquals(2, actual.stream().filter(it -> it instanceof OWLAnnotationPropertyRangeAxiom).count());
63+
List<OWLAxiom> actual1 = o1.axioms(Imports.INCLUDED).toList();
64+
Assertions.assertEquals(10, actual1.size());
65+
Assertions.assertEquals(4, actual1.stream().filter(it -> it instanceof OWLDeclarationAxiom).count());
66+
Assertions.assertEquals(3, actual1.stream().filter(it -> it instanceof OWLSubAnnotationPropertyOfAxiom).count());
67+
Assertions.assertEquals(2, actual1.stream().filter(it -> it instanceof OWLAnnotationPropertyRangeAxiom).count());
68+
Assertions.assertEquals(1, actual1.stream().filter(it -> it instanceof OWLEquivalentClassesAxiom).count());
69+
70+
Assertions.assertEquals(4, o1.axioms(AxiomType.DECLARATION, Imports.INCLUDED).count());
71+
Assertions.assertEquals(3, o1.axioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF, Imports.INCLUDED).count());
72+
Assertions.assertEquals(2, o1.axioms(AxiomType.ANNOTATION_PROPERTY_RANGE, Imports.INCLUDED).count());
73+
Assertions.assertEquals(1, o1.axioms(AxiomType.EQUIVALENT_CLASSES, Imports.INCLUDED).count());
74+
75+
List<OWLLogicalAxiom> actual2 = o1.logicalAxioms(Imports.INCLUDED).toList();
76+
Assertions.assertEquals(1, actual2.size());
77+
78+
Assertions.assertEquals(10, o1.getAxiomCount(Imports.INCLUDED));
79+
Assertions.assertEquals(1, o1.getLogicalAxiomCount(Imports.INCLUDED));
80+
81+
Assertions.assertEquals(4, o1.getAxiomCount(AxiomType.DECLARATION, Imports.INCLUDED));
82+
Assertions.assertEquals(3, o1.getAxiomCount(AxiomType.SUB_ANNOTATION_PROPERTY_OF, Imports.INCLUDED));
83+
Assertions.assertEquals(2, o1.getAxiomCount(AxiomType.ANNOTATION_PROPERTY_RANGE, Imports.INCLUDED));
84+
Assertions.assertEquals(1, o1.getAxiomCount(AxiomType.EQUIVALENT_CLASSES, Imports.INCLUDED));
6285
}
6386

6487
@Test

0 commit comments

Comments
 (0)