use of eu.etaxonomy.cdm.model.name.NomenclaturalStatus in project cdmlib by cybertaxonomy.
the class NameCacheStrategyBase method getNomStatusTags.
@Override
public List<TaggedText> getNomStatusTags(TaxonName taxonName, boolean includeSeparatorBefore, boolean includeSeparatorAfter) {
Set<NomenclaturalStatus> ncStati = taxonName.getStatus();
Iterator<NomenclaturalStatus> iterator = ncStati.iterator();
List<TaggedText> nomStatusTags = new ArrayList<>();
while (iterator.hasNext()) {
NomenclaturalStatus ncStatus = iterator.next();
// since the NewInstance method of nomencatural status allows null as parameter
// we have to check for null values here
String nomStatusStr = "not defined";
if (ncStatus.getType() != null) {
NomenclaturalStatusType statusType = ncStatus.getType();
List<Language> prefLangs = Arrays.asList(new Language[] { Language.LATIN(), Language.DEFAULT() });
Representation repr = statusType.getPreferredRepresentation(prefLangs);
if (repr != null) {
if (!Language.LATIN().equals(repr.getLanguage())) {
String message = "No latin representation available for nom. status. " + statusType.getTitleCache();
logger.info(message);
}
nomStatusStr = repr.getAbbreviatedLabel();
} else {
String message = "No representation available for nom. status. " + statusType.getTitleCache();
logger.warn(message);
nomStatusStr = statusType.getTitleCache();
}
} else if (isNotBlank(ncStatus.getRuleConsidered())) {
nomStatusStr = ncStatus.getRuleConsidered();
}
String statusSeparator = ", ";
if (includeSeparatorBefore) {
nomStatusTags.add(new TaggedText(TagEnum.separator, statusSeparator));
}
nomStatusTags.add(new TaggedText(TagEnum.nomStatus, nomStatusStr, new TypedEntityReference<>(ncStatus.getClass(), ncStatus.getUuid())));
if (includeSeparatorAfter) {
nomStatusTags.add(new TaggedText(TagEnum.postSeparator, ","));
}
}
return nomStatusTags;
}
use of eu.etaxonomy.cdm.model.name.NomenclaturalStatus in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method extractStatusString.
private String extractStatusString(CdmLightExportState state, TaxonName name, boolean abbrev) {
try {
Set<NomenclaturalStatus> status = name.getStatus();
if (status.isEmpty()) {
return "";
}
String statusString = "";
for (NomenclaturalStatus nameStatus : status) {
if (nameStatus != null) {
if (abbrev) {
if (nameStatus.getType() != null) {
statusString += nameStatus.getType().getIdInVocabulary();
}
} else {
if (nameStatus.getType() != null) {
statusString += nameStatus.getType().getTitleCache();
}
}
if (!abbrev) {
if (nameStatus.getRuleConsidered() != null && !StringUtils.isBlank(nameStatus.getRuleConsidered())) {
statusString += ": " + nameStatus.getRuleConsidered();
}
if (nameStatus.getCitation() != null) {
String shortCitation = OriginalSourceFormatter.INSTANCE.format(nameStatus.getCitation(), null);
statusString += " (" + shortCitation + ")";
}
// if (nameStatus.getCitationMicroReference() != null
// && !StringUtils.isBlank(nameStatus.getCitationMicroReference())) {
// statusString += " " + nameStatus.getCitationMicroReference();
// }
}
statusString += " ";
}
}
return statusString;
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when extracting status string for " + cdmBaseStr(name) + ": " + e.getMessage());
return "";
}
}
use of eu.etaxonomy.cdm.model.name.NomenclaturalStatus in project cdmlib by cybertaxonomy.
the class Cdm2CdmImportBase method handlePersistedNomenclaturalStatus.
protected NomenclaturalStatus handlePersistedNomenclaturalStatus(NomenclaturalStatus status, Cdm2CdmImportState state) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException {
NomenclaturalStatus result = handlePersisted((SingleSourcedEntityBase) status, state);
// complete
result.setType(detache(result.getType(), state));
return result;
}
use of eu.etaxonomy.cdm.model.name.NomenclaturalStatus in project cdmlib by cybertaxonomy.
the class TcsXmlTaxonNameRelationsImport method doInvoke.
@Override
public void doInvoke(TcsXmlImportState state) {
logger.info("start make taxon name relations ...");
@SuppressWarnings("unchecked") MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>) state.getStore(ICdmIO.TAXONNAME_STORE);
Set<TaxonName> nameStore = new HashSet<>();
ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
String childName;
boolean obligatory;
TcsXmlImportConfigurator config = state.getConfig();
Element elDataSet = super.getDataSetElement(config);
Namespace tcsNamespace = config.getTcsXmlNamespace();
childName = "TaxonNames";
obligatory = false;
Element elTaxonNames = XmlHelp.getSingleChildElement(success, elDataSet, childName, tcsNamespace, obligatory);
String tcsElementName = "TaxonName";
@SuppressWarnings("unchecked") List<Element> elTaxonNameList = elTaxonNames == null ? new ArrayList<>() : elTaxonNames.getChildren(tcsElementName, tcsNamespace);
// Element source = tcsConfig.getSourceRoot();
int i = 0;
int nameRelCount = 0;
// for each taxonName
for (Element elTaxonName : elTaxonNameList) {
if ((++i % modCount) == 0) {
logger.info("Names handled: " + (i - 1));
}
// Basionyms
tcsElementName = "Basionym";
@SuppressWarnings("unchecked") List<Element> elBasionymList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elBasionym : elBasionymList) {
nameRelCount++;
logger.debug("BASIONYM " + nameRelCount);
NameRelationshipType relType = NameRelationshipType.BASIONYM();
boolean inverse = false;
String id = elTaxonName.getAttributeValue("id");
// TaxonName fromName = taxonNameMap.get(id);
makeNomenclaturalNoteType(config, elBasionym, relType, taxonNameMap, nameStore, removeVersionOfRef(id), inverse);
}
// end Basionyms
// SpellingCorrections
tcsElementName = "SpellingCorrectionOf";
@SuppressWarnings("unchecked") List<Element> elSpellingCorrectionList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elSpellingCorrection : elSpellingCorrectionList) {
nameRelCount++;
logger.debug("SpellingCorrectionOf " + nameRelCount);
NameRelationshipType relType = NameRelationshipType.ORTHOGRAPHIC_VARIANT();
boolean inverse = true;
String id = elTaxonName.getAttributeValue("id");
makeNomenclaturalNoteType(config, elSpellingCorrection, relType, taxonNameMap, nameStore, id, inverse);
}
// end SpellingCorrections
// LaterHomonymOf
tcsElementName = "LaterHomonymOf";
@SuppressWarnings("unchecked") List<Element> elLaterHomonymList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elLaterHomonym : elLaterHomonymList) {
nameRelCount++;
logger.debug("LaterHomonymOf " + nameRelCount);
NameRelationshipType relType = NameRelationshipType.LATER_HOMONYM();
boolean inverse = false;
String id = elTaxonName.getAttributeValue("id");
makeNomenclaturalNoteType(config, elLaterHomonym, relType, taxonNameMap, nameStore, id, inverse);
}
// end LaterHomonymOf
// ReplacementNameFor
tcsElementName = "ReplacementNameFor";
@SuppressWarnings("unchecked") List<Element> elReplacementNameForList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elReplacementNameFor : elReplacementNameForList) {
nameRelCount++;
logger.debug("LaterHomonymOf " + nameRelCount);
NameRelationshipType relType = NameRelationshipType.REPLACED_SYNONYM();
boolean inverse = false;
String id = elTaxonName.getAttributeValue("id");
makeNomenclaturalNoteType(config, elReplacementNameFor, relType, taxonNameMap, nameStore, id, inverse);
}
// end ReplacementNameFor
// ConservedAgainst
tcsElementName = "ConservedAgainst";
@SuppressWarnings("unchecked") List<Element> elConservedAgainstList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elConservedAgainst : elConservedAgainstList) {
nameRelCount++;
logger.debug("ConservedAgainst " + nameRelCount);
NameRelationshipType relType = NameRelationshipType.CONSERVED_AGAINST();
boolean inverse = false;
String id = elTaxonName.getAttributeValue("id");
makeNomenclaturalNoteType(config, elConservedAgainst, relType, taxonNameMap, nameStore, id, inverse);
}
// end ConservedAgainst
// Sanctioned
tcsElementName = "Sanctioned";
@SuppressWarnings("unchecked") List<Element> elSanctionedList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elSanctioned : elSanctionedList) {
// nameRelCount++;
// TODO sanctioned
logger.warn("Sanctioned not yet implemented ");
// /NameRelationshipType relType = NameRelationshipType.XXX
// boolean inverse = false;
//
// String id = elTaxonName.getAttributeValue("id");
// makeNomenclaturalNoteType(tcsConfig, elSanctioned, relType, taxonNameMap, nameStore, id, inverse);
}
// end Sanctioned
// PublicationStatus
tcsElementName = "PublicationStatus";
List<Element> elPublicationStatusList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elPublicationStatus : elPublicationStatusList) {
nameRelCount++;
// TODO PublicationStatus
// logger.warn("PublicationStatus not yet implemented " );
NomenclaturalStatusType statusType = null;
NameRelationshipType nameRelType = null;
@SuppressWarnings("unchecked") List<Content> content = elPublicationStatus.getContent();
Element el = elPublicationStatus.getChild("Note");
Iterator<Content> iterator = content.iterator();
Content next;
String ruleConsidered = null;
String relatedName = null;
while (iterator.hasNext()) {
next = iterator.next();
if (next.getClass().getName().equals("org.jdom.Element")) {
Element element = (Element) next;
try {
if (element.getName().equals("Note")) {
@SuppressWarnings("unchecked") Iterator<Content> iteratorNote = element.getContent().iterator();
Content nextNote;
while (iteratorNote.hasNext()) {
nextNote = iteratorNote.next();
if (nextNote.getValue().startsWith("nom. inval.")) {
statusType = TcsXmlTransformer.nomStatusString2NomStatus("nom. inval.");
} else if (nextNote.getValue().startsWith("nom. illeg.")) {
statusType = TcsXmlTransformer.nomStatusString2NomStatus("nom. illeg.");
} else if (nextNote.getValue().startsWith("nom. superfl.")) {
statusType = TcsXmlTransformer.nomStatusString2NomStatus("nom. superfl.");
} else if (nextNote.getValue().startsWith("[isonym]")) {
// in cdm NameRelationship
nameRelType = NameRelationshipType.LATER_ISONYM();
}
}
} else if (element.getName().equals("RuleConsidered")) {
@SuppressWarnings("unchecked") Iterator<Content> iteratorNote = element.getContent().iterator();
Content nextNote;
while (iteratorNote.hasNext()) {
nextNote = iteratorNote.next();
ruleConsidered = nextNote.getValue();
}
} else if (element.getName().equals("RelatedName")) {
@SuppressWarnings("unchecked") Iterator<Content> iteratorNote = element.getContent().iterator();
Content nextNote;
while (iteratorNote.hasNext()) {
nextNote = iteratorNote.next();
relatedName = nextNote.getValue();
}
}
} catch (UnknownCdmTypeException e) {
// TODO Auto-generated catch block
logger.warn(e.getMessage());
}
}
}
TaxonName taxonName = null;
if (statusType != null || nameRelType != null) {
String id = elTaxonName.getAttributeValue("id");
taxonName = taxonNameMap.get(removeVersionOfRef(id));
}
if (taxonName != null) {
if (statusType != null) {
NomenclaturalStatus status = NomenclaturalStatus.NewInstance(statusType);
if (ruleConsidered != null) {
status.setRuleConsidered(ruleConsidered);
}
taxonName.addStatus(status);
}
if (nameRelType != null) {
String id = elTaxonName.getAttributeValue("id");
TaxonName relatedTaxonName = taxonNameMap.get(removeVersionOfRef(id));
taxonName.addRelationshipFromName(relatedTaxonName, nameRelType, ruleConsidered, null);
}
}
}
// end PublicationStatus
// BasedOn
tcsElementName = "BasedOn";
@SuppressWarnings("unchecked") List<Element> elBasedOnList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
for (Element elBasedOn : elBasedOnList) {
// nameRelCount++;
// TODO BasedOn
logger.debug("BasedOn not yet implemented ");
/*
* <tcs:BasedOn>
<tcs:RelatedName ref="urn:lsid:ipni.org:names:151372-1"></tcs:RelatedName>
</tcs:BasedOn>
*/
// /NameRelationshipType relType = NameRelationshipType.XXX
// boolean inverse = false;
//
// String id = elTaxonName.getAttributeValue("id");
// makeNomenclaturalNoteType(tcsConfig, elBasedOn, relType, taxonNameMap, nameStore, id, inverse);
}
// end BasedOn
}
// Other Relations
// TODO
logger.info(nameRelCount + " nameRelations handled");
getNameService().save(nameStore);
logger.info("end make taxon name relationships ...");
if (!success.getValue()) {
state.setUnsuccessfull();
}
return;
}
use of eu.etaxonomy.cdm.model.name.NomenclaturalStatus in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method parseNomStatus.
// TODO make it an Array of status
/**
* Extracts a {@link NomenclaturalStatus} from the reference String and adds it to the @link {@link TaxonName}.
* The nomenclatural status part is deleted from the reference String.
* @return String the new (shortend) reference String
*/
public String parseNomStatus(String fullString, INonViralName nameToBeFilled, boolean makeEmpty) {
Set<NomenclaturalStatusType> existingStatusTypeSet = new HashSet<>();
Set<NomenclaturalStatusType> newStatusTypeSet = new HashSet<>();
for (NomenclaturalStatus existingStatus : nameToBeFilled.getStatus()) {
existingStatusTypeSet.add(existingStatus.getType());
}
String statusString;
Pattern hasStatusPattern = Pattern.compile("(" + pNomStatusPhrase + ")");
Matcher hasStatusMatcher = hasStatusPattern.matcher(fullString);
if (hasStatusMatcher.find()) {
String statusPhrase = hasStatusMatcher.group(0);
Pattern statusPattern = Pattern.compile(pNomStatus);
Matcher statusMatcher = statusPattern.matcher(statusPhrase);
statusMatcher.find();
statusString = statusMatcher.group(0);
try {
TaxonName nameToBeFilledCasted = TaxonName.castAndDeproxy(nameToBeFilled);
NomenclaturalStatusType nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, nameToBeFilledCasted);
if (!existingStatusTypeSet.contains(nomStatusType)) {
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(nomStatusType);
nameToBeFilled.addStatus(nomStatus);
}
newStatusTypeSet.add(nomStatusType);
fullString = fullString.replace(statusPhrase, "");
} catch (UnknownCdmTypeException e) {
// Do nothing
}
}
// remove not existing nom status
if (makeEmpty) {
Set<NomenclaturalStatus> tmpStatus = new HashSet<>();
tmpStatus.addAll(nameToBeFilled.getStatus());
for (NomenclaturalStatus status : tmpStatus) {
if (!newStatusTypeSet.contains(status.getType())) {
nameToBeFilled.removeStatus(status);
}
}
}
return fullString;
}
Aggregations