Search in sources :

Example 11 with StatisticalMeasure

use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.

the class OwlExportUtil method addFeatureResource.

private static Resource addFeatureResource(Feature feature, Resource termResource, ICdmRepository repo, StructureTreeOwlExportState state) {
    if (feature.isSupportsCategoricalData()) {
        termResource.addLiteral(OwlUtil.propFeatureIsCategorical, true);
    }
    if (feature.isSupportsQuantitativeData()) {
        termResource.addLiteral(OwlUtil.propFeatureIsQuantitative, true);
    }
    Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
    for (MeasurementUnit measurementUnit : recommendedMeasurementUnits) {
        Resource measurementUnitResource = createTermResource(measurementUnit, true, repo, state);
        termResource.addProperty(OwlUtil.propFeatureHasRecommendedMeasurementUnit, measurementUnitResource);
    }
    Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumerations = feature.getRecommendedModifierEnumeration();
    for (TermVocabulary<DefinedTerm> modifierVocabulary : recommendedModifierEnumerations) {
        Resource modifierEnumerationResource = createVocabularyResource(modifierVocabulary, repo, state);
        termResource.addProperty(OwlUtil.propFeatureHasRecommendedModifierEnumeration, modifierEnumerationResource);
    }
    Set<StatisticalMeasure> recommendedStatisticalMeasures = feature.getRecommendedStatisticalMeasures();
    for (StatisticalMeasure statisticalMeasure : recommendedStatisticalMeasures) {
        Resource statisticalMeasureResource = createTermResource(statisticalMeasure, true, repo, state);
        termResource.addProperty(OwlUtil.propFeatureHasRecommendedStatisticalMeasure, statisticalMeasureResource);
    }
    Set<TermVocabulary<State>> supportedCategoricalEnumerations = feature.getSupportedCategoricalEnumerations();
    for (TermVocabulary<State> stateVocabulary : supportedCategoricalEnumerations) {
        Resource supportedCategoricalEnumerationResource = createVocabularyResource(stateVocabulary, repo, state);
        termResource.addProperty(OwlUtil.propFeatureHasSupportedCategoricalEnumeration, supportedCategoricalEnumerationResource);
    }
    return termResource;
}
Also used : MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) State(eu.etaxonomy.cdm.model.description.State) FeatureState(eu.etaxonomy.cdm.model.description.FeatureState) Resource(com.hp.hpl.jena.rdf.model.Resource) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 12 with StatisticalMeasure

use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.

the class SDDImport method handleSummaryQuantitativeData.

/**
 * @param sddNamespace
 * @param taxonDescription
 * @param elSummaryData
 */
private void handleSummaryQuantitativeData(Namespace sddNamespace, TaxonDescription taxonDescription, Element elSummaryData) {
    String ref;
    int k;
    // <Quantitative ref="c2">
    List<Element> elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace);
    k = 0;
    // for each Quantitative
    for (Element elQuantitative : elQuantitatives) {
        if ((++k % modCount) == 0) {
            logger.warn("Quantitative handled: " + (k - 1));
        }
        ref = elQuantitative.getAttributeValue("ref");
        Feature feature = features.get(ref);
        QuantitativeData quantitativeData = QuantitativeData.NewInstance();
        quantitativeData.setFeature(feature);
        MeasurementUnit unit = units.get(ref);
        String prefix = defaultUnitPrefixes.get(ref);
        if (unit != null) {
            String u = unit.getLabel();
            if (prefix != null) {
                u = prefix + u;
            }
            unit.setLabel(u);
            quantitativeData.setUnit(unit);
        }
        // <Measure type="Min" value="2.3"/>
        List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
        int l = 0;
        // for each State
        for (Element elMeasure : elMeasures) {
            if ((++l % modCount) == 0) {
                logger.info("States handled: " + (l - 1));
            }
            String type = elMeasure.getAttributeValue("type");
            String value = elMeasure.getAttributeValue("value");
            if (value.contains(",")) {
                value = value.replace(',', '.');
            }
            BigDecimal v = new BigDecimal(value);
            // Float v = new Float(0);
            StatisticalMeasure t = null;
            if (type.equals("Min")) {
                t = StatisticalMeasure.MIN();
            } else if (type.equals("Mean")) {
                t = StatisticalMeasure.AVERAGE();
            } else if (type.equals("Max")) {
                t = StatisticalMeasure.MAX();
            } else if (type.equals("SD")) {
                t = StatisticalMeasure.STANDARD_DEVIATION();
            } else if (type.equals("N")) {
                t = StatisticalMeasure.SAMPLE_SIZE();
            } else if (type.equals("UMethLower")) {
                t = StatisticalMeasure.TYPICAL_LOWER_BOUNDARY();
            } else if (type.equals("UMethUpper")) {
                t = StatisticalMeasure.TYPICAL_UPPER_BOUNDARY();
            } else if (type.equals("Var")) {
                t = StatisticalMeasure.VARIANCE();
            } else {
                t = StatisticalMeasure.NewInstance(type, type, type);
                statisticalMeasures.add(t);
            }
            StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
            statisticalValue.setValue(v);
            statisticalValue.setType(t);
            quantitativeData.addStatisticalValue(statisticalValue);
            featureData.add(statisticalValue);
        }
        taxonDescription.addElement(quantitativeData);
    }
}
Also used : MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) Element(org.jdom.Element) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) Feature(eu.etaxonomy.cdm.model.description.Feature) BigDecimal(java.math.BigDecimal) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue)

