Search in sources :

Example 11 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class CsvWriterTest method testLabels.

@Test
public void testLabels() throws IOException {
    StringWriter strWriter = new StringWriter();
    try (CsvWriter csvWriter = new CsvWriter(strWriter)) {
        csvWriter.writeAttributes(Arrays.asList("col1", "col2"), Arrays.asList("label1", "label2"));
        Entity entity = new DynamicEntity(entityType);
        entity.set("col1", "val1");
        entity.set("col2", "val2");
        csvWriter.add(entity);
        assertEquals(strWriter.toString(), "\"label1\",\"label2\"\n\"val1\",\"val2\"\n");
    }
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) StringWriter(java.io.StringWriter) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 12 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class CsvIterator method get.

private Entity get() {
    if (getNext) {
        try {
            String[] values = csvReader.readNext();
            if (values != null && values.length == colNamesMap.size()) {
                List<String> valueList = Arrays.asList(values);
                for (int i = 0; i < values.length; ++i) {
                    // subsequent separators indicate
                    // null
                    // values instead of empty strings
                    String value = values[i].isEmpty() ? null : values[i];
                    values[i] = processCell(value, false);
                }
                next = new DynamicEntity(entityType);
                for (String name : colNamesMap.keySet()) {
                    next.set(name, valueList.get(colNamesMap.get(name)));
                }
            } else if (values != null && (values.length > 1 || (values.length == 1 && values[0].length() > 0)) && values.length < colNamesMap.size()) {
                throw new MolgenisDataException(format("Number of values (%d) doesn't match the number of headers (%d): [%s]", values.length, colNamesMap.size(), stream(values).collect(joining(","))));
            } else {
                next = null;
            }
            getNext = false;
        } catch (IOException e) {
            throw new MolgenisDataException(format("Exception reading line of csv file [%s]", repositoryName), e);
        }
    }
    return next;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 13 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class SortaController method toDownloadRow.

private Entity toDownloadRow(SortaJobExecution sortaJobExecution, Entity resultEntity, EntityType downloadEntityType) {
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    Entity inputEntity = resultEntity.getEntity(MatchingTaskContentMetaData.INPUT_TERM);
    Entity ontologyTermEntity = sortaService.getOntologyTermEntity(resultEntity.getString(MatchingTaskContentMetaData.MATCHED_TERM), sortaJobExecution.getOntologyIri());
    Entity row = new DynamicEntity(downloadEntityType);
    inputEntity.getAttributeNames().forEach(attributeName -> {
        if (!attributeName.equalsIgnoreCase(SortaCsvRepository.ALLOWED_IDENTIFIER)) {
            row.set(attributeName, inputEntity.get(attributeName));
        }
    });
    if (ontologyTermEntity != null) {
        row.set(OntologyTermMetaData.ONTOLOGY_TERM_NAME, ontologyTermEntity.getString(OntologyTermMetaData.ONTOLOGY_TERM_NAME));
        row.set(OntologyTermMetaData.ONTOLOGY_TERM_IRI, ontologyTermEntity.getString(OntologyTermMetaData.ONTOLOGY_TERM_IRI));
    }
    row.set(MatchingTaskContentMetaData.VALIDATED, resultEntity.getBoolean(MatchingTaskContentMetaData.VALIDATED));
    Double score = resultEntity.getDouble(MatchingTaskContentMetaData.SCORE);
    if (score != null) {
        row.set(MatchingTaskContentMetaData.SCORE, format.format(score));
    }
    return row;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) NumberFormat(java.text.NumberFormat)

Example 14 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class SortaCsvRepository method iterator.

@Override
public Iterator<Entity> iterator() {
    final AtomicInteger count = new AtomicInteger(0);
    final Iterator<Entity> iterator = csvRepository.iterator();
    return new Iterator<Entity>() {

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public Entity next() {
            Entity entity = iterator.next();
            if (isEmpty(entity.getString(ALLOWED_IDENTIFIER))) {
                DynamicEntity dynamicEntity = new DynamicEntity(getEntityType());
                dynamicEntity.set(entity);
                entity = dynamicEntity;
                entity.set(ALLOWED_IDENTIFIER, String.valueOf(count.incrementAndGet()));
            }
            return entity;
        }
    };
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 15 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity 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)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3