diff --git a/src/wrappers/PhylorefWrapper.js b/src/wrappers/PhylorefWrapper.js index f64b6573..e287a0c9 100644 --- a/src/wrappers/PhylorefWrapper.js +++ b/src/wrappers/PhylorefWrapper.js @@ -43,7 +43,7 @@ class PhylorefWrapper { normalizedPhyloref.internalSpecifiers = (phyloref.internalSpecifiers || []) .map(TaxonomicUnitWrapper.normalize); - normalizedPhyloref.externalSpecifiers = (phyloref.internalSpecifiers || []) + normalizedPhyloref.externalSpecifiers = (phyloref.externalSpecifiers || []) .map(TaxonomicUnitWrapper.normalize); return normalizedPhyloref; diff --git a/src/wrappers/SpecimenWrapper.js b/src/wrappers/SpecimenWrapper.js index 6888a00f..ce8ab8fb 100644 --- a/src/wrappers/SpecimenWrapper.js +++ b/src/wrappers/SpecimenWrapper.js @@ -29,6 +29,25 @@ class SpecimenWrapper { this.specimen = specimen; } + /** + * Normalize the specified specimen. + * @param specimen A specimen to be normalized. + */ + static normalize(specimen) { + const wrapped = new SpecimenWrapper(specimen); + const normalizedSpecimen = { + '@type': SpecimenWrapper.TYPE_SPECIMEN, + label: wrapped.label, + 'dwc:basisOfRecord': wrapped.basisOfRecord, + occurrenceID: wrapped.occurrenceID, + catalogNumber: wrapped.catalogNumber, + institutionCode: wrapped.institutionCode, + collectionCode: wrapped.collectionCode, + }; + if ('@id' in specimen) normalizedSpecimen['@id'] = specimen['@id']; + return normalizedSpecimen; + } + /** * Parse the provided occurrence ID. The two expected formats are: * - 'urn:catalog:[institutionCode]:[collectionCode]:[catalogNumber]' diff --git a/src/wrappers/TaxonConceptWrapper.js b/src/wrappers/TaxonConceptWrapper.js index 9e4f3d19..91b21998 100644 --- a/src/wrappers/TaxonConceptWrapper.js +++ b/src/wrappers/TaxonConceptWrapper.js @@ -34,6 +34,23 @@ class TaxonConceptWrapper { this.defaultNomenCode = defaultNomenCode; } + /** + * Normalize the specified taxon concept. + * @param tc A taxon concept to be normalized. + */ + static normalize(tc) { + const wrapped = new TaxonConceptWrapper(tc); + const normalizedTC = { + '@type': TaxonConceptWrapper.TYPE_TAXON_CONCEPT, + label: wrapped.label, + hasName: TaxonNameWrapper.normalize(wrapped.taxonName), + nameString: wrapped.taxonName.nameComplete, + accordingTo: wrapped.accordingTo, + }; + if ('@id' in tc) normalizedTC['@id'] = tc['@id']; + return normalizedTC; + } + /** * Return the taxon name of this taxon concept (if any) as an object. */ @@ -89,10 +106,10 @@ class TaxonConceptWrapper { */ get accordingTo() { // Do we have any accordingTo information? - if (has(this.tunit, 'accordingTo')) return this.type.accordingTo; + if (has(this.tunit, 'accordingTo')) return this.tunit.accordingTo; // Do we have an accordingToString? - if (has(this.tunit, 'accordingToString')) return this.type.accordingToString; + if (has(this.tunit, 'accordingToString')) return this.tunit.accordingToString; // If not, we have no accodingTo information! return undefined; @@ -106,10 +123,10 @@ class TaxonConceptWrapper { */ get accordingToString() { // Do we have any accordingTo information? - if (has(this.tunit, 'accordingTo')) return JSON.stringify(this.type.accordingTo); + if (has(this.tunit, 'accordingTo')) return JSON.stringify(this.tunit.accordingTo); // Do we have an accordingToString? - if (has(this.tunit, 'accordingToString')) return this.type.accordingToString; + if (has(this.tunit, 'accordingToString')) return this.tunit.accordingToString; // If not, we have no accodingTo information! return undefined; diff --git a/src/wrappers/TaxonNameWrapper.js b/src/wrappers/TaxonNameWrapper.js index e70666fa..8dcfe3fd 100644 --- a/src/wrappers/TaxonNameWrapper.js +++ b/src/wrappers/TaxonNameWrapper.js @@ -143,6 +143,25 @@ class TaxonNameWrapper { return undefined; } + /** + * Normalize the specified taxon name. + * @param txname A taxon name to be normalized. + */ + static normalize(txname) { + const wrapped = new TaxonNameWrapper(txname); + const normalizedTxname = { + '@type': TaxonNameWrapper.TYPE_TAXON_NAME, + nomenclaturalCode: wrapped.nomenclaturalCode, + label: wrapped.label, + nameComplete: wrapped.nameComplete, + genusPart: wrapped.genusPart, + specificEpithet: wrapped.specificEpithet, + infraspecificEpithet: wrapped.infraspecificEpithet, + }; + if ('@id' in txname) normalizedTxname['@id'] = txname['@id']; + return normalizedTxname; + } + /** * Returns the nomenclatural code of this taxon name. */ diff --git a/src/wrappers/TaxonomicUnitWrapper.js b/src/wrappers/TaxonomicUnitWrapper.js index 7c63af18..26c7dcb2 100644 --- a/src/wrappers/TaxonomicUnitWrapper.js +++ b/src/wrappers/TaxonomicUnitWrapper.js @@ -59,6 +59,25 @@ class TaxonomicUnitWrapper { this.defaultNomenCode = defaultNomenCode; } + /** + * Normalize the specified taxonomic unit. + * @param tunit A taxonomic unit to be normalized. + */ + static normalize(tunit) { + const wrapped = new TaxonomicUnitWrapper(tunit); + if (wrapped.taxonConcept) { + return TaxonConceptWrapper.normalize(tunit); + } + if (wrapped.specimen) { + return SpecimenWrapper.normalize(tunit); + } + if (wrapped.externalReferences) { + // External references should only have an `@id`. + return tunit; + } + return tunit; + } + /** * What type of specifier is this? This is an array that could contain multiple * classes, but should contain one of: