Skip to content

Package: AxiomSaver

AxiomSaver

nameinstructionbranchcomplexitylinemethod
AxiomSaver(Connector, ValueFactory, String)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createSesameStatements(NamedResource, Assertion, Collection, URI)
M: 0 C: 59
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
createStatement(Resource, URI, Value, URI)
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
persistAxioms(AxiomValueDescriptor)
M: 0 C: 38
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
persistAxioms(NamedResource, Map, URI)
M: 0 C: 37
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 7
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.sesame;
16:
17: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
18: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
19: import cz.cvut.kbss.ontodriver.descriptor.AxiomValueDescriptor;
20: import cz.cvut.kbss.ontodriver.model.Assertion;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22: import cz.cvut.kbss.ontodriver.model.Value;
23: import org.openrdf.model.Resource;
24: import org.openrdf.model.Statement;
25: import org.openrdf.model.ValueFactory;
26:
27: import java.net.URI;
28: import java.util.*;
29:
30: class AxiomSaver {
31:
32: private final Connector connector;
33: private final ValueFactory valueFactory;
34: private final SesameValueConverter valueConverter;
35:
36: AxiomSaver(Connector connector, ValueFactory valueFactory, String language) {
37: this.connector = connector;
38: this.valueFactory = valueFactory;
39: this.valueConverter = new SesameValueConverter(valueFactory, language);
40: }
41:
42: void persistAxioms(AxiomValueDescriptor axiomDescriptor) throws SesameDriverException {
43: final List<Statement> statements = new ArrayList<>();
44:• for (Assertion assertion : axiomDescriptor.getAssertions()) {
45: statements.addAll(createSesameStatements(axiomDescriptor.getSubject(), assertion,
46: axiomDescriptor.getAssertionValues(assertion),
47: axiomDescriptor.getAssertionContext(assertion)));
48: }
49:• if (!statements.isEmpty()) {
50: connector.addStatements(statements);
51: }
52: }
53:
54: void persistAxioms(NamedResource subject, Map<Assertion, Set<Value<?>>> values, URI context) throws SesameDriverException {
55: final List<Statement> statements = new ArrayList<>();
56:• for (Map.Entry<Assertion, Set<Value<?>>> entry : values.entrySet()) {
57: statements.addAll(createSesameStatements(subject, entry.getKey(), entry.getValue(), context));
58: }
59:• if (!statements.isEmpty()) {
60: connector.addStatements(statements);
61: }
62: }
63:
64: private Collection<? extends Statement> createSesameStatements(NamedResource subject,
65: Assertion assertion, Collection<Value<?>> assertionValues, URI assertionContext)
66: throws SesameDriverException {
67: final List<Statement> statements = new ArrayList<>(assertionValues.size());
68:
69: final org.openrdf.model.Resource subjectUri = SesameUtils.toSesameUri(
70: subject.getIdentifier(), valueFactory);
71: final org.openrdf.model.URI property = SesameUtils.toSesameUri(assertion.getIdentifier(),
72: valueFactory);
73:• final org.openrdf.model.URI context = assertionContext != null ? SesameUtils.toSesameUri(
74: assertionContext, valueFactory) : null;
75:• for (Value<?> val : assertionValues) {
76:• if (val == Value.nullValue()) {
77: continue;
78: }
79: org.openrdf.model.Value value = valueConverter.toSesameValue(assertion, val);
80: statements.add(createStatement(subjectUri, property, value, context));
81: }
82: return statements;
83: }
84:
85: private Statement createStatement(Resource subject, org.openrdf.model.URI property,
86: org.openrdf.model.Value value, org.openrdf.model.URI context) {
87:• if (context != null) {
88: return valueFactory.createStatement(subject, property, value, context);
89: } else {
90: return valueFactory.createStatement(subject, property, value);
91: }
92: }
93: }