Skip to content

Package: ReferencedListPropertyStrategy

ReferencedListPropertyStrategy

nameinstructionbranchcomplexitylinemethod
ReferencedListPropertyStrategy(EntityType, ListAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createListDescriptor(Axiom)
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
createListValueDescriptor(Object)
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
extractListValues(List, Object, AxiomValueGatherer)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$addValueFromAxiom$0(Axiom)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$addValueFromAxiom$1(Axiom)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.jopa.oom;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
19: import cz.cvut.kbss.jopa.model.metamodel.ListAttribute;
20: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
21: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
22: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptorImpl;
23: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
24: import cz.cvut.kbss.ontodriver.model.Assertion;
25: import cz.cvut.kbss.ontodriver.model.Axiom;
26: import cz.cvut.kbss.ontodriver.model.NamedResource;
27:
28: import java.net.URI;
29: import java.util.Collection;
30: import java.util.List;
31:
32: class ReferencedListPropertyStrategy<X> extends
33: ListPropertyStrategy<ReferencedListDescriptor, ReferencedListValueDescriptor, X> {
34:
35: public ReferencedListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att,
36: Descriptor descriptor, EntityMappingHelper mapper) {
37: super(et, att, descriptor, mapper);
38: }
39:
40: @Override
41: void addValueFromAxiom(Axiom<?> ax) {
42: final ReferencedListDescriptor listDescriptor = createListDescriptor(ax);
43: final Collection<Axiom<NamedResource>> sequence = mapper.loadReferencedList(listDescriptor);
44: sequence.stream().filter(a -> a.getAssertion().getIdentifier()
45: .equals(listAttribute.getOWLPropertyHasContentsIRI().toURI()))
46: .forEach(super::addValueFromAxiom);
47: }
48:
49: @Override
50: ReferencedListDescriptor createListDescriptor(Axiom<?> ax) {
51: final NamedResource owner = ax.getSubject();
52:
53: final boolean inferred = listAttribute.isInferred();
54: final Assertion listProperty = Assertion.createObjectPropertyAssertion(listAttribute
55: .getIRI().toURI(), inferred);
56: final Assertion nextNodeProperty = Assertion.createObjectPropertyAssertion(listAttribute
57: .getOWLObjectPropertyHasNextIRI().toURI(), inferred);
58: final Assertion nodeContentProperty = Assertion.createObjectPropertyAssertion(listAttribute
59: .getOWLPropertyHasContentsIRI().toURI(), inferred);
60: final ReferencedListDescriptor listDescriptor = new ReferencedListDescriptorImpl(owner,
61: listProperty, nextNodeProperty, nodeContentProperty);
62: listDescriptor.setContext(getAttributeContext());
63: return listDescriptor;
64: }
65:
66: @Override
67: <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder) {
68: final ReferencedListValueDescriptor listDescriptor = createListValueDescriptor(instance);
69: addListElementsToListValueDescriptor(listDescriptor, list);
70: valueBuilder.addReferencedListValues(listDescriptor);
71: }
72:
73: @Override
74: ReferencedListValueDescriptor createListValueDescriptor(X instance) {
75: final URI owner = EntityPropertiesUtils.getPrimaryKey(instance, et);
76: final Assertion hasList = Assertion
77: .createObjectPropertyAssertion(listAttribute.getIRI().toURI(), listAttribute.isInferred());
78: final Assertion hasNext = Assertion.createObjectPropertyAssertion(listAttribute
79: .getOWLObjectPropertyHasNextIRI().toURI(), listAttribute.isInferred());
80: final Assertion hasContent = Assertion.createObjectPropertyAssertion(listAttribute
81: .getOWLPropertyHasContentsIRI().toURI(), listAttribute.isInferred());
82: final ReferencedListValueDescriptor descriptor = new ReferencedListValueDescriptor(
83: NamedResource.create(owner), hasList, hasNext, hasContent);
84: descriptor.setContext(getAttributeContext());
85: return descriptor;
86: }
87: }