Skip to content

Commit d181b5a

Browse files
committed
ont-api: add OWLDataPropertyDomainAxiom model-impl (issue #2) + add/change tests
1 parent 699b179 commit d181b5a

14 files changed

+540
-280
lines changed

src/main/java/com/github/owlcs/ontapi/internal/OWLContentType.java

+57-44
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
package com.github.owlcs.ontapi.internal;
1616

17-
import org.apache.jena.util.iterator.ExtendedIterator;
18-
import org.semanticweb.owlapi.model.*;
1917
import com.github.owlcs.ontapi.OntApiException;
2018
import com.github.owlcs.ontapi.jena.model.OntGraphModel;
2119
import com.github.owlcs.ontapi.jena.utils.Iter;
20+
import org.apache.jena.util.iterator.ExtendedIterator;
21+
import org.semanticweb.owlapi.model.*;
2222

2323
import java.util.*;
2424
import java.util.function.Supplier;
@@ -62,48 +62,48 @@ void write(OntGraphModel m, OWLObject v) {
6262
},
6363
// axioms:
6464
DECLARATION(AxiomType.DECLARATION, true, ENTITY),
65-
EQUIVALENT_CLASSES(AxiomType.EQUIVALENT_CLASSES, false, CLASS_EXPRESSION),
66-
SUBCLASS_OF(AxiomType.SUBCLASS_OF, false, CLASS_EXPRESSION),
67-
DISJOINT_CLASSES(AxiomType.DISJOINT_CLASSES, false, CLASS_EXPRESSION),
68-
DISJOINT_UNION(AxiomType.DISJOINT_UNION, false, CLASS, CLASS_EXPRESSION),
69-
CLASS_ASSERTION(AxiomType.CLASS_ASSERTION, true, INDIVIDUAL, CLASS_EXPRESSION),
70-
SAME_INDIVIDUAL(AxiomType.SAME_INDIVIDUAL, false, INDIVIDUAL),
71-
DIFFERENT_INDIVIDUALS(AxiomType.DIFFERENT_INDIVIDUALS, false, INDIVIDUAL),
65+
EQUIVALENT_CLASSES(AxiomType.EQUIVALENT_CLASSES, CLASS_EXPRESSION),
66+
SUBCLASS_OF(AxiomType.SUBCLASS_OF, CLASS_EXPRESSION),
67+
DISJOINT_CLASSES(AxiomType.DISJOINT_CLASSES, CLASS_EXPRESSION),
68+
DISJOINT_UNION(AxiomType.DISJOINT_UNION, CLASS, CLASS_EXPRESSION),
69+
CLASS_ASSERTION(AxiomType.CLASS_ASSERTION, INDIVIDUAL, CLASS_EXPRESSION),
70+
SAME_INDIVIDUAL(AxiomType.SAME_INDIVIDUAL, INDIVIDUAL),
71+
DIFFERENT_INDIVIDUALS(AxiomType.DIFFERENT_INDIVIDUALS, INDIVIDUAL),
7272
OBJECT_PROPERTY_ASSERTION(AxiomType.OBJECT_PROPERTY_ASSERTION, true, NAMED_OBJECT_PROPERTY, INDIVIDUAL),
73-
NEGATIVE_OBJECT_PROPERTY_ASSERTION(AxiomType.NEGATIVE_OBJECT_PROPERTY_ASSERTION, false, OBJECT_PROPERTY_EXPRESSION, INDIVIDUAL),
73+
NEGATIVE_OBJECT_PROPERTY_ASSERTION(AxiomType.NEGATIVE_OBJECT_PROPERTY_ASSERTION, OBJECT_PROPERTY_EXPRESSION, INDIVIDUAL),
7474
DATA_PROPERTY_ASSERTION(AxiomType.DATA_PROPERTY_ASSERTION, true, DATATYPE_PROPERTY, LITERAL, INDIVIDUAL),
75-
NEGATIVE_DATA_PROPERTY_ASSERTION(AxiomType.NEGATIVE_DATA_PROPERTY_ASSERTION, false, DATATYPE_PROPERTY, INDIVIDUAL, LITERAL),
76-
EQUIVALENT_OBJECT_PROPERTIES(AxiomType.EQUIVALENT_OBJECT_PROPERTIES, false, OBJECT_PROPERTY_EXPRESSION),
77-
SUB_OBJECT_PROPERTY(AxiomType.SUB_OBJECT_PROPERTY, false, OBJECT_PROPERTY_EXPRESSION),
78-
INVERSE_OBJECT_PROPERTIES(AxiomType.INVERSE_OBJECT_PROPERTIES, false, OBJECT_PROPERTY_EXPRESSION),
79-
FUNCTIONAL_OBJECT_PROPERTY(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
80-
INVERSE_FUNCTIONAL_OBJECT_PROPERTY(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
81-
SYMMETRIC_OBJECT_PROPERTY(AxiomType.SYMMETRIC_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
82-
ASYMMETRIC_OBJECT_PROPERTY(AxiomType.ASYMMETRIC_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
83-
TRANSITIVE_OBJECT_PROPERTY(AxiomType.TRANSITIVE_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
84-
REFLEXIVE_OBJECT_PROPERTY(AxiomType.REFLEXIVE_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
85-
IRREFLEXIVE_OBJECT_PROPERTY(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, true, OBJECT_PROPERTY_EXPRESSION),
86-
OBJECT_PROPERTY_DOMAIN(AxiomType.OBJECT_PROPERTY_DOMAIN, true, OBJECT_PROPERTY_EXPRESSION, CLASS_EXPRESSION),
87-
OBJECT_PROPERTY_RANGE(AxiomType.OBJECT_PROPERTY_RANGE, true, OBJECT_PROPERTY_EXPRESSION, CLASS_EXPRESSION),
88-
DISJOINT_OBJECT_PROPERTIES(AxiomType.DISJOINT_OBJECT_PROPERTIES, false, OBJECT_PROPERTY_EXPRESSION),
89-
SUB_PROPERTY_CHAIN_OF(AxiomType.SUB_PROPERTY_CHAIN_OF, false, OBJECT_PROPERTY_EXPRESSION),
90-
EQUIVALENT_DATA_PROPERTIES(AxiomType.EQUIVALENT_DATA_PROPERTIES, false, DATATYPE_PROPERTY),
75+
NEGATIVE_DATA_PROPERTY_ASSERTION(AxiomType.NEGATIVE_DATA_PROPERTY_ASSERTION, DATATYPE_PROPERTY, INDIVIDUAL, LITERAL),
76+
EQUIVALENT_OBJECT_PROPERTIES(AxiomType.EQUIVALENT_OBJECT_PROPERTIES, OBJECT_PROPERTY_EXPRESSION),
77+
SUB_OBJECT_PROPERTY(AxiomType.SUB_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
78+
INVERSE_OBJECT_PROPERTIES(AxiomType.INVERSE_OBJECT_PROPERTIES, OBJECT_PROPERTY_EXPRESSION),
79+
FUNCTIONAL_OBJECT_PROPERTY(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
80+
INVERSE_FUNCTIONAL_OBJECT_PROPERTY(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
81+
SYMMETRIC_OBJECT_PROPERTY(AxiomType.SYMMETRIC_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
82+
ASYMMETRIC_OBJECT_PROPERTY(AxiomType.ASYMMETRIC_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
83+
TRANSITIVE_OBJECT_PROPERTY(AxiomType.TRANSITIVE_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
84+
REFLEXIVE_OBJECT_PROPERTY(AxiomType.REFLEXIVE_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
85+
IRREFLEXIVE_OBJECT_PROPERTY(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
86+
OBJECT_PROPERTY_DOMAIN(AxiomType.OBJECT_PROPERTY_DOMAIN, OBJECT_PROPERTY_EXPRESSION, CLASS_EXPRESSION),
87+
OBJECT_PROPERTY_RANGE(AxiomType.OBJECT_PROPERTY_RANGE, OBJECT_PROPERTY_EXPRESSION, CLASS_EXPRESSION),
88+
DISJOINT_OBJECT_PROPERTIES(AxiomType.DISJOINT_OBJECT_PROPERTIES, OBJECT_PROPERTY_EXPRESSION),
89+
SUB_PROPERTY_CHAIN_OF(AxiomType.SUB_PROPERTY_CHAIN_OF, OBJECT_PROPERTY_EXPRESSION),
90+
EQUIVALENT_DATA_PROPERTIES(AxiomType.EQUIVALENT_DATA_PROPERTIES, DATATYPE_PROPERTY),
9191
SUB_DATA_PROPERTY(AxiomType.SUB_DATA_PROPERTY, true, DATATYPE_PROPERTY),
9292
FUNCTIONAL_DATA_PROPERTY(AxiomType.FUNCTIONAL_DATA_PROPERTY, true, DATATYPE_PROPERTY),
93-
DATA_PROPERTY_DOMAIN(AxiomType.DATA_PROPERTY_DOMAIN, true, DATATYPE_PROPERTY, CLASS_EXPRESSION),
94-
DATA_PROPERTY_RANGE(AxiomType.DATA_PROPERTY_RANGE, true, DATATYPE_PROPERTY, DATA_RANGE),
95-
DISJOINT_DATA_PROPERTIES(AxiomType.DISJOINT_DATA_PROPERTIES, false, DATATYPE_PROPERTY),
96-
HAS_KEY(AxiomType.HAS_KEY, false, CLASS_EXPRESSION, DATATYPE_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
97-
SWRL_RULE(AxiomType.SWRL_RULE, false, SWRL_ATOM),
93+
DATA_PROPERTY_DOMAIN(AxiomType.DATA_PROPERTY_DOMAIN, DATATYPE_PROPERTY, CLASS_EXPRESSION),
94+
DATA_PROPERTY_RANGE(AxiomType.DATA_PROPERTY_RANGE, DATATYPE_PROPERTY, DATA_RANGE),
95+
DISJOINT_DATA_PROPERTIES(AxiomType.DISJOINT_DATA_PROPERTIES, DATATYPE_PROPERTY),
96+
HAS_KEY(AxiomType.HAS_KEY, CLASS_EXPRESSION, DATATYPE_PROPERTY, OBJECT_PROPERTY_EXPRESSION),
97+
SWRL_RULE(AxiomType.SWRL_RULE, SWRL_ATOM),
9898
ANNOTATION_ASSERTION(AxiomType.ANNOTATION_ASSERTION, true, ANNOTATION_PROPERTY, LITERAL, ANONYMOUS_INDIVIDUAL, IRI),
9999
SUB_ANNOTATION_PROPERTY_OF(AxiomType.SUB_ANNOTATION_PROPERTY_OF, true, ANNOTATION_PROPERTY),
100100
ANNOTATION_PROPERTY_RANGE(AxiomType.ANNOTATION_PROPERTY_RANGE, true, ANNOTATION_PROPERTY, IRI),
101101
ANNOTATION_PROPERTY_DOMAIN(AxiomType.ANNOTATION_PROPERTY_DOMAIN, true, ANNOTATION_PROPERTY, IRI),
102-
DATATYPE_DEFINITION(AxiomType.DATATYPE_DEFINITION, true, DATATYPE, DATA_RANGE),
102+
DATATYPE_DEFINITION(AxiomType.DATATYPE_DEFINITION, DATATYPE, DATA_RANGE),
103103
;
104104

105-
private static final Set<OWLContentType> AXIOMS;
106-
private static final Set<OWLContentType> LOGICAL;
105+
private static final Set<OWLContentType> ALL_AXIOMS;
106+
private static final Set<OWLContentType> LOGICAL_AXIOMS;
107107

108108
static {
109109
Set<OWLContentType> axioms = EnumSet.noneOf(OWLContentType.class);
@@ -116,14 +116,23 @@ void write(OntGraphModel m, OWLObject v) {
116116
logical.add(x);
117117
}
118118
}
119-
AXIOMS = axioms;
120-
LOGICAL = logical;
119+
ALL_AXIOMS = axioms;
120+
LOGICAL_AXIOMS = logical;
121121
}
122122

123123
private final AxiomType<OWLAxiom> type;
124124
private final boolean distinct;
125125
private final Set<OWLComponentType> components;
126126

127+
OWLContentType(AxiomType<? extends OWLAxiom> type, OWLComponentType... types) {
128+
this(type, false, types);
129+
}
130+
131+
/**
132+
* @param type {@link AxiomType} or {@code null} if ontology header
133+
* @param distinct see {@link #isDistinct()}
134+
* @param types an {@code Array} of top-level components
135+
*/
127136
@SuppressWarnings("unchecked")
128137
OWLContentType(AxiomType<? extends OWLAxiom> type, boolean distinct, OWLComponentType... types) {
129138
this.type = (AxiomType<OWLAxiom>) type;
@@ -181,7 +190,7 @@ static ExtendedIterator<OWLContentType> listAll() {
181190
* @return {@code Stream} of {@link OWLContentType}s
182191
*/
183192
public static Stream<OWLContentType> axioms() {
184-
return AXIOMS.stream();
193+
return ALL_AXIOMS.stream();
185194
}
186195

187196
/**
@@ -190,7 +199,7 @@ public static Stream<OWLContentType> axioms() {
190199
* @return {@code Stream} of {@link OWLContentType}s
191200
*/
192201
public static Stream<OWLContentType> logical() {
193-
return LOGICAL.stream();
202+
return LOGICAL_AXIOMS.stream();
194203
}
195204

196205
/**
@@ -231,12 +240,13 @@ boolean hasAnnotations(OWLObject container) {
231240
}
232241

233242
/**
234-
* Answers {@code true} if and only if
235-
* there can be only one unique content object of this enum-type,
236-
* which means that there is only one statement in the graph, to which that object corresponds.
237-
* Returns {@code false}, if an object of the enum-type can be derived from different RDF statements.
238-
* <p>
239-
* Several examples when the method returns {@code false}:
243+
* Answers {@code true} iff
244+
* an object of this type can be derived from one and only one main triple,
245+
* and returns {@code false}, if several main triples can correspond to the same object.
246+
* Usually the method returns {@code false}, only few types allow mapping to be distinct.
247+
* An example of distinct type is {@link #DECLARATION}:
248+
* any triple {@code x rdf:type y} uniquely corresponds to the entity {@code x} of the type {@code y}.
249+
* Below are examples of non-distinct types:
240250
* <ul>
241251
* <li>{@link #DIFFERENT_INDIVIDUALS}: the same axiom {@code DifferentIndividuals(<A> <B>)} can be derived
242252
* form three statements: {@code a1 owl:differentFrom a2}, {@code a2 owl:differentFrom a1}
@@ -246,6 +256,9 @@ boolean hasAnnotations(OWLObject container) {
246256
* {@code C1 owl:disjointUnionOf ( C2 ) . C1 owl:disjointUnionOf ( C2 ) . }</li>
247257
* <li>{@link #ANNOTATION}: bulk annotation is a b-node, RDF graph can contain any number of b-nodes
248258
* with the same content (annotation property and annotation value)</li>
259+
* <li>{@link #FUNCTIONAL_OBJECT_PROPERTY}:
260+
* the axiom {@code FunctionalObjectProperty(ObjectInverseOf(P))} can be derived from
261+
* the any statements of the form {@code _:bi rdf:type owl:FunctionalProperty . _:bi owl:inverseOf P .}</li>
249262
* </ul>
250263
*
251264
* @return boolean

src/main/java/com/github/owlcs/ontapi/internal/axioms/AbstractPropertyDomainTranslator.java

+75-10
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@
1414

1515
package com.github.owlcs.ontapi.internal.axioms;
1616

17-
import org.apache.jena.util.iterator.ExtendedIterator;
18-
import org.apache.jena.vocabulary.RDFS;
19-
import org.semanticweb.owlapi.model.HasDomain;
20-
import org.semanticweb.owlapi.model.HasProperty;
21-
import org.semanticweb.owlapi.model.OWLAxiom;
22-
import com.github.owlcs.ontapi.internal.AxiomTranslator;
23-
import com.github.owlcs.ontapi.internal.InternalConfig;
24-
import com.github.owlcs.ontapi.internal.WriteHelper;
17+
import com.github.owlcs.ontapi.internal.*;
18+
import com.github.owlcs.ontapi.internal.objects.ONTAxiomImpl;
19+
import com.github.owlcs.ontapi.internal.objects.ONTClassImpl;
20+
import com.github.owlcs.ontapi.jena.model.OntCE;
2521
import com.github.owlcs.ontapi.jena.model.OntGraphModel;
2622
import com.github.owlcs.ontapi.jena.model.OntPE;
2723
import com.github.owlcs.ontapi.jena.model.OntStatement;
2824
import com.github.owlcs.ontapi.jena.utils.OntModels;
25+
import org.apache.jena.graph.Triple;
26+
import org.apache.jena.util.iterator.ExtendedIterator;
27+
import org.apache.jena.vocabulary.RDFS;
28+
import org.semanticweb.owlapi.model.*;
29+
30+
import java.util.function.Supplier;
2931

3032
/**
31-
* The base class for {@link ObjectPropertyDomainTranslator} and {@link DataPropertyDomainTranslator} and {@link AnnotationPropertyDomainTranslator}.
32-
* The for mapping statement with {@code rdfs:domain} predicate.
33+
* The base class for {@link ObjectPropertyDomainTranslator},
34+
* {@link DataPropertyDomainTranslator} and {@link AnnotationPropertyDomainTranslator} axioms.
35+
* All of them are based on a statement with {@code rdfs:domain} predicate.
3336
* <p>
3437
* Created by @szuev on 30.09.2016.
3538
*/
@@ -55,4 +58,66 @@ protected boolean filter(OntStatement statement, InternalConfig config) {
5558
public boolean testStatement(OntStatement statement, InternalConfig config) {
5659
return RDFS.domain.equals(statement.getPredicate()) && filter(statement, config);
5760
}
61+
62+
/**
63+
* @param <A> either {@link OWLDataPropertyDomainAxiom}
64+
* or {@link OWLObjectPropertyDomainAxiom} or {@link OWLAnnotationPropertyDomainAxiom}
65+
* @param <P> either {@link OWLAnnotationProperty}
66+
* or {@link OWLDataPropertyExpression} or {@link OWLObjectPropertyExpression}
67+
* @param <D> either {@link OWLClassExpression} or {@link IRI}
68+
*/
69+
@SuppressWarnings("WeakerAccess")
70+
protected abstract static class DomainAxiomImpl<A extends OWLAxiom & HasProperty<P> & HasDomain<D>,
71+
P extends OWLPropertyExpression, D extends OWLObject>
72+
extends ONTAxiomImpl<A> implements WithTwoObjects<P, D> {
73+
74+
protected DomainAxiomImpl(Triple t, Supplier<OntGraphModel> m) {
75+
super(t, m);
76+
}
77+
78+
protected DomainAxiomImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
79+
super(subject, predicate, object, m);
80+
}
81+
82+
public P getProperty() {
83+
return getONTSubject().getOWLObject();
84+
}
85+
86+
public D getDomain() {
87+
return getONTObject().getOWLObject();
88+
}
89+
}
90+
91+
/**
92+
* @param <A> either {@link OWLDataPropertyDomainAxiom} or {@link OWLObjectPropertyDomainAxiom}
93+
* @param <P> either {@link OWLDataPropertyExpression} or {@link OWLObjectPropertyExpression}
94+
*/
95+
@SuppressWarnings("WeakerAccess")
96+
protected abstract static class ClassDomainAxiomImpl<A extends OWLAxiom & HasProperty<P> & HasDomain<OWLClassExpression>,
97+
P extends OWLPropertyExpression> extends DomainAxiomImpl<A, P, OWLClassExpression> {
98+
99+
protected ClassDomainAxiomImpl(Triple t, Supplier<OntGraphModel> m) {
100+
super(t, m);
101+
}
102+
103+
protected ClassDomainAxiomImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
104+
super(subject, predicate, object, m);
105+
}
106+
107+
@Override
108+
public final boolean canContainAnnotationProperties() {
109+
return isAnnotated();
110+
}
111+
112+
@Override
113+
public ONTObject<? extends OWLClassExpression> getURIObject(InternalObjectFactory factory) {
114+
return ONTClassImpl.find(getObjectURI(), factory, model);
115+
}
116+
117+
@Override
118+
public ONTObject<? extends OWLClassExpression> objectFromStatement(OntStatement statement,
119+
InternalObjectFactory factory) {
120+
return factory.getClass(statement.getObject(OntCE.class));
121+
}
122+
}
58123
}

src/main/java/com/github/owlcs/ontapi/internal/axioms/AbstractSubPropertyTranslator.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
package com.github.owlcs.ontapi.internal.axioms;
1616

17-
import org.apache.jena.graph.Triple;
18-
import org.apache.jena.util.iterator.ExtendedIterator;
19-
import org.apache.jena.vocabulary.RDFS;
20-
import org.semanticweb.owlapi.model.OWLAxiom;
21-
import org.semanticweb.owlapi.model.OWLPropertyExpression;
2217
import com.github.owlcs.ontapi.internal.AxiomTranslator;
2318
import com.github.owlcs.ontapi.internal.InternalConfig;
2419
import com.github.owlcs.ontapi.internal.WriteHelper;
@@ -28,6 +23,11 @@
2823
import com.github.owlcs.ontapi.jena.model.OntPE;
2924
import com.github.owlcs.ontapi.jena.model.OntStatement;
3025
import com.github.owlcs.ontapi.jena.utils.OntModels;
26+
import org.apache.jena.graph.Triple;
27+
import org.apache.jena.util.iterator.ExtendedIterator;
28+
import org.apache.jena.vocabulary.RDFS;
29+
import org.semanticweb.owlapi.model.OWLAxiom;
30+
import org.semanticweb.owlapi.model.OWLPropertyExpression;
3131

3232
import java.util.function.Supplier;
3333

@@ -77,14 +77,14 @@ public void write(Axiom axiom, OntGraphModel model) {
7777
* @param <P> - subtype of {@link OWLPropertyExpression}
7878
*/
7979
@SuppressWarnings("WeakerAccess")
80-
public abstract static class SubPropertyImpl<A extends OWLAxiom, P extends OWLPropertyExpression>
80+
public abstract static class SubPropertyAxiomImpl<A extends OWLAxiom, P extends OWLPropertyExpression>
8181
extends ONTAxiomImpl<A> implements WithTwoObjects.Unary<P> {
8282

83-
protected SubPropertyImpl(Triple t, Supplier<OntGraphModel> m) {
83+
protected SubPropertyAxiomImpl(Triple t, Supplier<OntGraphModel> m) {
8484
super(t, m);
8585
}
8686

87-
protected SubPropertyImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
87+
protected SubPropertyAxiomImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
8888
super(subject, predicate, object, m);
8989
}
9090

0 commit comments

Comments
 (0)