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