Package: AxiomAdapter
AxiomAdapter
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AxiomAdapter(OWLDataFactory) |
|
|
|
|
|
||||||||||||||||||||
createAxiom(NamedResource, Assertion, Object) |
|
|
|
|
|
||||||||||||||||||||
toAxiom(NamedResource, OWLAnnotationAssertionAxiom) |
|
|
|
|
|
||||||||||||||||||||
toAxiom(NamedResource, OWLDataPropertyExpression, OWLLiteral) |
|
|
|
|
|
||||||||||||||||||||
toAxiom(NamedResource, OWLObjectPropertyExpression, OWLIndividual) |
|
|
|
|
|
||||||||||||||||||||
toOWLIndividual(NamedResource) |
|
|
|
|
|
||||||||||||||||||||
toOwlAnnotationPropertyAssertionAxiom(Axiom) |
|
|
|
|
|
||||||||||||||||||||
toOwlClassAssertionAxiom(Axiom) |
|
|
|
|
|
||||||||||||||||||||
toOwlDataPropertyAssertionAxiom(Axiom) |
|
|
|
|
|
||||||||||||||||||||
toOwlObjectPropertyAssertionAxiom(Axiom) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.owlapi;
16:
17: import cz.cvut.kbss.ontodriver.model.*;
18: import cz.cvut.kbss.ontodriver.owlapi.util.OwlapiUtils;
19: import org.semanticweb.owlapi.model.*;
20:
21: /**
22: * Adapts OWLAPI axioms to JOPA (OntoDriver) axioms and vice versa.
23: */
24: public class AxiomAdapter {
25:
26: private final OWLDataFactory dataFactory;
27:
28: public AxiomAdapter(OWLDataFactory dataFactory) {
29: this.dataFactory = dataFactory;
30: }
31:
32: OWLAxiom toOwlClassAssertionAxiom(Axiom<?> axiom) {
33: final OWLClass owlClass = dataFactory.getOWLClass(IRI.create(axiom.getValue().stringValue()));
34: return dataFactory.getOWLClassAssertionAxiom(owlClass, toOWLIndividual(axiom.getSubject()));
35: }
36:
37: public OWLAxiom toOwlObjectPropertyAssertionAxiom(Axiom<?> axiom) {
38: final OWLObjectProperty objectProperty = dataFactory
39: .getOWLObjectProperty(IRI.create(axiom.getAssertion().getIdentifier()));
40: final OWLNamedIndividual objectValue = dataFactory.getOWLNamedIndividual(
41: IRI.create(axiom.getValue().stringValue()));
42: return dataFactory.getOWLObjectPropertyAssertionAxiom(objectProperty, toOWLIndividual(axiom.getSubject()),
43: objectValue);
44: }
45:
46: OWLAxiom toOwlDataPropertyAssertionAxiom(Axiom<?> axiom) {
47: final OWLDataProperty dataProperty = dataFactory
48: .getOWLDataProperty(IRI.create(axiom.getAssertion().getIdentifier()));
49: final OWLLiteral dataValue = OwlapiUtils.createOWLLiteralFromValue(axiom.getValue().getValue(),
50: OwlapiUtils.getAssertionLanguage(axiom.getAssertion()));
51: return dataFactory
52: .getOWLDataPropertyAssertionAxiom(dataProperty, toOWLIndividual(axiom.getSubject()), dataValue);
53: }
54:
55: OWLAxiom toOwlAnnotationPropertyAssertionAxiom(Axiom<?> axiom) {
56: final OWLAnnotationProperty annotationProperty = dataFactory.getOWLAnnotationProperty(IRI.create(
57: axiom.getAssertion().getIdentifier()));
58: final Object value = axiom.getValue().getValue();
59: final OWLAnnotationValue annotationValue;
60:• if (OwlapiUtils.isIndividualIri(value)) {
61: annotationValue = IRI.create(value.toString());
62: } else {
63: annotationValue = OwlapiUtils.createOWLLiteralFromValue(
64: axiom.getValue().getValue(), OwlapiUtils.getAssertionLanguage(axiom.getAssertion()));
65: }
66: return dataFactory
67: .getOWLAnnotationAssertionAxiom(annotationProperty, toOWLIndividual(axiom.getSubject()).getIRI(),
68: annotationValue);
69: }
70:
71: private OWLNamedIndividual toOWLIndividual(NamedResource subject) {
72: return dataFactory.getOWLNamedIndividual(IRI.create(subject.getIdentifier()));
73: }
74:
75: public <V> Axiom<V> createAxiom(NamedResource subject, Assertion assertion, V value) {
76: return new AxiomImpl<>(subject, assertion, new Value<>(value));
77: }
78:
79: Axiom<?> toAxiom(NamedResource subject, OWLDataPropertyExpression dataProperty, OWLLiteral value) {
80: final Assertion assertion =
81: Assertion.createDataPropertyAssertion(dataProperty.asOWLDataProperty().getIRI().toURI(),
82: false);
83: return createAxiom(subject, assertion, OwlapiUtils.owlLiteralToValue(value));
84: }
85:
86: Axiom<?> toAxiom(NamedResource subject, OWLObjectPropertyExpression objectProperty, OWLIndividual value) {
87: final Assertion assertion =
88: Assertion.createObjectPropertyAssertion(objectProperty.asOWLObjectProperty().getIRI().toURI(),
89: false);
90: final IRI target = value.asOWLNamedIndividual().getIRI();
91: return createAxiom(subject, assertion, NamedResource.create(target.toURI()));
92: }
93:
94: Axiom<?> toAxiom(NamedResource subject, OWLAnnotationAssertionAxiom assertionAxiom) {
95: final Assertion assertion = Assertion
96: .createAnnotationPropertyAssertion(
97: assertionAxiom.getProperty().asOWLAnnotationProperty().getIRI().toURI(),
98: false);
99:• if (assertionAxiom.getValue().asIRI().isPresent()) {
100: return createAxiom(subject, assertion, assertionAxiom.getValue().asIRI().get().toURI());
101: } else {
102: return createAxiom(subject, assertion, OwlapiUtils.owlLiteralToValue(
103: assertionAxiom.getValue().asLiteral().get()));
104: }
105: }
106: }