Skip to content

Method: addValueFromAxiom(Axiom)

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.ontodriver.descriptor.SimpleListDescriptor;
21: import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptorImpl;
22: import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor;
23: import cz.cvut.kbss.ontodriver.model.Assertion;
24: import cz.cvut.kbss.ontodriver.model.Axiom;
25: import cz.cvut.kbss.ontodriver.model.NamedResource;
26:
27: import java.util.Collection;
28: import java.util.List;
29:
30: class SimpleListPropertyStrategy<X> extends
31: ListPropertyStrategy<SimpleListDescriptor, SimpleListValueDescriptor, X> {
32:
33: public SimpleListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att,
34: Descriptor descriptor, EntityMappingHelper mapper) {
35: super(et, att, descriptor, mapper);
36: }
37:
38: @Override
39: void addValueFromAxiom(Axiom<?> ax) {
40: final SimpleListDescriptor listDescriptor = createListDescriptor(ax);
41: final Collection<Axiom<NamedResource>> sequence = mapper.loadSimpleList(listDescriptor);
42: sequence.forEach(super::addValueFromAxiom);
43: }
44:
45: @Override
46: SimpleListDescriptor createListDescriptor(Axiom<?> ax) {
47: final NamedResource owner = ax.getSubject();
48: final Assertion listProperty = Assertion.createObjectPropertyAssertion(listAttribute
49: .getIRI().toURI(), listAttribute.isInferred());
50: final Assertion nextNodeProperty = Assertion.createObjectPropertyAssertion(listAttribute
51: .getOWLObjectPropertyHasNextIRI().toURI(), listAttribute.isInferred());
52: final SimpleListDescriptor listDescriptor = new SimpleListDescriptorImpl(owner,
53: listProperty, nextNodeProperty);
54: listDescriptor.setContext(getAttributeContext());
55: return listDescriptor;
56: }
57:
58: @Override
59: <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder) {
60: final SimpleListValueDescriptor listDescriptor = createListValueDescriptor(instance);
61: addListElementsToListValueDescriptor(listDescriptor, list);
62: valueBuilder.addSimpleListValues(listDescriptor);
63: }
64:
65: @Override
66: SimpleListValueDescriptor createListValueDescriptor(X instance) {
67: final NamedResource owner = NamedResource.create(resolveValueIdentifier(instance, et));
68: final Assertion listProperty = Assertion
69: .createObjectPropertyAssertion(listAttribute.getIRI().toURI(), listAttribute.isInferred());
70: final Assertion nextNodeProperty = Assertion.createObjectPropertyAssertion(listAttribute
71: .getOWLObjectPropertyHasNextIRI().toURI(), listAttribute.isInferred());
72: final SimpleListValueDescriptor listDescriptor = new SimpleListValueDescriptor(owner,
73: listProperty, nextNodeProperty);
74: listDescriptor.setContext(getAttributeContext());
75: return listDescriptor;
76: }
77: }