Skip to content

Package: OntologySnapshot

OntologySnapshot

nameinstructionbranchcomplexitylinemethod
OntologySnapshot(OWLOntology, OWLOntologyManager, OWLDataFactory, OWLReasoner)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
applyChanges(List)
M: 6 C: 19
76%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
getDataFactory()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOntology()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOntologyManager()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getReasoner()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$applyChanges$0(TransactionalChange)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.owlapi.connector;
19:
20: import cz.cvut.kbss.ontodriver.owlapi.change.TransactionalChange;
21: import cz.cvut.kbss.ontodriver.owlapi.exception.OntologyChangeApplicationException;
22: import org.semanticweb.owlapi.model.OWLDataFactory;
23: import org.semanticweb.owlapi.model.OWLOntology;
24: import org.semanticweb.owlapi.model.OWLOntologyChange;
25: import org.semanticweb.owlapi.model.OWLOntologyManager;
26: import org.semanticweb.owlapi.model.parameters.ChangeApplied;
27: import org.semanticweb.owlapi.reasoner.OWLReasoner;
28:
29: import java.util.List;
30: import java.util.stream.Collectors;
31:
32: public class OntologySnapshot {
33:
34: private final OWLOntology ontology;
35: private final OWLOntologyManager ontologyManager;
36: private final OWLDataFactory dataFactory;
37: private final OWLReasoner reasoner;
38:
39: public OntologySnapshot(OWLOntology ontology, OWLOntologyManager ontologyManager, OWLDataFactory dataFactory,
40: OWLReasoner reasoner) {
41: this.ontology = ontology;
42: this.ontologyManager = ontologyManager;
43: this.dataFactory = dataFactory;
44: this.reasoner = reasoner;
45: }
46:
47: public OWLOntology getOntology() {
48: return ontology;
49: }
50:
51: public OWLOntologyManager getOntologyManager() {
52: return ontologyManager;
53: }
54:
55: public OWLDataFactory getDataFactory() {
56: return dataFactory;
57: }
58:
59: public OWLReasoner getReasoner() {
60: return reasoner;
61: }
62:
63: /**
64: * Applies the specified changes to this ontology snapshot.
65: *
66: * @param changes The changes to apply
67: * @return The applied changes
68: */
69: public List<TransactionalChange> applyChanges(List<TransactionalChange> changes) {
70: final List<OWLOntologyChange> toApply = changes.stream()
71: .flatMap(o -> o.toOwlChanges(ontology).stream())
72: .collect(Collectors.toList());
73: final ChangeApplied result = ontologyManager.applyChanges(toApply);
74:• if (result == ChangeApplied.UNSUCCESSFULLY) {
75: throw new OntologyChangeApplicationException(
76: "At least one of the following changes could not have been applied to this ontology snapshot: " +
77: toApply);
78: }
79: return changes;
80: }
81: }