use of eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException 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.strategy.exceptions.StringNotParsableException in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method handleAuthors.
public void handleAuthors(INonViralName nameToBeFilled, String fullNameString, String authorString) {
TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
Integer[] years = new Integer[4];
try {
NomenclaturalCode code = nameToBeFilled.getNameType();
fullAuthors(authorString, authors, years, code);
} catch (StringNotParsableException e) {
nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
nameToBeFilled.setTitleCache(fullNameString, true);
// FIXME Quick fix, otherwise search would not deliver results for unparsable names
nameToBeFilled.setNameCache(fullNameString, true);
// END
logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
}
nameToBeFilled.setCombinationAuthorship(authors[0]);
nameToBeFilled.setExCombinationAuthorship(authors[1]);
nameToBeFilled.setBasionymAuthorship(authors[2]);
nameToBeFilled.setExBasionymAuthorship(authors[3]);
if (nameToBeFilled.isZoological()) {
IZoologicalName zooName = (IZoologicalName) nameToBeFilled;
zooName.setPublicationYear(years[0]);
zooName.setOriginalPublicationYear(years[2]);
}
}
use of eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method fullAuthors.
/**
* Parses the fullAuthorString
* @param fullAuthorString
* @return array of Teams containing the Team[0],
* ExTeam[1], BasionymTeam[2], ExBasionymTeam[3]
*/
protected void fullAuthors(String fullAuthorStringOrig, TeamOrPersonBase<?>[] authors, Integer[] years, NomenclaturalCode code) throws StringNotParsableException {
if (fullAuthorStringOrig == null || code == null) {
return;
}
String fullAuthorString = fullAuthorStringOrig.trim();
// Botanic
if (code.isBotanical()) {
if (!fullBotanicAuthorStringPattern.matcher(fullAuthorString).matches()) {
throw new StringNotParsableException("fullAuthorString (" + fullAuthorString + ") not parsable: ");
}
} else // Zoo
if (code.isZoological()) {
if (!fullZooAuthorStringPattern.matcher(fullAuthorString).matches()) {
throw new StringNotParsableException("fullAuthorString (" + fullAuthorString + ") not parsable: ");
}
} else {
// TODO
logger.warn("Full author String parsable only for defined BotanicalNames or ZoologicalNames but this is " + code.getLabel());
throw new StringNotParsableException("fullAuthorString (" + fullAuthorString + ") not parsable: ");
}
fullAuthorsChecked(fullAuthorString, authors, years);
}
use of eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException in project cdmlib by cybertaxonomy.
the class IpniService method getNameFromLine.
private IBotanicalName getNameFromLine(String line, Map<Integer, String> parameterMap, ICdmRepository repository, IpniServiceNamesConfigurator config) {
// Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
String[] splits = line.split("%");
Map<String, String> valueMap = fillValueMap(parameterMap, splits);
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
// epithets
name.setGenusOrUninomial(valueMap.get(GENUS));
name.setInfraGenericEpithet(valueMap.get(INFRA_GENUS));
name.setSpecificEpithet(valueMap.get(SPECIES));
name.setInfraSpecificEpithet(valueMap.get(INFRA_SPECIFIC));
// rank
try {
String rankStr = nomalizeRank(valueMap.get(RANK));
Rank rank = Rank.getRankByLatinNameOrIdInVoc(rankStr, NomenclaturalCode.ICNAFP, true);
name.setRank(rank);
} catch (UnknownCdmTypeException e) {
logger.warn("Rank was unknown");
}
// caches
String pureName = valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS);
String nameCache = name.getNameCache();
if (!Nz(pureName).equals(nameCache)) {
nvnParser.parseSimpleName(name, valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), name.getRank(), true);
// name.setNameCache(valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), true);
}
String authors = "";
// authors
if (valueMap.get(BASIONYM_AUTHOR) != null) {
authors = valueMap.get(BASIONYM_AUTHOR);
// name.setBasionymAuthorship(Team.NewTitledInstance(valueMap.get(BASIONYM_AUTHOR), valueMap.get(BASIONYM_AUTHOR)));
}
if (valueMap.get(PUBLISHING_AUTHOR) != null) {
authors += valueMap.get(PUBLISHING_AUTHOR);
// name.setCombinationAuthorship(Team.NewTitledInstance(valueMap.get(PUBLISHING_AUTHOR), valueMap.get(PUBLISHING_AUTHOR)));
}
try {
nvnParser.parseAuthors(name, authors);
} catch (StringNotParsableException e1) {
//
}
if (!Nz(valueMap.get(AUTHORS)).equals(name.getAuthorshipCache())) {
name.setAuthorshipCache(valueMap.get(AUTHORS), true);
}
if ("Y".equals(valueMap.get(HYBRID))) {
if (!name.isHybrid()) {
// Is there a concrete way to include the hybrid flag info? As it does not say which type of hybrid it seems
// to be best to handle hybrids via parsing. But there might be a better errror handling possible.
logger.warn("Name is flagged as hybrid at IPNI but CDM name has no hybrid flag set: " + name.getTitleCache());
}
}
// publication
if (valueMap.get(PUBLICATION) != null || valueMap.get(COLLATION) != null || valueMap.get(PUBLICATION_YEAR_FULL) != null) {
Reference ref = ReferenceFactory.newGeneric();
// TODO probably we can do better parsing here
String pub = CdmUtils.concat(" ", valueMap.get(PUBLICATION), valueMap.get(COLLATION));
if (isNotBlank(pub)) {
String nomRefTitle = pub;
String[] split = nomRefTitle.split(":");
if (split.length > 1) {
String detail = split[split.length - 1];
name.setNomenclaturalMicroReference(detail.trim());
nomRefTitle = nomRefTitle.substring(0, nomRefTitle.length() - detail.length() - 1).trim();
}
ref.setAbbrevTitle(nomRefTitle);
}
VerbatimTimePeriod datePublished = parsePublicationFullYear(valueMap.get(PUBLICATION_YEAR_FULL));
ref.setDatePublished(datePublished);
name.setNomenclaturalReference(ref);
}
// name status
NomenclaturalStatusType statusType = null;
String statusString = valueMap.get(NAME_STATUS);
if (isNotBlank(statusString)) {
try {
statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, name);
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(statusType);
name.addStatus(nomStatus);
} catch (UnknownCdmTypeException e) {
logger.warn("Name status not recognized: " + statusString);
Annotation annotation = Annotation.NewInstance("Name status: " + statusString, AnnotationType.EDITORIAL(), Language.ENGLISH());
name.addAnnotation(annotation);
}
}
// remarks
String remarks = valueMap.get(REMARKS);
if (remarks != null) {
Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
name.addAnnotation(annotation);
}
// basionym
if (config.isDoBasionyms() && valueMap.get(BASIONYM) != null) {
TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(null);
basionym.setTitleCache(valueMap.get(BASIONYM), true);
name.addBasionym(basionym);
}
// replaced synonym
if (config.isDoBasionyms() && valueMap.get(REPLACED_SYNONYM) != null) {
TaxonName replacedSynoynm = TaxonNameFactory.NewBotanicalInstance(null);
replacedSynoynm.setTitleCache(valueMap.get(REPLACED_SYNONYM), true);
name.addReplacedSynonym(replacedSynoynm, null, null, null, null);
}
// type information
if (config.isDoType() && valueMap.get(COLLECTION_DATE_AS_TEXT) != null || valueMap.get(COLLECTION_NUMBER) != null || valueMap.get(COLLECTION_DAY1) != null || valueMap.get(COLLECTION_DAY2) != null || valueMap.get(COLLECTION_MONTH1) != null || valueMap.get(COLLECTION_MONTH2) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null || valueMap.get(COLLECTOR_TEAM_AS_TEXT) != null || valueMap.get(LOCALITY) != null || valueMap.get(LATITUDE_DEGREES) != null || valueMap.get(LATITUDE_MINUTES) != null || valueMap.get(LATITUDE_SECONDS) != null || valueMap.get(NORTH_OR_SOUTH) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null) // TODO TBC
{
DerivedUnitFacade specimen = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
// gathering period
String collectionDateAsText = valueMap.get(COLLECTION_DATE_AS_TEXT);
TimePeriod gatheringPeriod = TimePeriodParser.parseString(collectionDateAsText);
try {
gatheringPeriod.setStartDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY1));
gatheringPeriod.setStartMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH1));
gatheringPeriod.setStartYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR1));
gatheringPeriod.setEndDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY2));
gatheringPeriod.setEndMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH2));
gatheringPeriod.setEndYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR2));
} catch (IndexOutOfBoundsException e) {
logger.info("Exception occurred when trying to fill gathering period");
}
specimen.setGatheringPeriod(gatheringPeriod);
specimen.setFieldNumber(valueMap.get(COLLECTION_NUMBER));
// collector team
String team = valueMap.get(COLLECTOR_TEAM_AS_TEXT);
if (team != null) {
Team collectorTeam = Team.NewTitledInstance(team, team);
specimen.setCollector(collectorTeam);
}
specimen.setLocality(valueMap.get(LOCALITY));
try {
String latDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
String latMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
String latSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
String direction = CdmUtils.Nz(valueMap.get(NORTH_OR_SOUTH));
String latitude = latDegrees + "°" + latMinutes + "'" + latSeconds + "\"" + direction;
String lonDegrees = CdmUtils.Nz(valueMap.get(LONGITUDE_DEGREES));
String lonMinutes = CdmUtils.Nz(valueMap.get(LONGITUDE_MINUTES));
String lonSeconds = CdmUtils.Nz(valueMap.get(LONGITUDE_SECONDS));
direction = CdmUtils.Nz(valueMap.get(EAST_OR_WEST));
String longitude = lonDegrees + "°" + lonMinutes + "'" + lonSeconds + "\"" + direction;
specimen.setExactLocationByParsing(longitude, latitude, null, null);
} catch (ParseException e) {
logger.info("Parsing exception occurred when trying to parse type exact location." + e.getMessage());
} catch (Exception e) {
logger.info("Exception occurred when trying to read type exact location." + e.getMessage());
}
// type annotation
if (valueMap.get(TYPE_REMARKS) != null) {
Annotation typeAnnotation = Annotation.NewInstance(valueMap.get(TYPE_REMARKS), AnnotationType.EDITORIAL(), Language.DEFAULT());
specimen.addAnnotation(typeAnnotation);
}
}
// TODO Type name
// TODO "Type locations" , eg. holotype CAT ,isotype CAT ,isotype FI
// TODO Geographic unit as text
// source
Reference citation = getIpniCitation(repository);
name.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Name", citation, valueMap.get(VERSION));
/* EXTENDED
* Species author,
* Standardised basionym author flag,
* Standardised publishing author flag
Full name
Full name without family
Full name without authors
Reference
Standardised publication flag
Publication year
publication year note
Publication year text
Volume
Start page
End page
Primary pagination
Secondary pagination
Reference remarks
Hybrid parents
Replaced synonym Author team
Other links
Same citation as
Bibliographic reference
Bibliographic type info
Original taxon name
Original taxon name author team
Original replaced synonym
Original replaced synonym author team
Original basionym
Original basionym author team
Original parent citation taxon name author team
Original taxon distribution
Original hybrid parentage
Original cited type
Original remarks
*/
return name;
}
use of eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException in project cdmlib by cybertaxonomy.
the class NormalExplicitImport method createTaxon.
/**
* @param state
* @param rank
* @param taxonNameStr
* @param authorStr
* @param nameStatus
* @param nameStatus2
* @param nc
* @return
*/
private TaxonBase<?> createTaxon(TaxonExcelImportState state, Rank rank, String taxonNameStr, String authorStr, String publishingAutorStr, String basionymAuthor, String reference, String date, String nameStatus, String taxonomicStatus, NomenclaturalCode nc) {
TaxonBase<?> taxonBase;
INonViralName taxonName = null;
if (nc == NomenclaturalCode.ICVCN) {
logger.warn("ICVCN not yet supported");
} else {
// String taxonNameStr = titleCache.substring(0, titleCache.indexOf(authorStr));
taxonName = nc.getNewTaxonNameInstance(rank);
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
taxonName = parser.parseFullName(taxonNameStr, nc, rank);
if (!taxonName.getNameCache().equals(taxonNameStr)) {
taxonName.setNameCache(taxonNameStr, true);
}
// Create the author
if (StringUtils.isNotBlank(authorStr)) {
try {
parser.parseAuthors(taxonName, authorStr);
} catch (StringNotParsableException e) {
taxonName.setAuthorshipCache(authorStr);
}
}
if (StringUtils.isNotBlank(reference)) {
String pub = CdmUtils.concat(" ", reference, ((NormalExplicitRow) state.getCurrentRow()).getCollation());
String[] split = pub.split(":");
pub = split[0];
INomenclaturalReference ref = state.getReference(pub);
if (ref == null) {
ref = parser.parseReferenceTitle(pub, date, true);
state.putReference(pub, (Reference) ref);
}
if (split.length > 1) {
String detail = split[split.length - 1];
taxonName.setNomenclaturalMicroReference(detail.trim());
}
if (ref.getAuthorship() == null) {
ref.setAuthorship(taxonName.getCombinationAuthorship());
}
if (ref.getAbbrevTitle() == null && !ref.isOfType(ReferenceType.Article)) {
ref.setAbbrevTitle(reference);
ref.setProtectedAbbrevTitleCache(false);
}
ref.setProtectedTitleCache(false);
taxonName.setNomenclaturalReference(ref);
// taxonName.setNomenclaturalMicroReference(state.getCurrentRow().getCollation());
}
}
// Create the taxon
// Reference sec = state.getConfig().getSourceReference();
// Create the status
nameStatus = CdmUtils.Nz(nameStatus).trim().toLowerCase();
taxonomicStatus = CdmUtils.Nz(taxonomicStatus).trim().toLowerCase();
if (synonymMarkers.contains(nameStatus) || synonymMarkers.contains(taxonomicStatus)) {
taxonBase = Synonym.NewInstance(taxonName, null);
} else if (validMarkers.contains(nameStatus)) {
taxonBase = Taxon.NewInstance(taxonName, null);
} else {
Taxon taxon = Taxon.NewInstance(taxonName, null);
if (nameStatusMarkers.contains(nameStatus)) {
if (nameStatus.equals(NOM_ILLEG)) {
taxonName.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
} else if (nameStatus.equals(NOM_REJ)) {
taxonName.addStatus(NomenclaturalStatusType.REJECTED(), null, null);
} else if (nameStatus.equals(NOM_CONS)) {
taxonName.addStatus(NomenclaturalStatusType.CONSERVED(), null, null);
}
} else {
taxon.setTaxonStatusUnknown(true);
}
taxonBase = taxon;
}
taxonBase.getName().addSource(OriginalSourceType.Import, null, "TaxonName", state.getConfig().getSourceReference(), null);
taxonBase.addSource(OriginalSourceType.Import, null, "TaxonName", state.getConfig().getSourceReference(), null);
return taxonBase;
}
Aggregations