Example 13 with StatisticalMeasure

use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.

the class PolytomousKeyGenerator method computeAllValues.

private void computeAllValues(List<BigDecimal> allValues, QuantitativeData qd) {
    Set<StatisticalMeasurementValue> values = qd.getStatisticalValues();
    BigDecimal lowerboundary = null;
    BigDecimal upperboundary = null;
    for (StatisticalMeasurementValue smv : values) {
        StatisticalMeasure type = smv.getType();
        BigDecimal value = smv.getValue();
        // DONT FORGET sample size, MEAN etc
        if (type.isMin() || type.isTypicalLowerBoundary() || type.isAverage() || type.isExactValue()) {
            if (lowerboundary == null) {
                lowerboundary = value;
            } else {
                lowerboundary = lowerboundary.min(value);
            }
        }
        if (type.isMax() || type.isTypicalUpperBoundary() || type.isAverage() || type.isExactValue()) {
            if (upperboundary == null) {
                upperboundary = value;
            } else {
                upperboundary = upperboundary.max(value);
            }
        }
    // if (type.isMax()) {
    // upperboundary = smv.getValue();
    // upperboundarypresent=true;
    // }else if (type.equals(StatisticalMeasure.MIN())) {
    // lowerboundary = smv.getValue();
    // lowerboundarypresent=true;
    // }else if (type.equals(StatisticalMeasure.TYPICAL_UPPER_BOUNDARY()) && upperboundarypresent==false) {
    // upperboundary = smv.getValue();
    // upperboundarypresent=true;
    // }else if (type.equals(StatisticalMeasure.TYPICAL_LOWER_BOUNDARY()) && lowerboundarypresent==false) {
    // lowerboundary = smv.getValue();
    // lowerboundarypresent=true;
    // }else if (type.equals(StatisticalMeasure.AVERAGE()) && upperboundarypresent==false && lowerboundarypresent==false) {
    // lowerboundary = smv.getValue();
    // upperboundary = lowerboundary;
    // lowerboundarypresent=true;
    // upperboundarypresent=true;
    // }
    }
    if (lowerboundary != null && upperboundary != null) {
        allValues.add(lowerboundary);
        allValues.add(upperboundary);
    } else if (lowerboundary != null || upperboundary != null) {
        logger.warn("Only one of upper or lower boundary is defined. Statistical measurement value not used.");
    }
}
Also used : StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) BigDecimal(java.math.BigDecimal)

Example 14 with StatisticalMeasure

use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.

the class CharacterDto method fromCharacter.

