Search in sources :

Example 1 with MatchingTaskContentMetaData

use of org.molgenis.ontology.sorta.meta.MatchingTaskContentMetaData in project molgenis by molgenis.

the class SortaJobProcessor method process.

public void process() {
    RunAsSystemAspect.runAsSystem(() -> {
        long maxCount = dataService.count(inputRepositoryName, new QueryImpl<>());
        progress.status("Matching " + maxCount + " input terms from " + inputRepositoryName + ".\nStoring results in " + resultRepositoryName);
        progress.setProgressMax((int) maxCount);
        // FIXME get rid of getApplicationContext reference
        MatchingTaskContentMetaData matchingTaskContentMetaData = getApplicationContext().getBean(MatchingTaskContentMetaData.class);
        // Match input terms with code
        List<Entity> entitiesToAdd = newArrayList();
        dataService.findAll(inputRepositoryName).forEach(inputRow -> {
            Entity resultEntity = new DynamicEntity(matchingTaskContentMetaData) {

                @Override
                protected void validateValueType(String attrName, Object value) {
                // FIXME enable validation by not overriding this method
                }
            };
            resultEntity.set(MatchingTaskContentMetaData.INPUT_TERM, inputRow);
            resultEntity.set(MatchingTaskContentMetaData.IDENTIFIER, idGenerator.generateId());
            resultEntity.set(MatchingTaskContentMetaData.VALIDATED, false);
            entitiesToAdd.add(resultEntity);
            Iterable<Entity> ontologyTermEntities = sortaService.findOntologyTermEntities(ontologyIri, inputRow);
            if (Iterables.size(ontologyTermEntities) > 0) {
                Entity firstMatchedOntologyTerm = Iterables.getFirst(ontologyTermEntities, new DynamicEntity(matchingTaskContentMetaData));
                resultEntity.set(MatchingTaskContentMetaData.MATCHED_TERM, firstMatchedOntologyTerm.get(OntologyTermMetaData.ONTOLOGY_TERM_IRI));
                resultEntity.set(MatchingTaskContentMetaData.SCORE, firstMatchedOntologyTerm.get(SCORE));
            } else {
                resultEntity.set(MatchingTaskContentMetaData.SCORE, 0.0);
            }
            // Add entity in batch
            if (entitiesToAdd.size() >= ADD_BATCH_SIZE) {
                dataService.add(resultRepositoryName, entitiesToAdd.stream());
                entitiesToAdd.clear();
            }
            // Increase the number of the progress
            counter.incrementAndGet();
            // Update the progress only when the progress proceeds the threshold
            if (counter.get() % PROGRESS_UPDATE_BATCH_SIZE == 0) {
                progress.progress(counter.get(), "Processed " + counter + " input terms.");
            }
        });
        // Add the rest
        if (!entitiesToAdd.isEmpty()) {
            dataService.add(resultRepositoryName, entitiesToAdd.stream());
        }
        progress.progress(counter.get(), "Processed " + counter + " input terms.");
        progress.setResultUrl(menuReaderService.getMenu().findMenuItemPath(SortaController.ID) + "/result/" + resultRepositoryName);
    });
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) MatchingTaskContentMetaData(org.molgenis.ontology.sorta.meta.MatchingTaskContentMetaData)

Aggregations

Entity (org.molgenis.data.Entity)1 DynamicEntity (org.molgenis.data.support.DynamicEntity)1 MatchingTaskContentMetaData (org.molgenis.ontology.sorta.meta.MatchingTaskContentMetaData)1