Search in sources :

Example 1 with Collection

use of eu.etaxonomy.cdm.model.occurrence.Collection in project cdmlib by cybertaxonomy.

the class BciServiceWrapper method getCollectionFromLine.

private Collection getCollectionFromLine(String line, ICdmRepository appConfig) {
    // urn:lsid:biocol.org:col:15727	http://biocol.org/urn:lsid:biocol.org:col:15727	University of Bergen Herbarium
    String[] splits = line.split("\t");
    if (splits.length != 3) {
        logger.warn("Unknwon BCI line format: " + line);
        return null;
    }
    String lsidString = splits[0];
    String urlString = splits[1];
    String collectionName = splits[2];
    Collection result = Collection.NewInstance();
    // LSID
    LSID lsid = null;
    try {
        lsid = new LSID(lsidString);
    } catch (MalformedLSIDException e) {
        logger.warn("Malformed LSID " + lsidString, e);
    }
    result.setLsid(lsid);
    String id = getCollectionId(lsid);
    result.setName(collectionName);
    // id, citation
    Reference citation = getBciCitation(appConfig);
    result.addSource(OriginalSourceType.Lineage, id, null, citation, null);
    return result;
}
Also used : LSID(eu.etaxonomy.cdm.model.common.LSID) MalformedLSIDException(com.ibm.lsid.MalformedLSIDException) Reference(eu.etaxonomy.cdm.model.reference.Reference) Collection(eu.etaxonomy.cdm.model.occurrence.Collection)

Example 2 with Collection

use of eu.etaxonomy.cdm.model.occurrence.Collection in project cdmlib by cybertaxonomy.

the class SpecimenImportBase method getCollection.

/**
 * Look if the Collection does already exist
 * @param collectionCode
 * @param collectionCode: a string
 * @param config : the configurator
 * @return the Collection (existing or new)
 */
protected Collection getCollection(Institution institution, String collectionCode, STATE state) {
    SpecimenImportConfiguratorBase config = state.getConfig();
    Collection collection = null;
    List<Collection> collections;
    collection = (Collection) state.collections.get(collectionCode);
    if (collection != null) {
        return collection;
    }
    try {
        collections = getCollectionService().searchByCode(collectionCode);
    } catch (Exception e) {
        collections = new ArrayList<Collection>();
    }
    if (collections.size() > 0 && config.isReuseExistingMetaData()) {
        for (Collection coll : collections) {
            if (coll.getCode() != null && coll.getInstitute() != null && coll.getCode().equalsIgnoreCase(collectionCode) && coll.getInstitute().equals(institution)) {
                collection = coll;
                break;
            }
        }
    }
    if (collection == null) {
        collection = Collection.NewInstance();
        collection.setCode(collectionCode);
        collection.setInstitute(institution);
        collection.setTitleCache(collectionCode);
        UUID uuid = save(collection, state);
    }
    state.collections.put(collectionCode, collection);
    return collection;
}
Also used : ArrayList(java.util.ArrayList) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) UUID(java.util.UUID)

Example 3 with Collection

use of eu.etaxonomy.cdm.model.occurrence.Collection in project cdmlib by cybertaxonomy.

the class Abcd206Import method setCollectionData.

/**
 * setCollectionData : store the collection object into the
 * derivedUnitFacade
 *
 * @param state
 */
protected void setCollectionData(Abcd206ImportState state, DerivedUnitFacade derivedUnitFacade) {
    Abcd206ImportConfigurator config = state.getConfig();
    SpecimenImportUtility.setUnitID(derivedUnitFacade.innerDerivedUnit(), state.getDataHolder().getUnitID(), config);
    if (!config.isMapUnitIdToAccessionNumber()) {
        derivedUnitFacade.setAccessionNumber(NB(state.getDataHolder().accessionNumber));
    }
    // derivedUnitFacade.setCollectorsNumber(NB(state.getDataHolder().collectorsNumber));
    /*
         * INSTITUTION & COLLECTION
         */
    // manage institution
    Institution institution = this.getInstitution(NB(state.getDataHolder().institutionCode), state);
    // manage collection
    Collection collection = this.getCollection(institution, NB(state.getDataHolder().collectionCode), state);
    // link specimen & collection
    derivedUnitFacade.setCollection(collection);
}
Also used : Collection(eu.etaxonomy.cdm.model.occurrence.Collection) Institution(eu.etaxonomy.cdm.model.agent.Institution)

