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