Search in sources :

Example 6 with Relation

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

the class EntityModelWriterTest method testCreateRfdModelNullValuePlusHyperlink.

@Test
public void testCreateRfdModelNullValuePlusHyperlink() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute1 = mock(Attribute.class);
    Attribute attribute2 = mock(Attribute.class);
    List<Attribute> attributeList = Arrays.asList(attribute1, attribute2);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    when(objectEntity.get("attribute1Name")).thenReturn(null);
    String value = "http://molgenis.org/index.html";
    doReturn(value).when(objectEntity).get("attribute2Name");
    when(objectEntity.getString("attribute2Name")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute1.getName()).thenReturn("attribute1Name");
    when(attribute2.getName()).thenReturn("attribute2Name");
    when(attribute2.getDataType()).thenReturn(AttributeType.HYPERLINK);
    LabeledResource tag2 = new LabeledResource("http://IRI1.nl", "tag1 label");
    Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2);
    doReturn(tags2).when(tagService).getTagsForAttribute(entityType, attribute2);
    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://IRI1.nl, http://molgenis.org/index.html) [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 7 with Relation

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

the class AlgorithmServiceImplIT method testCreateAttributeMappingIfOnlyOneMatch.

@Test
public void testCreateAttributeMappingIfOnlyOneMatch() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDescription("height");
    sourceEntityType.addAttribute(sourceAttribute);
    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> matches = ImmutableMap.of(sourceAttribute, ExplainedAttribute.create(sourceAttribute, singletonList(ExplainedQueryString.create("height", "height", "height", 100)), true));
    LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
    when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(matches);
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertEquals(mapping.getAttributeMapping("targetHeight").getAlgorithm(), "$('sourceHeight').value();");
}
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)

Example 8 with Relation

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

the class TagValidator method validate.

/**
 * Validates tag
 *
 * @param tag tag
 * @throws MolgenisValidationException if tag is not valid
 */
@SuppressWarnings("MethodMayBeStatic")
public void validate(Tag tag) {
    String relationIri = tag.getRelationIri();
    Relation relation = Relation.forIRI(relationIri);
    if (relation == null) {
        throw new MolgenisValidationException(new ConstraintViolation(format("Unknown relation IRI [%s]", relationIri)));
    }
}
Also used : Relation(org.molgenis.data.semantic.Relation) ConstraintViolation(org.molgenis.data.validation.ConstraintViolation) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException)

Example 9 with Relation

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

the class UntypedTagService method getTagsForAttribute.

@Override
@RunAsSystem
public Multimap<Relation, LabeledResource> getTagsForAttribute(EntityType entityType, Attribute attribute) {
    Entity entity = findAttributeEntity(entityType, attribute.getName());
    if (entity == null)
        return ArrayListMultimap.create();
    Multimap<Relation, LabeledResource> tags = ArrayListMultimap.create();
    for (Entity tagEntity : entity.getEntities(AttributeMetadata.TAGS)) {
        SemanticTag<Attribute, LabeledResource, LabeledResource> tag = SemanticTag.asTag(attribute, tagEntity);
        tags.put(tag.getRelation(), tag.getObject());
    }
    return tags;
}
Also used : Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 10 with Relation

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

the class OntologyTagServiceImpl method asTag.

private <SubjectType> SemanticTag<SubjectType, OntologyTerm, Ontology> asTag(SubjectType subjectType, Entity tagEntity) {
    String identifier = tagEntity.getString(TagMetadata.ID);
    Relation relation = asRelation(tagEntity);
    Ontology ontology = asOntology(tagEntity);
    OntologyTerm ontologyTerm = asOntologyTerm(tagEntity);
    if (relation == null || ontologyTerm == null) {
        return null;
    }
    return new SemanticTag<>(identifier, subjectType, relation, ontologyTerm, ontology);
}
Also used : Relation(org.molgenis.data.semantic.Relation) Ontology(org.molgenis.ontology.core.model.Ontology) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) SemanticTag(org.molgenis.data.semantic.SemanticTag)

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