Search in sources :

Example 1 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class SpecimenCdmExcelImport method createTaxonFromDetermination.

private Taxon createTaxonFromDetermination(SpecimenCdmExcelImportState state, DeterminationLight commonDetermination) {
    // rank
    Rank rank;
    try {
        rank = isBlank(commonDetermination.rank) ? null : Rank.getRankByLatinNameOrIdInVoc(commonDetermination.rank, true);
    } catch (UnknownCdmTypeException e) {
        rank = null;
    }
    // name
    INonViralName name;
    INonViralNameParser<INonViralName> parser = NonViralNameParserImpl.NewInstance();
    NomenclaturalCode nc = state.getConfig().getNomenclaturalCode();
    if (StringUtils.isNotBlank(commonDetermination.fullName)) {
        name = parser.parseFullName(commonDetermination.fullName, nc, rank);
        if (StringUtils.isBlank(name.getAuthorshipCache()) && StringUtils.isNotBlank(commonDetermination.author)) {
            setAuthorship(name, commonDetermination.author, parser);
        }
    } else {
        if (nc != null) {
            name = nc.getNewTaxonNameInstance(rank);
        } else {
            name = TaxonNameFactory.NewNonViralInstance(rank);
        }
        if (StringUtils.isNotBlank(commonDetermination.genus)) {
            name.setGenusOrUninomial(commonDetermination.genus);
        }
        if (StringUtils.isNotBlank(commonDetermination.speciesEpi)) {
            name.setSpecificEpithet(commonDetermination.speciesEpi);
        }
        if (StringUtils.isNotBlank(commonDetermination.infraSpeciesEpi)) {
            name.setInfraSpecificEpithet(commonDetermination.infraSpeciesEpi);
        }
        if (StringUtils.isNotBlank(commonDetermination.author)) {
            setAuthorship(name, commonDetermination.author, parser);
        }
        // guess rank if null
        if (name.getRank() == null) {
            if (name.getInfraGenericEpithet() != null && name.getSpecificEpithet() == null) {
                name.setRank(Rank.INFRAGENERICTAXON());
            } else if (name.getSpecificEpithet() != null && name.getInfraSpecificEpithet() == null) {
                name.setRank(Rank.SPECIES());
            } else if (name.getInfraSpecificEpithet() != null) {
                name.setRank(Rank.INFRASPECIFICTAXON());
            }
        }
    }
    // sec
    Reference sec = null;
    if (StringUtils.isNotBlank(commonDetermination.determinedBy)) {
        sec = ReferenceFactory.newGeneric();
        TeamOrPersonBase<?> determinedBy;
        IBotanicalName dummyName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
        try {
            parser.parseAuthors(dummyName, commonDetermination.determinedBy);
            determinedBy = dummyName.getCombinationAuthorship();
        } catch (StringNotParsableException e) {
            determinedBy = Team.NewTitledInstance(commonDetermination.determinedBy, commonDetermination.determinedBy);
        }
        sec.setAuthorship(determinedBy);
    }
    // taxon
    Taxon taxon = Taxon.NewInstance(name, sec);
    if (StringUtils.isNotBlank(commonDetermination.family)) {
        if (name.getRank() == null || name.getRank().isLower(Rank.FAMILY())) {
            logger.warn("Family taxon could not be created");
        }
    }
    // return
    return taxon;
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Rank(eu.etaxonomy.cdm.model.name.Rank) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)

Example 2 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class SpecimenCdmExcelImport method makeTaxonName.

/**
 * @param state
 * @param determinationLight
 * @return
 */
private INonViralName makeTaxonName(SpecimenCdmExcelImportState state, DeterminationLight determinationLight) {
    INonViralName name = TaxonNameFactory.NewNonViralInstance(null);
    NomenclaturalCode nc = state.getConfig().getNomenclaturalCode();
    if (nc != null) {
        name = nc.getNewTaxonNameInstance(null);
    }
    name.setGenusOrUninomial(determinationLight.genus);
    name.setSpecificEpithet(determinationLight.speciesEpi);
    name.setInfraSpecificEpithet(determinationLight.infraSpeciesEpi);
    // FIXME bracketAuthors and teams not yet implemented!!!
    List<String> authors = new ArrayList<String>();
    if (StringUtils.isNotBlank(determinationLight.author)) {
        authors.add(determinationLight.author);
    }
    TeamOrPersonBase<?> agent = getOrMakeAgent(state, authors);
    name.setCombinationAuthorship(agent);
    try {
        if (StringUtils.isNotBlank(determinationLight.rank)) {
            name.setRank(Rank.getRankByLatinNameOrIdInVoc(determinationLight.rank, nc, true));
        }
    } catch (UnknownCdmTypeException e) {
        String message = "Rank not found: %s: ";
        message = String.format(message, determinationLight.rank);
        logger.warn(message);
    }
    if (StringUtils.isBlank(name.getInfraSpecificEpithet()) && StringUtils.isNotBlank(name.getSpecificEpithet())) {
        name.setRank(Rank.SPECIES());
    }
    if (StringUtils.isBlank(name.getSpecificEpithet()) && StringUtils.isNotBlank(name.getGenusOrUninomial())) {
        name.setRank(Rank.SPECIES());
    }
    if (StringUtils.isBlank(name.getTitleCache())) {
        // TODO test
        name.setTitleCache(determinationLight.fullName, true);
    }
    return name;
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) ArrayList(java.util.ArrayList)

