Search in sources :

Example 16 with Relation

use of org.molgenis.data.semantic.Relation in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelDATE.

@Test
public void testCreateRfdModelDATE() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    List<Attribute> attributeList = singletonList(attribute);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    LocalDate value = LocalDate.of(2013, Month.AUGUST, 12);
    when(objectEntity.get("attributeName")).thenReturn(value);
    when(objectEntity.getLocalDate("attributeName")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute.getName()).thenReturn("attributeName");
    when(attribute.getDataType()).thenReturn(AttributeType.DATE);
    LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label");
    Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag);
    when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
    Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
    assertEquals(result.size(), 1);
    Iterator results = result.iterator();
    assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"2013-08-12\"^^<http://www.w3.org/2001/XMLSchema#date>) [null]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 17 with Relation

use of org.molgenis.data.semantic.Relation in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelDATETIME.

@Test
public void testCreateRfdModelDATETIME() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    List<Attribute> attributeList = singletonList(attribute);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    Instant value = Instant.parse("2011-12-03T10:15:30Z");
    when(objectEntity.get("attributeName")).thenReturn(value);
    when(objectEntity.getInstant("attributeName")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute.getName()).thenReturn("attributeName");
    when(attribute.getDataType()).thenReturn(AttributeType.DATE_TIME);
    LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label");
    Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag);
    when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
    Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
    assertEquals(result.size(), 1);
    Iterator results = result.iterator();
    assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"2011-12-03T10:15:30Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>) [null]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute) Instant(java.time.Instant) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 18 with Relation

use of org.molgenis.data.semantic.Relation in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelBOOL.

@Test
public void testCreateRfdModelBOOL() {
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    List<Attribute> attributeList = singletonList(attribute);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    when(objectEntity.get("attributeName")).thenReturn(true);
    when(objectEntity.getBoolean("attributeName")).thenReturn(true);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute.getName()).thenReturn("attributeName");
    when(attribute.getDataType()).thenReturn(AttributeType.BOOL);
    LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label");
    Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag);
    when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
    Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
    assertEquals(result.size(), 1);
    Iterator results = result.iterator();
    assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>) [null]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 19 with Relation

use of org.molgenis.data.semantic.Relation in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelIntAttribute.

@Test
public void testCreateRfdModelIntAttribute() {
    List<Attribute> attributeList = singletonList(attr2);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    when(objectEntity.get("attributeName2")).thenReturn(2);
    when(objectEntity.getInt("attributeName2")).thenReturn(2);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attr2.getName()).thenReturn("attributeName2");
    when(attr2.getDataType()).thenReturn(AttributeType.INT);
    LabeledResource tag2 = new LabeledResource("http://IRI2.nl", "tag2Label");
    Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2);
    when(tagService.getTagsForAttribute(entityType, attr2)).thenReturn(tags2);
    Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
    assertEquals(result.size(), 1);
    Iterator results = result.iterator();
    assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI2.nl, \"2\"^^<http://www.w3.org/2001/XMLSchema#int>) [null]");
}
Also used : Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 20 with Relation

use of org.molgenis.data.semantic.Relation in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated.

@Test
public void testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute1 = attrMetaFactory.create().setName("sourceHeight1");
    sourceAttribute1.setDescription("height");
    Attribute sourceAttribute2 = attrMetaFactory.create().setName("sourceHeight2");
    sourceAttribute2.setDescription("height");
    sourceEntityType.addAttributes(Arrays.asList(sourceAttribute1, sourceAttribute2));
    User owner = userFactory.create();
    owner.setUsername("flup");
    owner.setPassword("geheim");
    owner.setId("12345");
    owner.setActive(true);
    owner.setEmail("flup@blah.com");
    owner.setFirstName("Flup");
    owner.setLastName("de Flap");
    MappingProject project = new MappingProject("project", owner);
    project.addTarget(targetEntityType);
    EntityMapping mapping = project.getMappingTarget("target").addSource(sourceEntityType);
    Map<Attribute, ExplainedAttribute> mappings = ImmutableMap.of(sourceAttribute1, ExplainedAttribute.create(sourceAttribute1), sourceAttribute2, ExplainedAttribute.create(sourceAttribute2));
    LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
    when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(mappings);
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertEquals(mapping.getAttributeMapping("targetHeight").getSourceAttributes().get(0), sourceAttribute1);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Relation(org.molgenis.data.semantic.Relation) User(org.molgenis.data.security.auth.User) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Relation (org.molgenis.data.semantic.Relation)22 Attribute (org.molgenis.data.meta.model.Attribute)15 Test (org.testng.annotations.Test)15 LabeledResource (org.molgenis.data.semantic.LabeledResource)12 Model (org.eclipse.rdf4j.model.Model)11 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)11 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)11 Iterator (java.util.Iterator)10 EntityType (org.molgenis.data.meta.model.EntityType)10 Entity (org.molgenis.data.Entity)9 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)9 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)4 User (org.molgenis.data.security.auth.User)2 SemanticTag (org.molgenis.data.semantic.SemanticTag)2 Ontology (org.molgenis.ontology.core.model.Ontology)2 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)2 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)2 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)2 Instant (java.time.Instant)1