Search in sources :

Example 1 with SemanticTag

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

the class UntypedTagService method getTagsForPackage.

@Override
@RunAsSystem
public Iterable<SemanticTag<Package, LabeledResource, LabeledResource>> getTagsForPackage(Package p) {
    Entity packageEntity = dataService.findOne(PACKAGE, new QueryImpl<>().eq(PackageMetadata.ID, p.getId()));
    if (packageEntity == null) {
        throw new UnknownEntityException("Unknown package [" + p.getId() + "]");
    }
    List<SemanticTag<Package, LabeledResource, LabeledResource>> tags = Lists.newArrayList();
    for (Entity tagEntity : packageEntity.getEntities(PackageMetadata.TAGS)) {
        tags.add(SemanticTag.asTag(p, tagEntity));
    }
    return tags;
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) UnknownEntityException(org.molgenis.data.UnknownEntityException) SemanticTag(org.molgenis.data.semantic.SemanticTag) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 2 with SemanticTag

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

the class OntologyTagServiceImpl method getTagsForPackage.

@Override
public Iterable<SemanticTag<Package, OntologyTerm, Ontology>> getTagsForPackage(Package package_) {
    Entity packageEntity = dataService.findOneById(PACKAGE, package_.getId());
    if (packageEntity == null) {
        throw new UnknownEntityException("Unknown package [" + package_.getId() + "]");
    }
    List<SemanticTag<Package, OntologyTerm, Ontology>> tags = Lists.newArrayList();
    for (Entity tagEntity : packageEntity.getEntities(PackageMetadata.TAGS)) {
        tags.add(asTag(package_, tagEntity));
    }
    return tags;
}
Also used : Entity(org.molgenis.data.Entity) UnknownEntityException(org.molgenis.data.UnknownEntityException) SemanticTag(org.molgenis.data.semantic.SemanticTag)

Example 3 with SemanticTag

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

Example 4 with SemanticTag

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

Example 5 with SemanticTag

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

the class UntypedTagService method getTagsForEntity.

@Override
@RunAsSystem
public Iterable<SemanticTag<EntityType, LabeledResource, LabeledResource>> getTagsForEntity(EntityType entityType) {
    List<SemanticTag<EntityType, LabeledResource, LabeledResource>> result = new ArrayList<>();
    Entity entity = findEntity(entityType);
    if (entity == null) {
        LOG.warn("No known entity with name " + entityType.getId() + ".");
    } else {
        for (Entity tagEntity : entity.getEntities(EntityTypeMetadata.TAGS)) {
            result.add(SemanticTag.asTag(entityType, tagEntity));
        }
    }
    return result;
}
Also used : Entity(org.molgenis.data.Entity) ArrayList(java.util.ArrayList) SemanticTag(org.molgenis.data.semantic.SemanticTag) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

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