Search in sources :

Example 11 with NomenclaturalStatus

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;
}
Also used : Language(eu.etaxonomy.cdm.model.common.Language) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) ArrayList(java.util.ArrayList) Representation(eu.etaxonomy.cdm.model.term.Representation) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) NomenclaturalStatusType(eu.etaxonomy.cdm.model.name.NomenclaturalStatusType) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 12 with NomenclaturalStatus

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 "";
    }
}
Also used : NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)

Example 13 with NomenclaturalStatus

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;
}
Also used : NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus)

Example 14 with NomenclaturalStatus

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;
}
Also used : NameRelationshipType(eu.etaxonomy.cdm.model.name.NameRelationshipType) Element(org.jdom.Element) NomenclaturalStatusType(eu.etaxonomy.cdm.model.name.NomenclaturalStatusType) MapWrapper(eu.etaxonomy.cdm.io.common.MapWrapper) Namespace(org.jdom.Namespace) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) Content(org.jdom.Content) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) Iterator(java.util.Iterator) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) HashSet(java.util.HashSet)

Example 15 with NomenclaturalStatus

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;
}
Also used : Pattern(java.util.regex.Pattern) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) Matcher(java.util.regex.Matcher) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) NomenclaturalStatusType(eu.etaxonomy.cdm.model.name.NomenclaturalStatusType) HashSet(java.util.HashSet)

Aggregations

NomenclaturalStatus (eu.etaxonomy.cdm.model.name.NomenclaturalStatus)19 NomenclaturalStatusType (eu.etaxonomy.cdm.model.name.NomenclaturalStatusType)7 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)6 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)5 HomotypicalGroup (eu.etaxonomy.cdm.model.name.HomotypicalGroup)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 VerbatimTimePeriod (eu.etaxonomy.cdm.model.common.VerbatimTimePeriod)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)2 NameRelationship (eu.etaxonomy.cdm.model.name.NameRelationship)2 NameTypeDesignation (eu.etaxonomy.cdm.model.name.NameTypeDesignation)2 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)2 User (eu.etaxonomy.cdm.model.permission.User)2 Reference (eu.etaxonomy.cdm.model.reference.Reference)2 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)2 Representation (eu.etaxonomy.cdm.model.term.Representation)2 HashMap (java.util.HashMap)2