public static CharacterDto fromCharacter(Character character) {
    TermVocabulary voc = character.getVocabulary();
    Set<TermVocabularyDto> recommendedModifierDtos = new HashSet<>();
    for (TermVocabulary<DefinedTerm> modVoc : character.getRecommendedModifierEnumeration()) {
        recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary(modVoc));
    }
    Set<TermDto> recommendedStatisticalMeasuresDtos = new HashSet<>();
    for (StatisticalMeasure term : character.getRecommendedStatisticalMeasures()) {
        recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term));
    }
    Set<TermVocabularyDto> supportedCategoricalDtos = new HashSet<>();
    for (TermVocabulary<State> catVoc : character.getSupportedCategoricalEnumerations()) {
        supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(catVoc));
    }
    Set<TermDto> recommendedMeasurementUnitsDtos = new HashSet<>();
    for (MeasurementUnit term : character.getRecommendedMeasurementUnits()) {
        recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term));
    }
    CharacterDto dto = new CharacterDto(character.getUuid(), character.getRepresentations(), character.getPartOf() != null ? character.getPartOf().getUuid() : null, character.getKindOf() != null ? character.getKindOf().getUuid() : null, voc != null ? voc.getUuid() : null, null, character.getIdInVocabulary(), character.isAvailableForTaxon(), character.isAvailableForTaxonName(), character.isAvailableForOccurrence(), character.getTitleCache(), character.getStructure() != null ? TermNodeDto.fromNode(character.getStructure(), null) : null, character.getStructureModifier() != null ? TermDto.fromTerm(character.getStructureModifier()) : null, character.getProperty() != null ? TermNodeDto.fromNode(character.getProperty(), null) : null, character.getPropertyModifier() != null ? TermDto.fromTerm(character.getPropertyModifier()) : null, character.getRatioToStructure() != null ? TermNodeDto.fromNode(character.getRatioToStructure(), null) : null, character.isSupportsCategoricalData(), character.isSupportsQuantitativeData(), supportedCategoricalDtos, recommendedModifierDtos, recommendedMeasurementUnitsDtos, recommendedStatisticalMeasuresDtos);
    return dto;
}
Also used : MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) State(eu.etaxonomy.cdm.model.description.State) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) HashSet(java.util.HashSet)

Example 15 with StatisticalMeasure

use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.

the class CharacterDto method termDtoListFrom.

