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, Value)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$statementToAxiom$0(Assertion, Value)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
resolveAssertion(IRI)
M: 6 C: 25
81%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 7
88%
M: 0 C: 1
100%
resolveValue(Statement, Assertion)
M: 0 C: 13
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 3
100%
M: 0 C: 1
100%
statementToAxiom(Statement)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
statementToAxiom(Statement, Assertion)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j.util;
19:
20: import cz.cvut.kbss.ontodriver.model.*;
21: import org.eclipse.rdf4j.model.IRI;
22: import org.eclipse.rdf4j.model.Statement;
23:
24: import java.util.Map;
25: import java.util.Optional;
26:
27: public class AxiomBuilder {
28:
29: private final NamedResource subject;
30: private final Map<IRI, Assertion> propertyToAssertion;
31:
32: private final Assertion unspecifiedProperty;
33:
34: public AxiomBuilder(NamedResource subject, Map<IRI, Assertion> propertyToAssertion, Assertion unspecifiedProperty) {
35: this.subject = subject;
36: this.propertyToAssertion = propertyToAssertion;
37: this.unspecifiedProperty = unspecifiedProperty;
38: }
39:
40: public Axiom<?> statementToAxiom(Statement statement) {
41: final Assertion assertion = resolveAssertion(statement.getPredicate());
42:
43: return statementToAxiom(statement, assertion);
44: }
45:
46: private static Optional<Value<?>> resolveValue(Statement stmt, Assertion assertion) {
47:• if (assertion == null || Rdf4jUtils.isBlankNode(stmt.getObject())) {
48: return Optional.empty();
49: }
50: return createValue(assertion, stmt.getObject());
51: }
52:
53: public Axiom<?> statementToAxiom(Statement statement, Assertion assertion) {
54: final Optional<Value<?>> val = resolveValue(statement, assertion);
55: return val.map(v -> new AxiomImpl<>(subject, assertion, v)).orElse(null);
56: }
57:
58: private Assertion resolveAssertion(IRI predicate) {
59: Assertion assertion = propertyToAssertion.get(predicate);
60:• if (assertion == null) {
61:• if (unspecifiedProperty != null) {
62: assertion = Assertion
63: .createPropertyAssertion(Rdf4jUtils.toJavaUri(predicate), unspecifiedProperty.isInferred());
64: }
65:• } else if (assertion.getType() == Assertion.AssertionType.PROPERTY) {
66: // If the property was unspecified, create assertion based on the actual property URI
67: assertion = Assertion.createPropertyAssertion(Rdf4jUtils.toJavaUri(predicate), assertion.isInferred());
68: }
69: return assertion;
70: }
71:
72: private static Optional<Value<?>> createValue(Assertion assertion, org.eclipse.rdf4j.model.Value value) {
73: return ValueConverter.fromRdf4jValue(assertion, value).map(Value::new);
74: }
75: }