Skip to content

Package: SesameValueConverter

SesameValueConverter

nameinstructionbranchcomplexitylinemethod
SesameValueConverter(ValueFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getValueAsSesameUri(Value)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
language(Assertion)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
resolvePropertyValue(Assertion, Value)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
toSesameValue(Assertion, Value)
M: 13 C: 23
64%
M: 1 C: 3
75%
M: 1 C: 3
75%
M: 1 C: 4
80%
M: 0 C: 1
100%

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.sesame;
16:
17: import cz.cvut.kbss.ontodriver.model.Assertion;
18: import cz.cvut.kbss.ontodriver.sesame.config.Constants;
19: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
20: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
21: import org.eclipse.rdf4j.model.IRI;
22: import org.eclipse.rdf4j.model.Value;
23: import org.eclipse.rdf4j.model.ValueFactory;
24:
25: class SesameValueConverter {
26:
27: private final ValueFactory vf;
28:
29: SesameValueConverter(ValueFactory vf) {
30: this.vf = vf;
31: }
32:
33: Value toSesameValue(Assertion assertion, cz.cvut.kbss.ontodriver.model.Value<?> val) throws SesameDriverException {
34:• switch (assertion.getType()) {
35: case DATA_PROPERTY:
36: return SesameUtils.createLiteral(val.getValue(), language(assertion), vf);
37: case CLASS:
38: case OBJECT_PROPERTY:
39: return getValueAsSesameUri(val);
40: case ANNOTATION_PROPERTY: // Intentional fall-through
41: case PROPERTY:
42: return resolvePropertyValue(assertion, val);
43: default:
44: // Failsafe
45: throw new IllegalArgumentException("Unsupported assertion type " + assertion.getType());
46: }
47: }
48:
49: private static String language(Assertion assertion) {
50:• return assertion.hasLanguage() ? assertion.getLanguage() : Constants.DEFAULT_LANG;
51: }
52:
53: private IRI getValueAsSesameUri(cz.cvut.kbss.ontodriver.model.Value<?> val) throws SesameDriverException {
54: try {
55: return vf.createIRI(val.getValue().toString());
56: } catch (IllegalArgumentException e) {
57: throw new SesameDriverException(e);
58: }
59: }
60:
61: private Value resolvePropertyValue(Assertion assertion, cz.cvut.kbss.ontodriver.model.Value<?> val) {
62:• if (SesameUtils.isResourceIdentifier(val.getValue())) {
63: return vf.createIRI(val.getValue().toString());
64: } else {
65: return SesameUtils.createLiteral(val.getValue(), language(assertion), vf);
66: }
67: }
68: }