public static List<TermDto> termDtoListFrom(List<Object[]> results) {
    // list to ensure order
    List<TermDto> dtos = new ArrayList<>();
    // map to handle multiple representations/media/vocRepresentation because of LEFT JOIN
    Map<UUID, TermDto> dtoMap = new HashMap<>(results.size());
    for (Object[] elements : results) {
        UUID uuid = (UUID) elements[0];
        if (dtoMap.containsKey(uuid)) {
            // multiple results for one term -> multiple (voc) representation/media
            if (elements[1] != null) {
                dtoMap.get(uuid).addRepresentation((Representation) elements[1]);
            }
            // }
            if (elements[8] != null) {
                dtoMap.get(uuid).addMedia(((Media) elements[8]).getUuid());
            }
        } else {
            // term representation
            Set<Representation> representations = new HashSet<>();
            if (elements[1] instanceof Representation) {
                representations = new HashSet<Representation>(1);
                representations.add((Representation) elements[1]);
            }
            // term media
            Set<UUID> mediaUuids = new HashSet<>();
            if (elements[8] instanceof Media) {
                mediaUuids.add(((Media) elements[8]).getUuid());
            }
            // voc representation
            // Set<Representation> vocRepresentations = new HashSet<>();
            // if(elements[6] instanceof Representation) {
            // vocRepresentations = new HashSet<Representation>(7);
            // vocRepresentations.add((Representation)elements[6]);
            // }
            boolean isAvailableForTaxon = false;
            boolean isAvailableForTaxonName = false;
            boolean isAvailableForOccurrence = false;
            EnumSet<CdmClass> availableForString = (EnumSet<CdmClass>) elements[9];
            if (availableForString.contains(CdmClass.TAXON)) {
                isAvailableForTaxon = true;
            }
            if (availableForString.contains(CdmClass.TAXON_NAME)) {
                isAvailableForTaxonName = true;
            }
            if (availableForString.contains(CdmClass.OCCURRENCE)) {
                isAvailableForOccurrence = true;
            }
            boolean isSupportsCategoricalData = false;
            boolean isSupportsQuantitativeData = false;
            EnumSet<CdmClass> supportsString = (EnumSet<CdmClass>) elements[11];
            if (supportsString.contains(CdmClass.CATEGORICAL_DATA)) {
                isSupportsCategoricalData = true;
            }
            if (supportsString.contains(CdmClass.QUANTITATIVE_DATA)) {
                isSupportsQuantitativeData = true;
            }
            Object o = elements[12];
            Set<TermVocabularyDto> recommendedModifierDtos = new HashSet<>();
            if (o instanceof TermVocabulary) {
                recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary) o));
            } else if (o instanceof Set) {
                Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = (Set<TermVocabulary<DefinedTerm>>) o;
                if (recommendedModifierEnumeration != null) {
                    for (TermVocabulary<DefinedTerm> voc : recommendedModifierEnumeration) {
                        recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary(voc));
                    }
                }
            }
            o = elements[13];
            Set<TermDto> recommendedStatisticalMeasuresDtos = new HashSet<>();
            if (o instanceof StatisticalMeasure) {
                recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm((StatisticalMeasure) o));
            } else if (o instanceof Set) {
                Set<StatisticalMeasure> recommendedStatisticalMeasures = (Set<StatisticalMeasure>) o;
                if (recommendedStatisticalMeasures != null) {
                    for (StatisticalMeasure term : recommendedStatisticalMeasures) {
                        recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term));
                    }
                }
            }
            o = elements[14];
            Set<TermVocabularyDto> supportedCategoricalDtos = new HashSet<>();
            if (o instanceof TermVocabulary) {
                supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary) o));
            } else if (o instanceof Set) {
                Set<TermVocabulary> supportedCategoricalEnumerations = (Set<TermVocabulary>) o;
                for (TermVocabulary<State> voc : supportedCategoricalEnumerations) {
                    supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(voc));
                }
            }
            o = elements[15];
            Set<TermDto> recommendedMeasurementUnitsDtos = new HashSet<>();
            if (o instanceof MeasurementUnit) {
                recommendedMeasurementUnitsDtos.add(TermDto.fromTerm((MeasurementUnit) o));
            } else if (o instanceof Set) {
                Set<MeasurementUnit> recommendedMeasurementUnits = (Set<MeasurementUnit>) elements[15];
                for (MeasurementUnit term : recommendedMeasurementUnits) {
                    recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term));
                }
            }
            o = elements[16];
            TermNodeDto prop = null;
            if (o instanceof TermNode) {
                prop = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
            }
            o = elements[17];
            TermNodeDto structure = null;
            if (o instanceof TermNode) {
                structure = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
            }
            o = elements[9];
            TermNodeDto ratioTo = null;
            if (o instanceof TermNode) {
                ratioTo = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
            }
            TermDto termDto = new CharacterDto(uuid, representations, (UUID) elements[2], (UUID) elements[3], (UUID) elements[4], null, (String) elements[5], // vocRepresentations,
            isAvailableForTaxon, isAvailableForTaxonName, isAvailableForOccurrence, (String) elements[10], structure, null, prop, null, ratioTo, isSupportsCategoricalData, // structure, structureModifier, prop, null, isSupportsCategoricalData,
            isSupportsQuantitativeData, supportedCategoricalDtos, recommendedModifierDtos, recommendedMeasurementUnitsDtos, recommendedStatisticalMeasuresDtos);
            termDto.setUri((URI) elements[7]);
            termDto.setMedia(mediaUuids);
            dtoMap.put(uuid, termDto);
            dtos.add(termDto);
        }
    }
    return dtos;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TermNode(eu.etaxonomy.cdm.model.term.TermNode) CdmClass(eu.etaxonomy.cdm.model.common.CdmClass) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) UUID(java.util.UUID) HashSet(java.util.HashSet) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) EnumSet(java.util.EnumSet) Media(eu.etaxonomy.cdm.model.media.Media) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) Representation(eu.etaxonomy.cdm.model.term.Representation) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Aggregations

StatisticalMeasure (eu.etaxonomy.cdm.model.description.StatisticalMeasure)16 MeasurementUnit (eu.etaxonomy.cdm.model.description.MeasurementUnit)11 HashSet (java.util.HashSet)10 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)7 TermVocabulary (eu.etaxonomy.cdm.model.term.TermVocabulary)7 StatisticalMeasurementValue (eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue)6 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)6 State (eu.etaxonomy.cdm.model.description.State)5 Set (java.util.Set)5 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)4 TermDto (eu.etaxonomy.cdm.persistence.dto.TermDto)4 HashMap (java.util.HashMap)4 Feature (eu.etaxonomy.cdm.model.description.Feature)3 Media (eu.etaxonomy.cdm.model.media.Media)3 DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)3 CategoricalDataDto (eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto)2 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)2 DescriptionElementDto (eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto)2 QuantitativeDataDto (eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto)2