Example 4 with Collection

use of eu.etaxonomy.cdm.model.occurrence.Collection in project cdmlib by cybertaxonomy.

the class MarkupSpecimenImport method makeFotgSpecimenType.

/**
 * Implemented for Flora of the Guyanas this may include duplicated code from similar places
 * @param state
 * @param collectionAndTypeOrig
 * @param facade
 * @param name
 * @param parentEvent
 * @return
 */
private boolean makeFotgSpecimenType(MarkupImportState state, final String collectionAndTypeOrig, DerivedUnitFacade facade, INonViralName name, XMLEvent parentEvent) {
    String collectionAndType = collectionAndTypeOrig;
    String notDesignatedRE = "not\\s+designated";
    String designatedByRE = "\\s*\\(((designated\\s+by\\s+|according\\s+to\\s+)[^\\)]+|here\\s+designated)\\)";
    String typesRE = "(holotype|isotypes?|neotype|isoneotype|syntype|lectotype|isolectotypes?|typ\\.\\scons\\.,?)";
    String collectionRE = "[A-Z\\-]{1,5}!?";
    String collectionsRE = String.format("%s(,\\s+%s)*", collectionRE, collectionRE);
    String addInfoRE = "(not\\s+seen|(presumed\\s+)?destroyed)";
    String singleTypeTypeRE = String.format("(%s\\s)?%s(,\\s+%s)*", typesRE, collectionsRE, addInfoRE);
    String allTypesRE = String.format("(\\(not\\s+seen\\)|\\(%s([,;]\\s%s)?\\))", singleTypeTypeRE, singleTypeTypeRE);
    String designatedRE = String.format("%s(%s)?", allTypesRE, designatedByRE);
    if (fotgTypePattern == null) {
        String pattern = String.format("(%s|%s)", notDesignatedRE, designatedRE);
        fotgTypePattern = Pattern.compile(pattern);
    }
    Matcher matcher = fotgTypePattern.matcher(collectionAndType);
    if (matcher.matches()) {
        fireWarningEvent("Try to synchronize type handling (at least creation) with standard type handling. E.g. use TypeInfo and according algorithms", parentEvent, 2);
        if (collectionAndType.matches(notDesignatedRE)) {
            SpecimenTypeDesignation desig = SpecimenTypeDesignation.NewInstance();
            desig.setNotDesignated(true);
            // name.addSpecimenTypeDesignation(typeSpecimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames)
            name.addTypeDesignation(desig, true);
        } else if (collectionAndType.matches(designatedRE)) {
            String designatedBy = null;
            Matcher desigMatcher = Pattern.compile(designatedByRE).matcher(collectionAndType);
            boolean hasDesignatedBy = desigMatcher.find();
            if (hasDesignatedBy) {
                designatedBy = desigMatcher.group(0);
                collectionAndType = collectionAndType.replace(designatedBy, "");
            }
            // remove brackets
            collectionAndType = collectionAndType.substring(1, collectionAndType.length() - 1);
            List<String> singleTypes = new ArrayList<String>();
            Pattern singleTypePattern = Pattern.compile("^" + singleTypeTypeRE);
            matcher = singleTypePattern.matcher(collectionAndType);
            while (matcher.find()) {
                String match = matcher.group(0);
                singleTypes.add(match);
                collectionAndType = collectionAndType.substring(match.length());
                if (!collectionAndType.isEmpty()) {
                    collectionAndType = collectionAndType.substring(1).trim();
                } else {
                    break;
                }
                matcher = singleTypePattern.matcher(collectionAndType);
            }
            List<SpecimenTypeDesignation> designations = new ArrayList<SpecimenTypeDesignation>();
            // single types
            for (String singleTypeOrig : singleTypes) {
                String singleType = singleTypeOrig;
                // type
                Pattern typePattern = Pattern.compile("^" + typesRE);
                matcher = typePattern.matcher(singleType);
                SpecimenTypeDesignationStatus typeStatus = null;
                if (matcher.find()) {
                    String typeStr = matcher.group(0);
                    singleType = singleType.substring(typeStr.length()).trim();
                    try {
                        typeStatus = SpecimenTypeParser.parseSpecimenTypeStatus(typeStr);
                    } catch (UnknownCdmTypeException e) {
                        fireWarningEvent("specimen type not recognized. Use generic type instead", parentEvent, 4);
                        typeStatus = SpecimenTypeDesignationStatus.TYPE();
                    // TODO use also type info from state
                    }
                } else {
                    typeStatus = SpecimenTypeDesignationStatus.TYPE();
                // TODO use also type info from state
                }
                // collection
                Pattern collectionPattern = Pattern.compile("^" + collectionsRE);
                matcher = collectionPattern.matcher(singleType);
                String[] collectionStrings = new String[0];
                if (matcher.find()) {
                    String collectionStr = matcher.group(0);
                    singleType = singleType.substring(collectionStr.length());
                    collectionStr = collectionStr.replace("(", "").replace(")", "").replaceAll("\\s", "");
                    collectionStrings = collectionStr.split(",");
                }
                // addInfo
                if (!singleType.isEmpty() && singleType.startsWith(", ")) {
                    singleType = singleType.substring(2);
                }
                boolean notSeen = false;
                if (singleType.equals("not seen")) {
                    singleType = singleType.replace("not seen", "");
                    notSeen = true;
                }
                if (singleType.startsWith("not seen, ")) {
                    singleType = singleType.replace("not seen, ", "");
                    notSeen = true;
                }
                boolean destroyed = false;
                if (singleType.equals("destroyed")) {
                    destroyed = true;
                    singleType = singleType.replace("destroyed", "");
                }
                boolean presumedDestroyed = false;
                if (singleType.equals("presumed destroyed")) {
                    presumedDestroyed = true;
                    singleType = singleType.replace("presumed destroyed", "");
                }
                boolean hasAddInfo = notSeen || destroyed || presumedDestroyed;
                if (!singleType.isEmpty()) {
                    String message = "SingleType was not fully read. Remaining: " + singleType + ". Original singleType was: " + singleTypeOrig;
                    fireWarningEvent(message, parentEvent, 6);
                    System.out.println(message);
                }
                if (collectionStrings.length > 0) {
                    boolean isFirst = true;
                    for (String collStr : collectionStrings) {
                        Collection collection = getCollection(state, collStr);
                        DerivedUnit unit = isFirst ? facade.innerDerivedUnit() : facade.addDuplicate(collection, null, null, null, null);
                        SpecimenTypeDesignation desig = SpecimenTypeDesignation.NewInstance();
                        designations.add(desig);
                        desig.setTypeSpecimen(unit);
                        desig.setTypeStatus(typeStatus);
                        handleSpecimenTypeAddInfo(state, notSeen, destroyed, presumedDestroyed, desig);
                        name.addTypeDesignation(desig, true);
                        isFirst = false;
                    }
                } else if (hasAddInfo) {
                    // handle addInfo if no collection data available
                    SpecimenTypeDesignation desig = SpecimenTypeDesignation.NewInstance();
                    designations.add(desig);
                    desig.setTypeStatus(typeStatus);
                    handleSpecimenTypeAddInfo(state, notSeen, destroyed, presumedDestroyed, desig);
                    name.addTypeDesignation(desig, true);
                } else {
                    fireWarningEvent("No type designation could be created as collection info was not recognized", parentEvent, 4);
                }
            }
            if (designatedBy != null) {
                if (designations.size() != 1) {
                    fireWarningEvent("Size of type designations is not exactly 1, which is expected for 'designated by'", parentEvent, 2);
                }
                designatedBy = designatedBy.trim();
                if (designatedBy.startsWith("(") && designatedBy.endsWith(")")) {
                    designatedBy = designatedBy.substring(1, designatedBy.length() - 1);
                }
                for (SpecimenTypeDesignation desig : designations) {
                    if (designatedBy.startsWith("designated by")) {
                        String titleCache = designatedBy.replace("designated by", "").trim();
                        Reference reference = ReferenceFactory.newGeneric();
                        reference.setTitleCache(titleCache, true);
                        desig.setCitation(reference);
                        // in future we could also try to parse it automatically
                        fireWarningEvent("MANUALLY: Designated by should be parsed manually: " + titleCache, parentEvent, 1);
                    } else if (designatedBy.equals("designated here")) {
                        Reference ref = state.getConfig().getSourceReference();
                        desig.setCitation(ref);
                        fireWarningEvent("MANUALLY: Microcitation should be added to 'designated here", parentEvent, 1);
                    } else if (designatedBy.startsWith("according to")) {
                        String annotationStr = designatedBy.replace("according to", "").trim();
                        Annotation annotation = Annotation.NewInstance(annotationStr, AnnotationType.EDITORIAL(), Language.ENGLISH());
                        desig.addAnnotation(annotation);
                    } else {
                        fireWarningEvent("Designated by does not match known pattern: " + designatedBy, parentEvent, 6);
                    }
                }
            }
        } else {
            fireWarningEvent("CollectionAndType unexpectedly not matching: " + collectionAndTypeOrig, parentEvent, 6);
        }
        return true;
    } else {
        if (state.getConfig().isUseFotGSpecimenTypeCollectionAndTypeOnly()) {
            fireWarningEvent("NO MATCH: " + collectionAndTypeOrig, parentEvent, 4);
        }
        return false;
    }
// // remove brackets
// if (collectionAndType.matches("^\\(.*\\)\\.?$")) {
// collectionAndType = collectionAndType.replaceAll("\\.$", "");
// collectionAndType = collectionAndType.substring(1, collectionAndType.length() - 1);
// }
// 
// String[] split = collectionAndType.split("[;,]");
// for (String str : split) {
// str = str.trim();
// boolean addToAllNamesInGroup = true;
// TypeInfo typeInfo = makeSpecimenTypeTypeInfo(str, parentEvent);
// SpecimenTypeDesignationStatus typeStatus = typeInfo.status;
// Collection collection = this.getCollection(state, typeInfo.collectionString);
// 
// // TODO improve cache strategy handling
// DerivedUnit typeSpecimen = facade.addDuplicate(collection, null, null, null, null);
// typeSpecimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
// name.addSpecimenTypeDesignation(typeSpecimen, typeStatus, null, null, null, false, addToAllNamesInGroup);
// }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Reference(eu.etaxonomy.cdm.model.reference.Reference) SpecimenTypeDesignationStatus(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus) Annotation(eu.etaxonomy.cdm.model.common.Annotation) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) List(java.util.List) ArrayList(java.util.ArrayList) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)

Example 5 with Collection

use of eu.etaxonomy.cdm.model.occurrence.Collection in project cdmlib by cybertaxonomy.

the class TypeDesignationSetFormatterTest method setUp.

@Before
public void setUp() throws Exception {
    Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
    Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
    Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
    team = Team.NewInstance(person1, person2, person3);
    book = ReferenceFactory.newBook();
    book.setAuthorship(team);
    book.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
    ntd = NameTypeDesignation.NewInstance();
    ntd.setId(1);
    TaxonName typeName = TaxonNameFactory.PARSED_BOTANICAL("Prionus coriatius L.");
    ntd.setTypeName(typeName);
    // Reference citation = ReferenceFactory.newGeneric();
    // citation.setTitleCache("Species Plantarum", true);
    // ntd.setCitation(citation);
    // ntd.addPrimaryTaxonomicSource(citation, null);
    ntd_LT = NameTypeDesignation.NewInstance();
    ntd_LT.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
    TaxonName typeName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    typeName2.setTitleCache("Prionus arealus L.", true);
    ntd_LT.setTypeName(typeName2);
    ntd_LT.setCitation(book);
    FieldUnit fu_1 = FieldUnit.NewInstance();
    fu_1.setId(1);
    fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
    FieldUnit fu_2 = FieldUnit.NewInstance();
    fu_2.setId(2);
    fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
    std_HT = SpecimenTypeDesignation.NewInstance();
    std_HT.setId(1);
    DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    Collection collection_OHA = Collection.NewInstance("OHA", null);
    specimen_HT.setCollection(collection_OHA);
    specimen_HT.setAccessionNumber("OHA 1234");
    createDerivationEvent(fu_1, specimen_HT);
    specimen_HT.getOriginals().add(fu_1);
    std_HT.setTypeSpecimen(specimen_HT);
    std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
    std_IT = SpecimenTypeDesignation.NewInstance();
    std_IT.setId(2);
    DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    specimen_IT.setTitleCache("BER", true);
    createDerivationEvent(fu_1, specimen_IT);
    std_IT.setTypeSpecimen(specimen_IT);
    std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
    std_LT = SpecimenTypeDesignation.NewInstance();
    DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    specimen_LT.setTitleCache("LEC", true);
    createDerivationEvent(fu_1, specimen_LT);
    std_LT.setTypeSpecimen(specimen_LT);
    std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
    std_LT.setCitation(book);
    std_IT_2 = SpecimenTypeDesignation.NewInstance();
    std_IT_2.setId(3);
    DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    specimen_IT_2.setTitleCache("KEW", true);
    createDerivationEvent(fu_1, specimen_IT_2);
    std_IT_2.setTypeSpecimen(specimen_IT_2);
    std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
    std_IT_3 = SpecimenTypeDesignation.NewInstance();
    std_IT_3.setId(4);
    DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    specimen_IT_3.setTitleCache("M", true);
    createDerivationEvent(fu_2, specimen_IT_3);
    std_IT_3.setTypeSpecimen(specimen_IT_3);
    std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
    mtd_HT_published = SpecimenTypeDesignation.NewInstance();
    mtd_HT_published.setId(5);
    MediaSpecimen mediaSpecimen_published = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
    Media media = Media.NewInstance();
    Reference ref = ReferenceFactory.newGeneric();
    ref.setTitleCache("A.K. & W.K (2008) Algae of the BGBM", true);
    media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "p.33"));
    mediaSpecimen_published.setMediaSpecimen(media);
    createDerivationEvent(fu_1, mediaSpecimen_published);
    mtd_HT_published.setTypeSpecimen(mediaSpecimen_published);
    mtd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
    mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
    mtd_IT_unpublished.setId(6);
    MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
    eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
    collection.setCode("B");
    mediaSpecimen_unpublished.setCollection(collection);
    mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
    createDerivationEvent(fu_1, mediaSpecimen_unpublished);
    mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
    mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) Person(eu.etaxonomy.cdm.model.agent.Person) Before(org.junit.Before)

Aggregations

Collection (eu.etaxonomy.cdm.model.occurrence.Collection)34 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)12 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)9 Institution (eu.etaxonomy.cdm.model.agent.Institution)8 Reference (eu.etaxonomy.cdm.model.reference.Reference)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Person (eu.etaxonomy.cdm.model.agent.Person)5 Media (eu.etaxonomy.cdm.model.media.Media)5 FieldUnit (eu.etaxonomy.cdm.model.occurrence.FieldUnit)5 GatheringEvent (eu.etaxonomy.cdm.model.occurrence.GatheringEvent)5 DerivationEvent (eu.etaxonomy.cdm.model.occurrence.DerivationEvent)4 MediaSpecimen (eu.etaxonomy.cdm.model.occurrence.MediaSpecimen)4 DerivedUnitFacade (eu.etaxonomy.cdm.api.facade.DerivedUnitFacade)3 URI (eu.etaxonomy.cdm.common.URI)3 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 SpecimenTypeDesignationStatus (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus)3 DeterminationEvent (eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 Namespace (org.jdom.Namespace)3