Skip to content

Package: ExplicitAxiomLoader

ExplicitAxiomLoader

nameinstructionbranchcomplexitylinemethod
ExplicitAxiomLoader(OwlapiAdapter, OntologySnapshot)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
annotationPropertyValuesToAxioms(NamedResource, Stream)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
dataPropertyValuesToAxioms(NamedResource, Stream)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
doesPropertyExist(IRI)
M: 0 C: 16
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$annotationPropertyValuesToAxioms$4(NamedResource, OWLAnnotationAssertionAxiom)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$dataPropertyValuesToAxioms$1(NamedResource, OWLDataPropertyAssertionAxiom)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$loadAxioms$0(Assertion)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$loadPropertyAxioms$5(Collection, NamedResource, OWLDataPropertyAssertionAxiom)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$loadPropertyAxioms$6(Collection, NamedResource, OWLObjectPropertyAssertionAxiom)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$loadPropertyAxioms$7(Collection, NamedResource, OWLAnnotationAssertionAxiom)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$objectPropertyValuesToAxioms$2(OWLObjectPropertyAssertionAxiom)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$objectPropertyValuesToAxioms$3(NamedResource, OWLObjectPropertyAssertionAxiom)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
loadAxioms(NamedResource, Set)
M: 0 C: 74
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
loadPropertyAxioms(NamedResource)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
objectPropertyValuesToAxioms(NamedResource, Stream)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
shouldLoadAnnotationPropertyValue(OWLAnnotationAssertionAxiom)
M: 0 C: 60
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
shouldLoadDataPropertyValue(OWLDataPropertyAssertionAxiom)
M: 0 C: 50
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 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.Assertion;
18: import cz.cvut.kbss.ontodriver.model.Axiom;
19: import cz.cvut.kbss.ontodriver.model.NamedResource;
20: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
21: import cz.cvut.kbss.ontodriver.owlapi.util.OwlapiUtils;
22: import org.semanticweb.owlapi.model.*;
23:
24: import java.net.URI;
25: import java.util.*;
26: import java.util.stream.Collectors;
27: import java.util.stream.Stream;
28:
29: class ExplicitAxiomLoader implements AxiomLoader {
30:
31: private static final Assertion UNSPECIFIED_ASSERTION = Assertion.createUnspecifiedPropertyAssertion(false);
32:
33: private final OWLOntology ontology;
34: private final OWLDataFactory dataFactory;
35:
36: private final OwlapiAdapter adapter;
37: private final AxiomAdapter axiomAdapter;
38: private final String language;
39:
40: private Map<URI, Assertion> assertionMap;
41:
42: ExplicitAxiomLoader(OwlapiAdapter adapter, OntologySnapshot snapshot) {
43: this.adapter = adapter;
44: this.ontology = snapshot.getOntology();
45: this.dataFactory = snapshot.getDataFactory();
46: this.axiomAdapter = new AxiomAdapter(dataFactory, adapter.getLanguage());
47: this.language = adapter.getLanguage();
48: }
49:
50: @Override
51: public Collection<Axiom<?>> loadAxioms(NamedResource subject, Set<Assertion> assertions) {
52: this.assertionMap = new HashMap<>(assertions.size());
53: assertions.forEach(a -> assertionMap.put(a.getIdentifier(), a));
54: final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory);
55: final Collection<Axiom<?>> axioms = new ArrayList<>();
56:• if (assertions.contains(Assertion.createClassAssertion(false))) {
57: axioms.addAll(adapter.getTypesHandler().getTypes(subject, null, false));
58: }
59: // This involves a lot of filtering, perhaps we should use EntitySearcher and look for values of concrete properties
60: final Stream<OWLDataPropertyAssertionAxiom> dpAssertions = ontology.dataPropertyAssertionAxioms(individual);
61: axioms.addAll(dataPropertyValuesToAxioms(subject, dpAssertions));
62: final Stream<OWLObjectPropertyAssertionAxiom> opAssertions = ontology.objectPropertyAssertionAxioms(individual);
63: axioms.addAll(objectPropertyValuesToAxioms(subject, opAssertions));
64: final Stream<OWLAnnotationAssertionAxiom> apAssertions = ontology.annotationAssertionAxioms(individual.getIRI());
65: axioms.addAll(annotationPropertyValuesToAxioms(subject, apAssertions));
66: return axioms;
67: }
68:
69: private Collection<Axiom<?>> dataPropertyValuesToAxioms(NamedResource subject,
70: Stream<OWLDataPropertyAssertionAxiom> axioms) {
71: return axioms.filter(this::shouldLoadDataPropertyValue)
72: .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
73: .collect(Collectors.toList());
74: }
75:
76: private boolean shouldLoadDataPropertyValue(OWLDataPropertyAssertionAxiom axiom) {
77: final OWLLiteral value = axiom.getObject();
78: final IRI dpIri = axiom.getProperty().asOWLDataProperty().getIRI();
79: final boolean propertyExists = doesPropertyExist(dpIri);
80:• if (!propertyExists) {
81: return false;
82: }
83: final URI dpUri = dpIri.toURI();
84: // Note: I don't really like the fact that we are basing this on a randomly generated identifier of the unspecified
85: // property. Perhaps the strategy of using unspecified properties should be revisited.
86:• final Assertion assertion = assertionMap.containsKey(dpUri) ? assertionMap.get(dpUri) :
87: assertionMap.get(UNSPECIFIED_ASSERTION.getIdentifier());
88:• return OwlapiUtils.doesLanguageMatch(value, assertion.hasLanguage() ? assertion.getLanguage() : language);
89: }
90:
91: private boolean doesPropertyExist(IRI o) {
92:• return assertionMap.containsKey(o.toURI()) || assertionMap.containsKey(UNSPECIFIED_ASSERTION.getIdentifier());
93: }
94:
95: private Collection<Axiom<?>> objectPropertyValuesToAxioms(NamedResource subject,
96: Stream<OWLObjectPropertyAssertionAxiom> axiomStream) {
97: return axiomStream.filter(axiom ->
98: doesPropertyExist(axiom.getProperty().asOWLObjectProperty().getIRI()))
99: .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
100: .collect(Collectors.toList());
101: }
102:
103: private Collection<Axiom<?>> annotationPropertyValuesToAxioms(NamedResource subject,
104: Stream<OWLAnnotationAssertionAxiom> axioms) {
105: return axioms.filter(this::shouldLoadAnnotationPropertyValue)
106: .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
107: .collect(Collectors.toList());
108: }
109:
110: private boolean shouldLoadAnnotationPropertyValue(OWLAnnotationAssertionAxiom axiom) {
111: final OWLAnnotationValue value = axiom.getValue();
112: final IRI apIri = axiom.getProperty().asOWLAnnotationProperty().getIRI();
113: final boolean propertyExists = doesPropertyExist(apIri);
114:• if (!propertyExists) {
115: return false;
116: }
117: final URI apUri = apIri.toURI();
118:• final Assertion assertion = assertionMap.containsKey(apUri) ? assertionMap.get(apUri) :
119: assertionMap.get(UNSPECIFIED_ASSERTION.getIdentifier());
120:• return !value.asLiteral().isPresent() || OwlapiUtils.doesLanguageMatch(value.asLiteral().get(),
121:• assertion.hasLanguage() ? assertion.getLanguage() : language);
122: }
123:
124: @Override
125: public Collection<Axiom<?>> loadPropertyAxioms(NamedResource subject) {
126: final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory);
127: final Collection<Axiom<?>> axioms = new ArrayList<>();
128: ontology.dataPropertyAssertionAxioms(individual)
129: .forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
130: ontology.objectPropertyAssertionAxioms(individual)
131: .forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
132: ontology.annotationAssertionAxioms(individual.getIRI())
133: .forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
134: return axioms;
135: }
136: }