Search in sources :

Example 6 with SemanticTag

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

the class UntypedTagService method addEntityTag.

@Override
public void addEntityTag(SemanticTag<EntityType, LabeledResource, LabeledResource> tag) {
    Entity entity = findEntity(tag.getSubject());
    if (entity == null) {
        throw new UnknownEntityException("Unknown entity [" + tag.getSubject().getId() + "]");
    }
    ImmutableList<SemanticTag<EntityType, LabeledResource, LabeledResource>> existingTags = ImmutableList.copyOf(getTagsForEntity(tag.getSubject()));
    if (existingTags.contains(tag)) {
        LOG.debug("Tag already present");
        return;
    }
    ImmutableList.Builder<Entity> builder = ImmutableList.builder();
    builder.addAll(entity.getEntities(EntityTypeMetadata.TAGS));
    builder.add(getTagEntity(tag));
    entity.set(EntityTypeMetadata.TAGS, builder.build());
    dataService.update(ENTITY_TYPE_META_DATA, entity);
}
Also used : Entity(org.molgenis.data.Entity) ImmutableList(com.google.common.collect.ImmutableList) UnknownEntityException(org.molgenis.data.UnknownEntityException) SemanticTag(org.molgenis.data.semantic.SemanticTag)

Example 7 with SemanticTag

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

the class OntologyTagServiceTest method testGetTagEntity.

@Test
public void testGetTagEntity() {
    Tag expected = tagFactory.create();
    expected.set(TagMetadata.ID, "1233");
    expected.set(TagMetadata.OBJECT_IRI, "http://edamontology.org/data_3031");
    expected.set(TagMetadata.LABEL, "Core data");
    expected.set(TagMetadata.RELATION_IRI, "http://molgenis.org/biobankconnect/instanceOf");
    expected.set(TagMetadata.RELATION_LABEL, "instanceOf");
    expected.set(TagMetadata.CODE_SYSTEM, "http://edamontology.org");
    OntologyTerm coreData = mock(OntologyTerm.class);
    when(coreData.getIRI()).thenReturn("http://edamontology.org/data_3031");
    when(coreData.getLabel()).thenReturn("Core data");
    Ontology edamOntology = mock(Ontology.class);
    when(edamOntology.getIRI()).thenReturn("http://edamontology.org");
    SemanticTag<Object, OntologyTerm, Ontology> tag = new SemanticTag<>("1233", null, Relation.instanceOf, coreData, edamOntology);
    when(tagRepository.getTagEntity("http://edamontology.org/data_3031", "Core data", Relation.instanceOf, "http://edamontology.org")).thenReturn(expected);
    assertEquals(ontologyTagService.getTagEntity(tag), expected);
}
Also used : Ontology(org.molgenis.ontology.core.model.Ontology) SemanticTag(org.molgenis.data.semantic.SemanticTag) OntologyTag(org.molgenis.semanticsearch.semantic.OntologyTag) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) SemanticTag(org.molgenis.data.semantic.SemanticTag) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 8 with SemanticTag

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

the class OntologyTagServiceTest method testGetTagsForPackage.

@Test
public void testGetTagsForPackage() {
    Package p = packageFactory.create("test", "desc");
    Package pack = packageFactory.create();
    pack.setTags(singletonList(chromosomeNameTagEntity));
    when(ontologyService.getOntology("http://edamontology.org")).thenReturn(EDAM_ONTOLOGY);
    when(ontologyService.getOntologyTerm("http://edamontology.org/data_0987")).thenReturn(CHROMOSOME_NAME_ONTOLOGY_TERM);
    when(dataService.findOneById(PACKAGE, "test")).thenReturn(pack);
    assertEquals(ontologyTagService.getTagsForPackage(p), singletonList(new SemanticTag<>("1234", p, Relation.forIRI("http://molgenis.org/biobankconnect/instanceOf"), OntologyTerm.create("http://edamontology.org/data_0987", "Chromosome name", "Name of a chromosome."), Ontology.create("EDAM", "http://edamontology.org", "The EDAM ontology."))));
}
Also used : Package(org.molgenis.data.meta.model.Package) SemanticTag(org.molgenis.data.semantic.SemanticTag) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

SemanticTag (org.molgenis.data.semantic.SemanticTag)8 Entity (org.molgenis.data.Entity)4 UnknownEntityException (org.molgenis.data.UnknownEntityException)3 Test (org.testng.annotations.Test)3 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)2 Ontology (org.molgenis.ontology.core.model.Ontology)2 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)2 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Model (org.eclipse.rdf4j.model.Model)1 Resource (org.eclipse.rdf4j.model.Resource)1 Statement (org.eclipse.rdf4j.model.Statement)1 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)1 EntityType (org.molgenis.data.meta.model.EntityType)1 Package (org.molgenis.data.meta.model.Package)1 LabeledResource (org.molgenis.data.semantic.LabeledResource)1 Relation (org.molgenis.data.semantic.Relation)1 QueryImpl (org.molgenis.data.support.QueryImpl)1 OntologyTag (org.molgenis.semanticsearch.semantic.OntologyTag)1