|
14 | 14 |
|
15 | 15 | package com.github.owlcs.ontapi.internal.axioms;
|
16 | 16 |
|
17 |
| -import org.apache.jena.util.iterator.ExtendedIterator; |
18 |
| -import org.apache.jena.util.iterator.NullIterator; |
19 |
| -import org.semanticweb.owlapi.model.*; |
20 | 17 | 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; |
21 | 22 | import com.github.owlcs.ontapi.jena.model.OntGraphModel;
|
22 | 23 | import com.github.owlcs.ontapi.jena.model.OntNAP;
|
23 | 24 | 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.*; |
24 | 29 |
|
| 30 | +import java.util.Arrays; |
25 | 31 | import java.util.Collection;
|
| 32 | +import java.util.Set; |
| 33 | +import java.util.function.BiFunction; |
| 34 | +import java.util.function.Supplier; |
26 | 35 |
|
27 | 36 | /**
|
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. |
29 | 39 | * <p>
|
30 | 40 | * Created by @szuev on 30.09.2016.
|
31 | 41 | */
|
@@ -65,14 +75,175 @@ public boolean testStatement(OntStatement statement, InternalConfig config) {
|
65 | 75 |
|
66 | 76 | @Override
|
67 | 77 | 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, |
69 | 87 | 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() |
74 | 92 | .getOWLAnnotationPropertyDomainAxiom(p.getOWLObject(), d.getOWLObject(), ONTObject.toSet(annotations));
|
75 | 93 | return ONTWrapperImpl.create(res, statement).append(annotations).append(p).append(d);
|
76 | 94 | }
|
77 | 95 |
|
| 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 | + } |
78 | 249 | }
|
0 commit comments