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