Search in sources :

Example 1 with TermFrequencyMetaData

use of org.molgenis.ontology.core.ic.TermFrequencyMetaData in project molgenis by molgenis.

the class OntologyTermFrequencyServiceImpl method addEntry.

private Entity addEntry(String term, PubMedTFEntity pubMedTFEntity, DataService dataService) {
    if (pubMedTFEntity == null)
        return null;
    // FIXME remove reference to getApplicationContext
    TermFrequencyMetaData termFrequencyEntityType = getApplicationContext().getBean(TermFrequencyMetaData.class);
    Entity entity = new DynamicEntity(termFrequencyEntityType);
    entity.set(TERM, term);
    entity.set(FREQUENCY, pubMedTFEntity.getFrequency());
    entity.set(OCCURRENCE, pubMedTFEntity.getOccurrence());
    dataService.add(TERM_FREQUENCY, entity);
    return entity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) TermFrequencyMetaData(org.molgenis.ontology.core.ic.TermFrequencyMetaData) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 2 with TermFrequencyMetaData

use of org.molgenis.ontology.core.ic.TermFrequencyMetaData in project molgenis by molgenis.

the class OntologyTermFrequencyServiceImpl method updateTermFrequency.

@Override
@Async
@RunAsSystem
public void updateTermFrequency() {
    // Remove all the existing term frequency records
    dataService.deleteAll(TERM_FREQUENCY);
    List<Entity> entitiesToAdd = new ArrayList<>();
    // Create new term frequency records
    dataService.findAll(ONTOLOGY_TERM_SYNONYM).forEach(entity -> {
        String ontologyTermSynonym = entity.getString(OntologyTermSynonymMetaData.ONTOLOGY_TERM_SYNONYM_ATTR);
        PubMedTFEntity pubMedTFEntity = pubMedTermFrequencyService.getTermFrequency(ontologyTermSynonym);
        if (pubMedTFEntity != null) {
            // FIXME remove reference to getApplicationContext
            TermFrequencyMetaData termFrequencyEntityType = getApplicationContext().getBean(TermFrequencyMetaData.class);
            Entity mapEntity = new DynamicEntity(termFrequencyEntityType);
            mapEntity.set(TERM, ontologyTermSynonym);
            mapEntity.set(FREQUENCY, pubMedTFEntity.getFrequency());
            mapEntity.set(OCCURRENCE, pubMedTFEntity.getOccurrence());
            entitiesToAdd.add(mapEntity);
            if (entitiesToAdd.size() > BATCH_SIZE) {
                dataService.add(TERM_FREQUENCY, entitiesToAdd.stream());
                entitiesToAdd.clear();
            }
        }
    });
    if (!entitiesToAdd.isEmpty()) {
        dataService.add(TERM_FREQUENCY, entitiesToAdd.stream());
    }
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) TermFrequencyMetaData(org.molgenis.ontology.core.ic.TermFrequencyMetaData) DynamicEntity(org.molgenis.data.support.DynamicEntity) ArrayList(java.util.ArrayList) Async(org.springframework.scheduling.annotation.Async) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Aggregations

Entity (org.molgenis.data.Entity)2 DynamicEntity (org.molgenis.data.support.DynamicEntity)2 TermFrequencyMetaData (org.molgenis.ontology.core.ic.TermFrequencyMetaData)2 ArrayList (java.util.ArrayList)1 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)1 Async (org.springframework.scheduling.annotation.Async)1