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