EntityDeconstructor { <T> AxiomValueGatherer mapFieldToAxioms(URI primaryKey, T entity, Field field, EntityType<T> et, Descriptor descriptor) { final FieldSpecification<? super T, ?> fieldSpec = et .getFieldSpecification(field.getName()); final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(primaryKey, descriptor); try { addAssertions(entity, et, fieldSpec, descriptor, valueBuilder); } catch (IllegalAccessException e) { throw new EntityDeconstructionException(e); } return valueBuilder; } EntityDeconstructor(ObjectOntologyMapperImpl mapper);   }
@Test void mapsEntityDataPropertyFieldToAxiomDescriptor() throws Exception { final Descriptor aDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut.mapFieldToAxioms(entityA.getUri(), entityA, OWLClassA.getStrAttField(), mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(1, res.getAssertions().size()); assertTrue(containsDPAssertion(res, OWLClassA.getStrAttField(), entityA.getStringAttribute())); }
@Test void mapsEntityDataPropertyWithNullValueToAxiomDescriptor() throws Exception { final Descriptor aDescriptor = new EntityDescriptor(); entityA.setStringAttribute(null); final AxiomValueGatherer builder = sut.mapFieldToAxioms(entityA.getUri(), entityA, OWLClassA.getStrAttField(), mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(1, res.getAssertions().size()); assertTrue(res.getAssertions().contains( Assertion.createDataPropertyAssertion(strAttAIdentifier, mocks.forOwlClassA().stringAttribute().getLanguage(), mocks.forOwlClassA().stringAttribute().isInferred()))); final List<Value<?>> val = res.getAssertionValues(res.getAssertions().iterator().next()); assertEquals(1, val.size()); assertEquals(Value.nullValue(), val.get(0)); assertNull(val.get(0).getValue()); }
@Test void mapsEntityObjectPropertyValueInContextToAxiomDescriptor() throws Exception { final Descriptor dDescriptor = new EntityDescriptor(); dDescriptor.addAttributeContext(OWLClassD.getOwlClassAField(), CONTEXT); when(oomMock.isManaged(entityD.getOwlClassA())).thenReturn(true); final AxiomValueGatherer builder = sut.mapFieldToAxioms(entityD.getUri(), entityD, OWLClassD.getOwlClassAField(), mocks.forOwlClassD().entityType(), dDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(1, res.getAssertions().size()); final Assertion ass = Assertion.createObjectPropertyAssertion(owlClassAAttIdentifier, mocks.forOwlClassD().owlClassAAtt().isInferred()); assertEquals(CONTEXT, res.getAssertionContext(ass)); assertTrue( containsOPAssertion(res, OWLClassD.getOwlClassAField(), NamedResource.create(entityA.getUri()))); }
@Test void mapsEntityObjectPropertyAssertionToSubjectContextWhenAssertionsInSubjectContextAreConfigured() throws Exception { final URI subjectContext = Generators.createIndividualIdentifier(); final Descriptor dDescriptor = new EntityDescriptor(subjectContext); final Descriptor aDescriptor = new EntityDescriptor(CONTEXT); dDescriptor.addAttributeDescriptor(OWLClassD.getOwlClassAField(), aDescriptor); when(oomMock.isManaged(entityD.getOwlClassA())).thenReturn(true); final AxiomValueGatherer builder = sut.mapFieldToAxioms(entityD.getUri(), entityD, OWLClassD.getOwlClassAField(), mocks.forOwlClassD().entityType(), dDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(1, res.getAssertions().size()); final Assertion ass = Assertion.createObjectPropertyAssertion(owlClassAAttIdentifier, mocks.forOwlClassD().owlClassAAtt().isInferred()); assertEquals(subjectContext, res.getAssertionContext(ass)); }
@Test void mapFieldToAxiomsMapsSimpleLiteralFieldToAxiomWithAssertionWithoutLanguageTag() throws Exception { final String value = "test"; entityM.setSimpleLiteral(value); final AxiomValueGatherer builder = sut .mapFieldToAxioms(URI.create(entityM.getKey()), entityM, OWLClassM.getSimpleLiteralField(), mocks.forOwlClassM().entityType(), new EntityDescriptor()); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(1, res.getAssertions().size()); final Assertion a = res.getAssertions().iterator().next(); assertEquals(Vocabulary.p_m_simpleLiteral, a.getIdentifier().toString()); assertFalse(a.hasLanguage()); assertEquals(value, res.getAssertionValues(a).get(0).getValue()); }