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]");
}
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;
}
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);
}
}
}
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()));
}
}
}
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));
}
Aggregations