Skip to content

Package: SesameValueConverter

SesameValueConverter

nameinstructionbranchcomplexitylinemethod
SesameValueConverter(ValueFactory, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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%
resolvePropertyValue(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: 22
63%
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) 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.exceptions.SesameDriverException;
18: import cz.cvut.kbss.ontodriver.model.Assertion;
19: import org.openrdf.model.Value;
20: import org.openrdf.model.ValueFactory;
21:
22: class SesameValueConverter {
23:
24: private ValueFactory vf;
25: private String language;
26:
27: SesameValueConverter(ValueFactory vf, String language) {
28: this.vf = vf;
29: this.language = language;
30: }
31:
32: Value toSesameValue(Assertion assertion, cz.cvut.kbss.ontodriver.model.Value<?> val)
33: throws SesameDriverException {
34:• switch (assertion.getType()) {
35: case DATA_PROPERTY:
36: return SesameUtils.createDataPropertyLiteral(val.getValue(), language, 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(val);
43: default:
44: // Failsafe
45: throw new IllegalArgumentException("Unsupported assertion type " + assertion.getType());
46: }
47: }
48:
49: private org.openrdf.model.URI getValueAsSesameUri(cz.cvut.kbss.ontodriver.model.Value<?> val)
50: throws SesameDriverException {
51: try {
52: return vf.createURI(val.getValue().toString());
53: } catch (IllegalArgumentException e) {
54: throw new SesameDriverException(e);
55: }
56: }
57:
58: private org.openrdf.model.Value resolvePropertyValue(cz.cvut.kbss.ontodriver.model.Value<?> val) {
59:• if (SesameUtils.isResourceIdentifier(val.getValue())) {
60: return vf.createURI(val.getValue().toString());
61: } else {
62: return SesameUtils.createDataPropertyLiteral(val.getValue(), language, vf);
63: }
64: }
65: }