Example 3 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class SpecimenCdmExcelImport method getTaxonName.

private TaxonName getTaxonName(SpecimenCdmExcelImportState state, String name) {
    TaxonName result = null;
    result = state.getName(name);
    if (result != null) {
        return result;
    }
    List<TaxonName> list = getNameService().findByTitleWithRestrictions(null, name, null, null, null, null, null, null).getRecords();
    // TODO better strategy to find best name, e.g. depending on the classification it is used in
    if (!list.isEmpty()) {
        result = list.get(0);
    }
    if (result == null) {
        NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
        NomenclaturalCode code = state.getConfig().getNomenclaturalCode();
        result = (TaxonName) parser.parseFullName(name, code, null);
    }
    if (result != null) {
        state.putName(name, result);
    }
    return result;
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) NonViralNameParserImpl(eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 4 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class DwcTaxonStreamItem2CdmTaxonConverter method toBeRemovedFromStream.

@Override
public boolean toBeRemovedFromStream(StreamItem item) {
    if (!config.isDoSplitRelationshipImport()) {
        return false;
    } else {
        if (isSynonym(item)) {
            return !this.config.isDoSynonymRelationships();
        } else {
            NomenclaturalCode nomCode = getNomCode(item);
            Rank rank = getRank(item, nomCode);
            boolean isHigherRank = rank == null || rank.isHigher(Rank.SPECIES());
            if (isHigherRank) {
                return !config.isDoHigherRankRelationships();
            } else {
                return !config.isDoLowerRankRelationships();
            }
        }
    }
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) Rank(eu.etaxonomy.cdm.model.name.Rank)

Example 5 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class DwcTaxonStreamItem2CdmTaxonConverter method getNomCode.

private NomenclaturalCode getNomCode(StreamItem item) {
    String strNomCode = getValue(item, TermUri.DWC_NOMENCLATURAL_CODE);
    NomenclaturalCode nomCode = null;
    // by Nomcenclatural Code
    if (strNomCode != null) {
        nomCode = NomenclaturalCode.fromString(strNomCode);
        if (nomCode == null) {
            String message = "NomCode '%s' not recognized";
            message = String.format(message, strNomCode);
            fireWarningEvent(message, item, 4);
        } else {
            return nomCode;
        }
    }
    // by Kingdom
    String strKingdom = getValue(item, TermUri.DWC_KINGDOM);
    if (strKingdom != null) {
        if (strKingdom.equalsIgnoreCase("Plantae")) {
            nomCode = NomenclaturalCode.ICNAFP;
        } else if (strKingdom.equalsIgnoreCase("Fungi")) {
            nomCode = NomenclaturalCode.ICNAFP;
        } else if (strKingdom.equalsIgnoreCase("Animalia")) {
            nomCode = NomenclaturalCode.ICZN;
        } else if (strKingdom.equalsIgnoreCase("Protozoa")) {
            nomCode = NomenclaturalCode.ICZN;
        }
    }
    // TODO further kingdoms
    if (nomCode == null) {
        // TODO warning
        if (config.getNomenclaturalCode() != null) {
            nomCode = config.getNomenclaturalCode();
        }
    }
    return nomCode;
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode)

Aggregations

NomenclaturalCode (eu.etaxonomy.cdm.model.name.NomenclaturalCode)18 Rank (eu.etaxonomy.cdm.model.name.Rank)8 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)7 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)7 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)6 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 ArrayList (java.util.ArrayList)3 Person (eu.etaxonomy.cdm.model.agent.Person)2 TeamOrPersonBase (eu.etaxonomy.cdm.model.agent.TeamOrPersonBase)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)2 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)2 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)2 Property (com.hp.hpl.jena.rdf.model.Property)1 Statement (com.hp.hpl.jena.rdf.model.Statement)1 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)1 URI (eu.etaxonomy.cdm.common.URI)1 MapWrapper (eu.etaxonomy.cdm.io.common.MapWrapper)1 ExcelDistributionUpdateConfigurator (eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator)1 NormalExplicitImportConfigurator (eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator)1