Skip to content

Package: AxiomBuilder

AxiomBuilder

nameinstructionbranchcomplexitylinemethod
AxiomBuilder(NamedResource, Map, Assertion)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createValue(Assertion.AssertionType, Value)
M: 4 C: 43
91%
M: 2 C: 9
82%
M: 2 C: 6
75%
M: 2 C: 10
83%
M: 0 C: 1
100%
resolveAssertion(URI)
M: 9 C: 25
74%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 7
78%
M: 0 C: 1
100%
resolveValue(Statement, Assertion)
M: 0 C: 21
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 6
100%
M: 0 C: 1
100%
resolveValue(Value)
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%
statementToAxiom(Statement)
M: 2 C: 20
91%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
statementToAxiom(Statement, Assertion)
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
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.util;
16:
17: import cz.cvut.kbss.ontodriver.model.*;
18: import org.openrdf.model.Literal;
19: import org.openrdf.model.Resource;
20: import org.openrdf.model.Statement;
21: import org.openrdf.model.URI;
22:
23: import java.util.Map;
24:
25: public class AxiomBuilder {
26:
27: private final NamedResource subject;
28: private final Map<URI, Assertion> propertyToAssertion;
29:
30: private final Assertion unspecifiedProperty;
31:
32: public AxiomBuilder(NamedResource subject, Map<URI, Assertion> propertyToAssertion, Assertion unspecifiedProperty) {
33: this.subject = subject;
34: this.propertyToAssertion = propertyToAssertion;
35: this.unspecifiedProperty = unspecifiedProperty;
36: }
37:
38: public Axiom<?> statementToAxiom(Statement statement) {
39: Assertion assertion = resolveAssertion(statement.getPredicate());
40:
41: final Value<?> val = resolveValue(statement, assertion);
42:• if (val == null) {
43: return null;
44: }
45: return new AxiomImpl<>(subject, assertion, val);
46: }
47:
48: private Value<?> resolveValue(Statement stmt, Assertion assertion) {
49:• if (assertion == null || SesameUtils.isBlankNode(stmt.getObject())) {
50: return null;
51: }
52: Value<?> val = createValue(assertion.getType(), stmt.getObject());
53:• if (val == null) {
54: return null;
55: }
56: return val;
57: }
58:
59: public Axiom<?> statementToAxiom(Statement statement, Assertion assertion) {
60: final Value<?> val = resolveValue(statement, assertion);
61:• if (val == null) {
62: return null;
63: }
64: return new AxiomImpl<>(subject, assertion, val);
65: }
66:
67: private Assertion resolveAssertion(URI predicate) {
68: Assertion assertion = propertyToAssertion.get(predicate);
69:• if (assertion == null) {
70:• if (unspecifiedProperty != null) {
71: assertion = Assertion
72: .createPropertyAssertion(SesameUtils.toJavaUri(predicate), unspecifiedProperty.isInferred());
73: } else {
74: assertion = null;
75: }
76:• } else if (assertion.getType() == Assertion.AssertionType.PROPERTY) {
77: // If the property was unspecified, create assertion based on the actual property URI
78: assertion = Assertion.createPropertyAssertion(SesameUtils.toJavaUri(predicate), assertion.isInferred());
79: }
80: return assertion;
81: }
82:
83: private Value<?> createValue(Assertion.AssertionType assertionType, org.openrdf.model.Value value) {
84:• switch (assertionType) {
85: case DATA_PROPERTY:
86:• if (!(value instanceof Literal)) {
87: return null;
88: }
89: return new Value<>(SesameUtils.getDataPropertyValue((Literal) value));
90: case CLASS:
91:• if (!(value instanceof Resource)) {
92: return null;
93: }
94: return new Value<>(SesameUtils.toJavaUri((Resource) value));
95: case OBJECT_PROPERTY:
96:• if (!(value instanceof Resource)) {
97: return null;
98: }
99: return new Value<>(NamedResource.create(value.stringValue()));
100: case ANNOTATION_PROPERTY: // Intentional fall-through
101: case PROPERTY:
102: return resolveValue(value);
103: }
104: return null;
105: }
106:
107: private Value<?> resolveValue(org.openrdf.model.Value object) {
108:• if (object instanceof Literal) {
109: return new Value<>(SesameUtils.getDataPropertyValue((Literal) object));
110: } else {
111: return new Value<>(SesameUtils.toJavaUri((Resource) object));
112: }
113: }
114: }