Search in sources :

Example 6 with LabeledResource

use of org.molgenis.data.semantic.LabeledResource 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 LabeledResource

use of org.molgenis.data.semantic.LabeledResource 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 8 with LabeledResource

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

the class EntityModelWriter method addStatementsForAttributeTags.

private void addStatementsForAttributeTags(Entity objectEntity, Model model, Resource subject, EntityType entityType) {
    for (Attribute objectAttribute : entityType.getAtomicAttributes()) {
        Object value = objectEntity.get(objectAttribute.getName());
        if (value == null) {
            continue;
        }
        for (LabeledResource tag : tagService.getTagsForAttribute(entityType, objectAttribute).get(Relation.isAssociatedWith)) {
            IRI predicate = valueFactory.createIRI(tag.getIri());
            addRelationForAttribute(model, subject, predicate, objectEntity, objectAttribute);
        }
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute)

Example 9 with LabeledResource

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

the class EntityModelWriter method addStatementsForEntityTags.

void addStatementsForEntityTags(Model model, Resource subject, EntityType entityType) {
    for (SemanticTag<EntityType, LabeledResource, LabeledResource> tag : tagService.getTagsForEntity(entityType)) {
        if (tag.getRelation() == Relation.isAssociatedWith) {
            LabeledResource object = tag.getObject();
            model.add(subject, rdfTypePredicate, valueFactory.createIRI(object.getIri()));
        }
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) LabeledResource(org.molgenis.data.semantic.LabeledResource)

Example 10 with LabeledResource

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

the class EntityModelWriterTest method testAddStatementsForEntityType.

@Test
public void testAddStatementsForEntityType() {
    Model model = new LinkedHashModel();
    Resource subject = valueFactory.createIRI("http://example.org/subject");
    LabeledResource object = new LabeledResource("http://example.org/object", "object");
    LabeledResource codeSystem = new LabeledResource("ex:object");
    SemanticTag<EntityType, LabeledResource, LabeledResource> tag = new SemanticTag<>("tagId", entityType, Relation.isAssociatedWith, object, codeSystem);
    when(tagService.getTagsForEntity(entityType)).thenReturn(singletonList(tag));
    writer.addStatementsForEntityTags(model, subject, entityType);
    Statement statement = valueFactory.createStatement(subject, TYPE, valueFactory.createIRI("http://example.org/object"));
    assertEquals(newArrayList(model), singletonList(statement));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) LabeledResource(org.molgenis.data.semantic.LabeledResource) Statement(org.eclipse.rdf4j.model.Statement) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Resource(org.eclipse.rdf4j.model.Resource) LabeledResource(org.molgenis.data.semantic.LabeledResource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) SemanticTag(org.molgenis.data.semantic.SemanticTag) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

LabeledResource (org.molgenis.data.semantic.LabeledResource)16 Model (org.eclipse.rdf4j.model.Model)12 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)12 Attribute (org.molgenis.data.meta.model.Attribute)12 Relation (org.molgenis.data.semantic.Relation)12 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)12 Test (org.testng.annotations.Test)12 Iterator (java.util.Iterator)10 Entity (org.molgenis.data.Entity)9 EntityType (org.molgenis.data.meta.model.EntityType)9 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 IRI (org.eclipse.rdf4j.model.IRI)1 Resource (org.eclipse.rdf4j.model.Resource)1 Statement (org.eclipse.rdf4j.model.Statement)1 SemanticTag (org.molgenis.data.semantic.SemanticTag)1 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)1