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