Skip to content

Commit 45e351e

Browse files
committed
ont-api: add model-impl for OWLAnnotationPropertyDomainAxiom (#2) + add tests
1 parent c9cb6d8 commit 45e351e

File tree

6 files changed

+231
-13
lines changed

6 files changed

+231
-13
lines changed

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

+180-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,28 @@
1414

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

17-
import org.apache.jena.util.iterator.ExtendedIterator;
18-
import org.apache.jena.util.iterator.NullIterator;
19-
import org.semanticweb.owlapi.model.*;
2017
import com.github.owlcs.ontapi.internal.*;
18+
import com.github.owlcs.ontapi.internal.objects.FactoryAccessor;
19+
import com.github.owlcs.ontapi.internal.objects.ONTAnnotationPropertyImpl;
20+
import com.github.owlcs.ontapi.internal.objects.ONTEntityImpl;
21+
import com.github.owlcs.ontapi.internal.objects.ONTStatementImpl;
2122
import com.github.owlcs.ontapi.jena.model.OntGraphModel;
2223
import com.github.owlcs.ontapi.jena.model.OntNAP;
2324
import com.github.owlcs.ontapi.jena.model.OntStatement;
25+
import org.apache.jena.graph.Triple;
26+
import org.apache.jena.util.iterator.ExtendedIterator;
27+
import org.apache.jena.util.iterator.NullIterator;
28+
import org.semanticweb.owlapi.model.*;
2429

30+
import java.util.Arrays;
2531
import java.util.Collection;
32+
import java.util.Set;
33+
import java.util.function.BiFunction;
34+
import java.util.function.Supplier;
2635

2736
/**
28-
* Translator for {@link AbstractPropertyDomainTranslator}.
37+
* A translator that provides {@link OWLAnnotationPropertyDomainAxiom} implementations.
38+
* The main triple is {@code A rdfs:domain U}, where {@code A} is annotation property and {@code U} is IRI.
2939
* <p>
3040
* Created by @szuev on 30.09.2016.
3141
*/
@@ -65,14 +75,175 @@ public boolean testStatement(OntStatement statement, InternalConfig config) {
6575

6676
@Override
6777
public ONTObject<OWLAnnotationPropertyDomainAxiom> toAxiom(OntStatement statement,
68-
InternalObjectFactory reader,
78+
Supplier<OntGraphModel> model,
79+
InternalObjectFactory factory,
80+
InternalConfig config) {
81+
return AxiomImpl.create(statement, model, factory, config);
82+
}
83+
84+
@Override
85+
public ONTObject<OWLAnnotationPropertyDomainAxiom> toAxiom(OntStatement statement,
86+
InternalObjectFactory factory,
6987
InternalConfig config) {
70-
ONTObject<OWLAnnotationProperty> p = reader.getProperty(statement.getSubject(getView()));
71-
ONTObject<IRI> d = reader.getIRI(statement.getResource().getURI());
72-
Collection<ONTObject<OWLAnnotation>> annotations = reader.getAnnotations(statement, config);
73-
OWLAnnotationPropertyDomainAxiom res = reader.getOWLDataFactory()
88+
ONTObject<OWLAnnotationProperty> p = factory.getProperty(statement.getSubject(getView()));
89+
ONTObject<IRI> d = factory.getIRI(statement.getResource().getURI());
90+
Collection<ONTObject<OWLAnnotation>> annotations = factory.getAnnotations(statement, config);
91+
OWLAnnotationPropertyDomainAxiom res = factory.getOWLDataFactory()
7492
.getOWLAnnotationPropertyDomainAxiom(p.getOWLObject(), d.getOWLObject(), ONTObject.toSet(annotations));
7593
return ONTWrapperImpl.create(res, statement).append(annotations).append(p).append(d);
7694
}
7795

96+
/**
97+
* @see com.github.owlcs.ontapi.owlapi.axioms.OWLAnnotationPropertyDomainAxiomImpl
98+
*/
99+
@SuppressWarnings("WeakerAccess")
100+
public abstract static class AxiomImpl
101+
extends DomainAxiomImpl<OWLAnnotationPropertyDomainAxiom, OWLAnnotationProperty, IRI>
102+
implements OWLAnnotationPropertyDomainAxiom {
103+
104+
protected AxiomImpl(Triple t, Supplier<OntGraphModel> m) {
105+
super(t, m);
106+
}
107+
108+
/**
109+
* Creates an {@link ONTObject} container that is also {@link OWLAnnotationPropertyDomainAxiom}.
110+
*
111+
* @param statement {@link OntStatement}, not {@code null}
112+
* @param model {@link OntGraphModel} provider, not {@code null}
113+
* @param factory {@link InternalObjectFactory}, not {@code null}
114+
* @param config {@link InternalConfig}, not {@code null}
115+
* @return {@link AxiomImpl}
116+
*/
117+
public static AxiomImpl create(OntStatement statement,
118+
Supplier<OntGraphModel> model,
119+
InternalObjectFactory factory,
120+
InternalConfig config) {
121+
return WithTwoObjects.create(statement, model,
122+
SimpleImpl.FACTORY, WithAnnotationsImpl.FACTORY, SET_HASH_CODE, factory, config);
123+
}
124+
125+
@Override
126+
public ONTObject<? extends OWLAnnotationProperty> getURISubject(InternalObjectFactory factory) {
127+
return ONTAnnotationPropertyImpl.find(getSubjectURI(), factory, model);
128+
}
129+
130+
@Override
131+
public ONTObject<? extends IRI> getURIObject(InternalObjectFactory factory) {
132+
return factory.getIRI(getObjectURI());
133+
}
134+
135+
@Override
136+
public ONTObject<? extends OWLAnnotationProperty> subjectFromStatement(OntStatement statement,
137+
InternalObjectFactory factory) {
138+
return factory.getProperty(statement.getSubject(OntNAP.class));
139+
}
140+
141+
@Override
142+
public ONTObject<? extends IRI> objectFromStatement(OntStatement statement, InternalObjectFactory factory) {
143+
return factory.getIRI(statement.getObject().asNode().getURI());
144+
}
145+
146+
@FactoryAccessor
147+
@Override
148+
protected OWLAnnotationPropertyDomainAxiom createAnnotatedAxiom(Collection<OWLAnnotation> annotations) {
149+
return getDataFactory().getOWLAnnotationPropertyDomainAxiom(eraseModel(getProperty()),
150+
getDomain(), annotations);
151+
}
152+
153+
@Override
154+
public final boolean canContainNamedClasses() {
155+
return false;
156+
}
157+
158+
@Override
159+
public final boolean canContainNamedIndividuals() {
160+
return false;
161+
}
162+
163+
@Override
164+
public final boolean canContainObjectProperties() {
165+
return false;
166+
}
167+
168+
@Override
169+
public final boolean canContainDataProperties() {
170+
return false;
171+
}
172+
173+
@Override
174+
public final boolean canContainClassExpressions() {
175+
return false;
176+
}
177+
178+
/**
179+
* An {@link OWLAnnotationPropertyDomainAxiom} without annotations.
180+
*/
181+
public static class SimpleImpl extends AxiomImpl implements Simple<OWLAnnotationProperty, IRI> {
182+
183+
private static final BiFunction<Triple, Supplier<OntGraphModel>, SimpleImpl> FACTORY = SimpleImpl::new;
184+
185+
protected SimpleImpl(Triple t, Supplier<OntGraphModel> m) {
186+
super(t, m);
187+
}
188+
189+
@Override
190+
public Set<OWLAnnotationProperty> getAnnotationPropertySet() {
191+
return createSet(getONTSubject().getOWLObject());
192+
}
193+
194+
@Override
195+
public Set<OWLEntity> getSignatureSet() {
196+
return createSet(getONTSubject().getOWLObject());
197+
}
198+
199+
@Override
200+
public boolean containsAnnotationProperty(OWLAnnotationProperty property) {
201+
return getSubjectURI().equals(ONTEntityImpl.getURI(property));
202+
}
203+
204+
@Override
205+
protected boolean sameContent(ONTStatementImpl other) {
206+
return false;
207+
}
208+
209+
@Override
210+
public boolean canContainDatatypes() {
211+
return false;
212+
}
213+
214+
@Override
215+
public boolean canContainAnonymousIndividuals() {
216+
return false;
217+
}
218+
}
219+
220+
/**
221+
* An {@link OWLAnnotationPropertyDomainAxiom} with annotations.
222+
* It has a public constructor since it is more generic then {@link SimpleImpl}.
223+
*/
224+
public static class WithAnnotationsImpl extends AxiomImpl
225+
implements Complex<WithAnnotationsImpl, OWLAnnotationProperty, IRI> {
226+
227+
private static final BiFunction<Triple, Supplier<OntGraphModel>, WithAnnotationsImpl> FACTORY =
228+
WithAnnotationsImpl::new;
229+
230+
protected final InternalCache.Loading<WithAnnotationsImpl, Object[]> content;
231+
232+
public WithAnnotationsImpl(Triple t, Supplier<OntGraphModel> m) {
233+
super(t, m);
234+
this.content = createContentCache();
235+
}
236+
237+
@Override
238+
public InternalCache.Loading<WithAnnotationsImpl, Object[]> getContentCache() {
239+
return content;
240+
}
241+
242+
@Override
243+
protected boolean sameContent(ONTStatementImpl other) {
244+
return other instanceof WithAnnotationsImpl
245+
&& Arrays.equals(getContent(), ((WithAnnotationsImpl) other).getContent());
246+
}
247+
}
248+
}
78249
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected AxiomImpl(Triple t, Supplier<OntGraphModel> m) {
8383
super(t, m);
8484
}
8585

86-
public AxiomImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
86+
protected AxiomImpl(Object subject, String predicate, Object object, Supplier<OntGraphModel> m) {
8787
super(subject, predicate, object, m);
8888
}
8989

@@ -134,7 +134,7 @@ public OWLSubClassOfAxiom asOWLSubClassOfAxiom() {
134134
* An {@link OWLDataPropertyDomainAxiom}
135135
* that has named class expression ({@link OWLClass OWL Class}) as object and has no annotations.
136136
*/
137-
protected static class SimpleImpl extends AxiomImpl
137+
public static class SimpleImpl extends AxiomImpl
138138
implements Simple<OWLDataPropertyExpression, OWLClassExpression> {
139139

140140
private static final BiFunction<Triple, Supplier<OntGraphModel>, SimpleImpl> FACTORY = SimpleImpl::new;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected AxiomImpl(Triple t, Supplier<OntGraphModel> m) {
8484
super(t, m);
8585
}
8686

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

@@ -135,7 +135,7 @@ public OWLSubClassOfAxiom asOWLSubClassOfAxiom() {
135135
* An {@link OWLObjectPropertyDomainAxiom}
136136
* that has named object property and class expressions and has no annotations.
137137
*/
138-
protected static class SimpleImpl extends AxiomImpl
138+
public static class SimpleImpl extends AxiomImpl
139139
implements Simple<OWLObjectPropertyExpression, OWLClassExpression> {
140140

141141
private static final BiFunction<Triple, Supplier<OntGraphModel>, SimpleImpl> FACTORY = SimpleImpl::new;

src/test/java/com/github/owlcs/ontapi/tests/TestFactory.java

+40
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,46 @@ public String toString() {
26142614
"df.getOWLObjectComplementOf(df.getOWLClass(\"C\")), Collections.emptyList())";
26152615
}
26162616
}
2617+
, new AxiomData() {
2618+
@Override
2619+
public AxiomType getType() {
2620+
return AxiomType.ANNOTATION_PROPERTY_DOMAIN;
2621+
}
2622+
2623+
@Override
2624+
public OWLObject create(OWLDataFactory df) {
2625+
return df.getOWLAnnotationPropertyDomainAxiom(df.getOWLAnnotationProperty("P"), IRI.create("D"));
2626+
}
2627+
2628+
@Override
2629+
public String toString() {
2630+
return "df.getOWLAnnotationPropertyDomainAxiom(df.getOWLAnnotationProperty(\"P\"), " +
2631+
"IRI.create(\"D\"))";
2632+
}
2633+
}
2634+
, new AxiomData() {
2635+
@Override
2636+
public AxiomType getType() {
2637+
return AxiomType.ANNOTATION_PROPERTY_DOMAIN;
2638+
}
2639+
2640+
@Override
2641+
public OWLObject create(OWLDataFactory df) {
2642+
return df.getOWLAnnotationPropertyDomainAxiom(df.getOWLAnnotationProperty("P"), IRI.create("D"),
2643+
Arrays.asList(df.getOWLAnnotation(df.getRDFSSeeAlso(), IRI.create("D")),
2644+
df.getRDFSComment("commm"),
2645+
df.getRDFSLabel(df.getOWLAnonymousIndividual("_:b0"))));
2646+
}
2647+
2648+
@Override
2649+
public String toString() {
2650+
return "df.getOWLAnnotationPropertyDomainAxiom(df.getOWLAnnotationProperty(\"P\"), " +
2651+
"IRI.create(\"D\"), " +
2652+
"Arrays.asList(df.getOWLAnnotation(df.getRDFSSeeAlso(), IRI.create(\"D\")), " +
2653+
"df.getRDFSComment(\"commm\"), " +
2654+
"df.getRDFSLabel(df.getOWLAnonymousIndividual(\"_:b0\"))))";
2655+
}
2656+
}
26172657
);
26182658
}
26192659

src/test/java/com/github/owlcs/ontapi/tests/internal/AxiomPropertiesTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public void testObjectPropertyDomain() {
102102
testAxiom(data, (Function<OWLObjectPropertyDomainAxiom, Object>) HasDomain::getDomain, HasProperty::getProperty);
103103
}
104104

105+
@Test
106+
public void testAnnotationPropertyDomain() {
107+
List<TestFactory.AxiomData> data = CommonAxiomsTest.getAxiomData(AxiomType.ANNOTATION_PROPERTY_DOMAIN);
108+
testAxiom(data, (Function<OWLAnnotationPropertyDomainAxiom, Object>) HasDomain::getDomain, HasProperty::getProperty);
109+
}
110+
105111
@SuppressWarnings("unchecked")
106112
@SafeVarargs
107113
private static <X extends OWLAxiom> void testAxiom(List<TestFactory.AxiomData> data,

src/test/java/com/github/owlcs/ontapi/tests/internal/CommonAxiomsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static List<AxiomData> getData() {
6565
, AxiomType.DISJOINT_UNION
6666
, AxiomType.DATA_PROPERTY_DOMAIN
6767
, AxiomType.OBJECT_PROPERTY_DOMAIN
68+
, AxiomType.ANNOTATION_PROPERTY_DOMAIN
6869
);
6970
}
7071

0 commit comments

Comments
 (0)