From 063f6e102e4251bb6404616abedfc87fc1531e9e Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 8 May 2024 00:28:33 -0400 Subject: [PATCH] Relinted source code. --- .eslintrc.json | 45 +++++++++++++++------------- src/matchers/TaxonomicUnitMatcher.js | 2 +- src/utils/owlterms.js | 1 - src/wrappers/CitationWrapper.js | 14 ++++----- src/wrappers/PhylogenyWrapper.js | 20 ++++++------- src/wrappers/PhylorefWrapper.js | 18 +++++------ src/wrappers/PhyxWrapper.js | 2 +- src/wrappers/SpecimenWrapper.js | 2 +- src/wrappers/TaxonNameWrapper.js | 2 +- src/wrappers/TaxonomicUnitWrapper.js | 4 +-- test/examples.js | 2 +- test/jphyloref.js | 2 +- test/phylogenies.js | 2 ++ test/phylorefs.js | 2 ++ test/scripts/phyx2owl.js | 7 +++-- test/scripts/resolve.js | 3 ++ test/specimens.js | 7 +++++ test/taxon-names.js | 5 ++++ test/taxonomic-units.js | 14 +++++++++ 19 files changed, 95 insertions(+), 59 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8ed8f7d6..e6018110 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,28 +1,31 @@ { - "extends": [ - "airbnb-base", - "plugin:mocha/recommended" - ], - "parserOptions": { - "parser": "babel-eslint", - "ecmaVersion": 6, - "sourceType": "module" - }, - "env": { - "es6": true - }, - "plugins": [ - "mocha", - "json-format" - ], - "rules": { - "prefer-destructuring": "off", - "comma-dangle": ["error", { + "extends": [ + "airbnb-base", + "plugin:mocha/recommended" + ], + "parserOptions": { + "parser": "babel-eslint", + "ecmaVersion": 6, + "sourceType": "module" + }, + "env": { + "es6": true + }, + "plugins": [ + "mocha", + "json-format" + ], + "rules": { + "prefer-destructuring": "off", + "comma-dangle": [ + "error", + { "arrays": "always-multiline", "objects": "always-multiline", "imports": "always-multiline", "exports": "always-multiline", "functions": "ignore" - }] - } + } + ] + } } diff --git a/src/matchers/TaxonomicUnitMatcher.js b/src/matchers/TaxonomicUnitMatcher.js index 692f4a85..05272001 100644 --- a/src/matchers/TaxonomicUnitMatcher.js +++ b/src/matchers/TaxonomicUnitMatcher.js @@ -87,7 +87,7 @@ class TaxonomicUnitMatcher { const externalRefs2 = wrappedTUnit2.externalReferences; return externalRefs1.some( - extref1 => externalRefs2.some( + (extref1) => externalRefs2.some( (extref2) => { if ( extref1 diff --git a/src/utils/owlterms.js b/src/utils/owlterms.js index 3fd8c653..0227bff1 100644 --- a/src/utils/owlterms.js +++ b/src/utils/owlterms.js @@ -1,4 +1,3 @@ - // Some OWL constants to be used. module.exports = { // Where is our context file located? diff --git a/src/wrappers/CitationWrapper.js b/src/wrappers/CitationWrapper.js index fff84959..6b7f8616 100644 --- a/src/wrappers/CitationWrapper.js +++ b/src/wrappers/CitationWrapper.js @@ -70,14 +70,14 @@ class CitationWrapper { // Add DOIs and URLs. additionalInfo += (this.citation.identifier || []) - .filter(id => id.type === 'doi') - .map(doi => ` doi: ${doi.id}`) + .filter((id) => id.type === 'doi') + .map((doi) => ` doi: ${doi.id}`) .join(''); - additionalInfo += (this.citation.link || []).map(link => ` URL: ${link.url}`).join(''); + additionalInfo += (this.citation.link || []).map((link) => ` URL: ${link.url}`).join(''); additionalInfo += (this.citation.identifier || []) - .filter(id => id.type === 'isbn') - .map(isbn => ` ISBN: ${isbn.id}`) + .filter((id) => id.type === 'isbn') + .map((isbn) => ` ISBN: ${isbn.id}`) .join(''); // A citation for a journal article should be different from others. @@ -86,8 +86,8 @@ class CitationWrapper { const journalIssue = (has(journal, 'number')) ? `(${journal.number})` : ''; const pages = (has(journal, 'pages')) ? `:${journal.pages}` : ''; additionalInfo += (journal.identifier || []) - .filter(id => id.type === 'issn') - .map(issn => `ISSN: ${issn.id} `) + .filter((id) => id.type === 'issn') + .map((issn) => `ISSN: ${issn.id} `) .join(''); return `${authorsAndTitle} ${journal.name || 'Unknown journal'} ${journal.volume || 'Unknown volume'}${journalIssue}${pages}${additionalInfo}`; } diff --git a/src/wrappers/PhylogenyWrapper.js b/src/wrappers/PhylogenyWrapper.js index fc9cd221..f52a49b3 100644 --- a/src/wrappers/PhylogenyWrapper.js +++ b/src/wrappers/PhylogenyWrapper.js @@ -136,8 +136,8 @@ class PhylogenyWrapper { const tunits = new Set(); nodeLabels.forEach( - nodeLabel => this.getTaxonomicUnitsForNodeLabel(nodeLabel) - .forEach(tunit => tunits.add(tunit)) + (nodeLabel) => this.getTaxonomicUnitsForNodeLabel(nodeLabel) + .forEach((tunit) => tunits.add(tunit)) ); return tunits; @@ -160,8 +160,8 @@ class PhylogenyWrapper { return Array.from( new Set( Array.from(vertices) - .map(vertex => vertex.label) - .filter(label => label !== undefined) + .map((vertex) => vertex.label) + .filter((label) => label !== undefined) ) ); } @@ -170,8 +170,8 @@ class PhylogenyWrapper { // Return the internal nodes (those with atleast one child). return Array.from(new Set( Array.from(arcs) - .map(arc => arc[0].label) // Retrieve the label of the parent vertex in this arc. - .filter(label => label !== undefined) + .map((arc) => arc[0].label) // Retrieve the label of the parent vertex in this arc. + .filter((label) => label !== undefined) )); } @@ -188,7 +188,7 @@ class PhylogenyWrapper { const allLabels = this.getNodeLabels('both'); const internalLabels = new Set(this.getNodeLabels('internal')); - return allLabels.filter(label => !internalLabels.has(label)); + return allLabels.filter((label) => !internalLabels.has(label)); } throw new Error(`Unknown nodeType: '${nodeType}'`); @@ -241,7 +241,7 @@ class PhylogenyWrapper { // Attempt pairwise matches between taxonomic units in the specifier // and associated with the node. return nodeTUnits.some( - tunit => new TaxonomicUnitMatcher(specifier, tunit).matched + (tunit) => new TaxonomicUnitMatcher(specifier, tunit).matched ); }); } @@ -399,7 +399,7 @@ class PhylogenyWrapper { Object.keys(nodeIdsByParentId).forEach((parentId) => { // What are the children of this parentId? const childrenIDs = Array.from(nodeIdsByParentId[parentId]); - const children = childrenIDs.map(childId => nodesById[childId]); + const children = childrenIDs.map((childId) => nodesById[childId]); // Is this the root node? if (has(nodesById, parentId)) { @@ -410,7 +410,7 @@ class PhylogenyWrapper { children.forEach((child) => { const childToModify = child; // Add all other sibling to node.siblings, but don't add this node itself! - childToModify.siblings = childrenIDs.filter(childId => childId !== child['@id']); + childToModify.siblings = childrenIDs.filter((childId) => childId !== child['@id']); }); }); diff --git a/src/wrappers/PhylorefWrapper.js b/src/wrappers/PhylorefWrapper.js index f6e6d180..97582def 100644 --- a/src/wrappers/PhylorefWrapper.js +++ b/src/wrappers/PhylorefWrapper.js @@ -343,7 +343,7 @@ class PhylorefWrapper { // owlterms.UNKNOWN_CODEs, then that is still usable as a default // nomenclatural code for this phyloreference. const uniqNomenCodesNoUnknowns = this.uniqNomenCodes - .filter(code => code !== owlterms.UNKNOWN_CODE); + .filter((code) => code !== owlterms.UNKNOWN_CODE); if (uniqNomenCodesNoUnknowns.length === 1) return uniqNomenCodesNoUnknowns[0]; return owlterms.UNKNOWN_CODE; @@ -576,15 +576,15 @@ class PhylorefWrapper { // selected internals -- when there are fewer, we'll just end up with the inverses // of the previous comparisons, which we'll already have covered. if (remainingInternals.length > 1 && selected.length <= remainingInternals.length) { - remainingInternals.map(newlySelected => this.createClassExpressionsForInternals( + remainingInternals.map((newlySelected) => this.createClassExpressionsForInternals( jsonld, // The new remaining is the old remaining minus the selected TU. - remainingInternals.filter(i => i !== newlySelected), + remainingInternals.filter((i) => i !== newlySelected), // The new selected is the old selected plus the selected TU. selected.concat([newlySelected]) )) .reduce((acc, val) => acc.concat(val), []) - .forEach(expr => classExprs.push(expr)); + .forEach((expr) => classExprs.push(expr)); } return classExprs; @@ -675,7 +675,7 @@ class PhylorefWrapper { logicalExpressions = externalSpecifiers.map((selectedExternal) => { // Add the internal specifiers. const intersectionExprs = internalSpecifiers.map( - sp => this.getIncludesRestrictionForTU(sp) + (sp) => this.getIncludesRestrictionForTU(sp) ); // Add the selected external specifier. @@ -689,7 +689,7 @@ class PhylorefWrapper { }); // Collect all of the externals that are not selected. - const remainingExternals = externalSpecifiers.filter(ex => ex !== selectedExternal); + const remainingExternals = externalSpecifiers.filter((ex) => ex !== selectedExternal); // Add the remaining externals, which we assume will resolve outside of // this clade. @@ -718,9 +718,7 @@ class PhylorefWrapper { // We only have internal specifiers. We therefore need to use the algorithm in // this.createClassExpressionsForInternals() to create this expression. - logicalExpressions = this.createClassExpressionsForInternals( - phylorefAsJSONLD, internalSpecifiers, [] - ); + logicalExpressions = this.createClassExpressionsForInternals(phylorefAsJSONLD, internalSpecifiers, []); } // If we have a single logical expression, we set that as an equivalentClass @@ -758,7 +756,7 @@ class PhylorefWrapper { // 2. We need to set each of these component classes to be a subclass of // this phyloreference so that it can include instances from each of the // logical expressions. - phylorefAsJSONLD.subClasses = logicalExpressions.map(classExpr => this.createComponentClass( + phylorefAsJSONLD.subClasses = logicalExpressions.map((classExpr) => this.createComponentClass( phylorefAsJSONLD, internalSpecifiers, externalSpecifiers, diff --git a/src/wrappers/PhyxWrapper.js b/src/wrappers/PhyxWrapper.js index 93097682..9dfe98c2 100644 --- a/src/wrappers/PhyxWrapper.js +++ b/src/wrappers/PhyxWrapper.js @@ -45,7 +45,7 @@ class PhyxWrapper { get defaultNomenCode() { if (has(this.phyx, 'defaultNomenclaturalCodeIRI')) return this.phyx.defaultNomenclaturalCodeIRI; const nomenCodes = (this.phyx.phylorefs || []) - .map(phyloref => new PhylorefWrapper(phyloref).defaultNomenCode); + .map((phyloref) => new PhylorefWrapper(phyloref).defaultNomenCode); const uniqNomenCodes = uniq(nomenCodes); if (uniqNomenCodes.length === 1) return uniqNomenCodes[0]; return owlterms.UNKNOWN_CODE; diff --git a/src/wrappers/SpecimenWrapper.js b/src/wrappers/SpecimenWrapper.js index 6888a00f..60ed4c21 100644 --- a/src/wrappers/SpecimenWrapper.js +++ b/src/wrappers/SpecimenWrapper.js @@ -57,7 +57,7 @@ class SpecimenWrapper { 'file://', 'urn:', ]; - if (URL_URN_PREFIXES.filter(prefix => occurID.toLowerCase().startsWith(prefix)).length > 0) { + if (URL_URN_PREFIXES.filter((prefix) => occurID.toLowerCase().startsWith(prefix)).length > 0) { return specimen; } diff --git a/src/wrappers/TaxonNameWrapper.js b/src/wrappers/TaxonNameWrapper.js index e70666fa..fb2abce9 100644 --- a/src/wrappers/TaxonNameWrapper.js +++ b/src/wrappers/TaxonNameWrapper.js @@ -138,7 +138,7 @@ class TaxonNameWrapper { // Look for the entry with the same IRI as the provided IRI. const matchingCode = codes - .find(code => (code.iri || '').toLowerCase() === nomenCode.toLowerCase()); + .find((code) => (code.iri || '').toLowerCase() === nomenCode.toLowerCase()); if (matchingCode) return matchingCode; return undefined; } diff --git a/src/wrappers/TaxonomicUnitWrapper.js b/src/wrappers/TaxonomicUnitWrapper.js index 7c63af18..dd574d11 100644 --- a/src/wrappers/TaxonomicUnitWrapper.js +++ b/src/wrappers/TaxonomicUnitWrapper.js @@ -122,7 +122,7 @@ class TaxonomicUnitWrapper { const externalReferences = this.externalReferences; if (externalReferences.length > 0) { return externalReferences - .map(externalRef => `<${externalRef}>`) + .map((externalRef) => `<${externalRef}>`) .join(' and '); } @@ -180,7 +180,7 @@ class TaxonomicUnitWrapper { 'urn:', ]; - if (URL_URN_PREFIXES.filter(prefix => nodeLabel.startsWith(prefix)).length > 0) { + if (URL_URN_PREFIXES.filter((prefix) => nodeLabel.startsWith(prefix)).length > 0) { // The node label starts with something that looks like a URL! // Treat it as an external reference. if (tunit === undefined) tunit = {}; diff --git a/test/examples.js b/test/examples.js index cb5fa532..f9f8d8f4 100644 --- a/test/examples.js +++ b/test/examples.js @@ -38,7 +38,7 @@ describe('PhyxWrapper', function () { describe('Test all correct example Phyx files', function () { const examples = fs.readdirSync(path.resolve(__dirname, './examples/correct')) - .filter(filename => filename.endsWith('.json')); + .filter((filename) => filename.endsWith('.json')); examples.forEach((example) => { const basename = path.resolve(__dirname, './examples/correct', path.parse(example).name); diff --git a/test/jphyloref.js b/test/jphyloref.js index 96da3890..0174b317 100644 --- a/test/jphyloref.js +++ b/test/jphyloref.js @@ -53,7 +53,7 @@ describe('JPhyloRef', function () { describe('test example JSON-LD files using JPhyloRef', function () { fs.readdirSync(path.resolve(__dirname, 'examples', 'correct')) - .filter(filename => filename.endsWith('.nq')) + .filter((filename) => filename.endsWith('.nq')) .forEach((filename) => { it(`testing ${filename}`, function () { this.timeout(60000); diff --git a/test/phylogenies.js b/test/phylogenies.js index 2d88f198..3ba38057 100644 --- a/test/phylogenies.js +++ b/test/phylogenies.js @@ -255,6 +255,7 @@ describe('PhylogenyWrapper', function () { expect(jsonld).to.have.property('@id'); expect(jsonld['@id']).to.equal('#providedId'); }); + it('should generate a new @id on input phylorefs', function () { const jsonld = new phyx.PhylogenyWrapper({ newick: '((Homo_sapiens, Panthera_tigris), Mus_musculus)', @@ -262,6 +263,7 @@ describe('PhylogenyWrapper', function () { expect(jsonld).to.have.property('@id'); expect(jsonld['@id']).to.equal('#phylogeny0'); }); + it('should generate the phylogeny in JSON-LD as expected', function () { const expectedResults = [ { diff --git a/test/phylorefs.js b/test/phylorefs.js index d6561a85..fc47aaf8 100644 --- a/test/phylorefs.js +++ b/test/phylorefs.js @@ -258,6 +258,7 @@ describe('PhylorefWrapper', function () { expect(jsonld).to.have.property('@id'); expect(jsonld['@id']).to.equal('#providedId'); }); + it('should generate a new @id on input phylorefs', function () { const jsonld = new phyx.PhylorefWrapper({ internalSpecifiers: [specifier1], @@ -266,6 +267,7 @@ describe('PhylorefWrapper', function () { expect(jsonld).to.have.property('@id'); expect(jsonld['@id']).to.equal('#phyloref0'); }); + it('should generate the expected equivClass expression for 1 int, 1 ext phyloref', function () { const jsonld = new phyx.PhylorefWrapper({ internalSpecifiers: [specifier1], diff --git a/test/scripts/phyx2owl.js b/test/scripts/phyx2owl.js index e73161bc..ddda0b7f 100644 --- a/test/scripts/phyx2owl.js +++ b/test/scripts/phyx2owl.js @@ -26,6 +26,7 @@ describe(PHYX2OWL_JS, function () { expect(result.stdout).to.be.empty; expect(result.stderr).to.contain('No input files provided.'); }); + it('should support `--help`', function () { const result = child.spawnSync(PHYX2OWL_JS, ['--help'], { encoding: 'utf-8', @@ -35,6 +36,7 @@ describe(PHYX2OWL_JS, function () { expect(result.stderr).to.be.empty; expect(result.stdout).to.contain('phyx2owl.js [files or directories to convert into OWL ontologies]'); }); + it('should be able to convert `brochu_2003.json`', function () { const PHYX_FILE = path.resolve(__dirname, '../examples/correct/brochu_2003.json'); const NQ_FILE = path.resolve(__dirname, '../examples/correct/brochu_2003.nq'); @@ -62,10 +64,11 @@ describe(PHYX2OWL_JS, function () { const nqExpected = fs.readFileSync(NQ_FILE, 'utf8'); expect(nqGenerated).to.equal(nqExpected); }); + it('should be able to convert the entire `test/examples/correct` directory', function () { const EXAMPLE_DIR = path.resolve(__dirname, '../examples/correct'); const jsonFilesInExamples = fs.readdirSync(EXAMPLE_DIR, 'utf8') - .filter(fileName => fileName.toLowerCase().endsWith('.json')); + .filter((fileName) => fileName.toLowerCase().endsWith('.json')); const result = child.spawnSync(PHYX2OWL_JS, [EXAMPLE_DIR, '--base-iri', 'http://example.org/phyx.js/example#'], { encoding: 'utf-8', @@ -82,7 +85,7 @@ describe(PHYX2OWL_JS, function () { // Make sure that the generated files *look* like JSON-LD files. fs.readdirSync(EXAMPLE_DIR, 'utf8') - .filter(fileName => fileName.toLowerCase().endsWith('.owl')) + .filter((fileName) => fileName.toLowerCase().endsWith('.owl')) .forEach((owlFilename) => { const nqGenerated = fs.readFileSync(path.resolve(EXAMPLE_DIR, owlFilename), 'utf8'); diff --git a/test/scripts/resolve.js b/test/scripts/resolve.js index 8cd97a97..8b620436 100644 --- a/test/scripts/resolve.js +++ b/test/scripts/resolve.js @@ -27,6 +27,7 @@ describe('bin/resolve.js', function () { expect(result.stdout).to.be.empty; expect(result.stderr).to.contain('No input files provided.'); }); + it('should support `--help`', function () { const result = child.spawnSync(RESOLVE_JS, ['--help'], { encoding: 'utf-8', @@ -36,6 +37,7 @@ describe('bin/resolve.js', function () { expect(result.stderr).to.be.empty; expect(result.stdout).to.contain('resolve.js [files to resolve on the Open Tree of Life]'); }); + it('should provide the expected results on the `brochu_2003.json` example file', function () { var resultObj; // eslint-disable-line no-var @@ -77,6 +79,7 @@ describe('bin/resolve.js', function () { error: 'no_mrca_found:400', }); }); + it('should correctly report errors with certain phyloreferences', function () { var resultObj; // eslint-disable-line no-var diff --git a/test/specimens.js b/test/specimens.js index 5ef11b58..643e2053 100644 --- a/test/specimens.js +++ b/test/specimens.js @@ -21,6 +21,7 @@ describe('SpecimenWrapper', function () { expect(wrapped).to.be.an.instanceOf(phyx.SpecimenWrapper); expect(wrapped.occurrenceID).to.be.undefined; }); + it('should be able to extract an occurenceID and catalogNumber from simple specimen IDs', function () { const wrapper = new phyx.SpecimenWrapper({ occurrenceID: 'Wall 2527, Fiji (uc)', @@ -30,6 +31,7 @@ describe('SpecimenWrapper', function () { expect(wrapper.catalogNumber).to.equal('Wall 2527, Fiji (uc)'); expect(wrapper.basisOfRecord).to.equal('PreservedSpecimen'); }); + it('should extract institutionCode and catalogNumber from a institutionCode:catalogNumber combination', function () { const wrapper = new phyx.SpecimenWrapper({ occurrenceID: 'FMNH:PR 2081', @@ -40,6 +42,7 @@ describe('SpecimenWrapper', function () { expect(wrapper.catalogNumber).to.equal('PR 2081'); expect(wrapper.basisOfRecord).to.equal('PreservedSpecimen'); }); + it('should extract occurenceID, institutionCode and catalogNumber from Darwin Core triples', function () { const wrapper = new phyx.SpecimenWrapper({ occurrenceID: 'FMNH:PR:2081', @@ -50,12 +53,14 @@ describe('SpecimenWrapper', function () { expect(wrapper.catalogNumber).to.equal('2081'); expect(wrapper.basisOfRecord).to.be.undefined; }); + it('should be able to extract the same occurrenceID from different representations', function () { expect(new phyx.SpecimenWrapper({ occurrenceID: 'urn:catalog:::MVZ225749' }).occurrenceID) .to.equal('urn:catalog:::MVZ225749'); expect(new phyx.SpecimenWrapper({ catalogNumber: 'MVZ225749' }).occurrenceID) .to.equal('urn:catalog:::MVZ225749'); }); + it('should not attempt to split a URN into occurenceID, institutionCode and catalogNumber', function () { const wrapper = new phyx.SpecimenWrapper({ occurrenceID: 'urn:lsid:biocol.org:col:34777', @@ -65,6 +70,7 @@ describe('SpecimenWrapper', function () { expect(wrapper.collectionCode).to.be.undefined; expect(wrapper.catalogNumber).to.be.undefined; }); + it('should not attempt to split a URL into occurenceID, institutionCode and catalogNumber', function () { const wrapper = new phyx.SpecimenWrapper({ occurrenceID: 'http://arctos.database.museum/guid/MVZ:Herp:148929?seid=886464', @@ -74,6 +80,7 @@ describe('SpecimenWrapper', function () { expect(wrapper.collectionCode).to.be.undefined; expect(wrapper.catalogNumber).to.be.undefined; }); + it('should be able to create a specimen JSON record from an occurrence ID', function () { const specimen = phyx.SpecimenWrapper.fromOccurrenceID('FMNH:PR:2081'); expect(specimen.occurrenceID).to.equal('FMNH:PR:2081'); diff --git a/test/taxon-names.js b/test/taxon-names.js index 01c58e2b..427220f3 100644 --- a/test/taxon-names.js +++ b/test/taxon-names.js @@ -20,6 +20,7 @@ describe('TaxonNameWrapper', function () { expect(wrapper).to.be.an.instanceOf(phyx.TaxonNameWrapper); expect(wrapper.nameComplete).to.be.undefined; }); + it('should be able to parse uninomial names as such', function () { const wrapper = new phyx.TaxonNameWrapper({ nameComplete: 'Mus', @@ -29,6 +30,7 @@ describe('TaxonNameWrapper', function () { expect(wrapper.genusPart).to.be.undefined; expect(wrapper.specificEpithet).to.be.undefined; }); + it('should be able to parse binomial names into genus and specific epithet', function () { const wrapper = new phyx.TaxonNameWrapper({ nameComplete: 'Mus musculus', @@ -37,6 +39,7 @@ describe('TaxonNameWrapper', function () { expect(wrapper.genusPart).to.equal('Mus'); expect(wrapper.specificEpithet).to.equal('musculus'); }); + it('should be able to parse trinomial names into genus, specific epithet and infraspecific epithet', function () { const wrapper = new phyx.TaxonNameWrapper({ nameComplete: 'Mus musculus domesticus', @@ -46,6 +49,7 @@ describe('TaxonNameWrapper', function () { expect(wrapper.specificEpithet).to.equal('musculus'); expect(wrapper.infraspecificEpithet).to.equal('domesticus'); }); + it('should ignore authority after a binomial name', function () { const taxonName = phyx.TaxonNameWrapper.fromVerbatimName('Mus musculus Linnaeus, 1758'); expect(taxonName.nameComplete).to.equal('Mus musculus'); @@ -54,6 +58,7 @@ describe('TaxonNameWrapper', function () { expect(taxonName.infraspecificEpithet).to.be.undefined; expect(taxonName.uninomial).to.be.undefined; }); + it('should be able to use default nomenclatural codes', function () { const taxonName = phyx.TaxonNameWrapper.fromVerbatimName('Mus musculus Linnaeus, 1758', owlterms.ICZN_CODE); expect(taxonName.nameComplete).to.equal('Mus musculus'); diff --git a/test/taxonomic-units.js b/test/taxonomic-units.js index aa8b3dcf..60e450e3 100644 --- a/test/taxonomic-units.js +++ b/test/taxonomic-units.js @@ -48,6 +48,7 @@ describe('TaxonomicUnitWrapper', function () { expect(wrapper.label).to.be.undefined; }); }); + describe('#label given a taxonomic unit', function () { it('should return a wrapped scientific name', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ @@ -59,6 +60,7 @@ describe('TaxonomicUnitWrapper', function () { }); expect(wrapper.label).to.equal('Ornithorhynchus anatinus (Shaw, 1799)'); }); + it('should return a wrapped specimen identifier preceded by "Specimen"', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@type': phyx.TaxonomicUnitWrapper.TYPE_SPECIMEN, @@ -66,6 +68,7 @@ describe('TaxonomicUnitWrapper', function () { }); expect(wrapper.label).to.equal('Specimen MVZ 225749'); }); + it('should return specimens with an occurrenceID as well as a taxon concept', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@type': [ @@ -76,6 +79,7 @@ describe('TaxonomicUnitWrapper', function () { }); expect(wrapper.label).to.equal('Specimen MVZ 225749 identified as Rana luteiventris'); }); + it('should ignore occurrence ID if typed as a taxon concept', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@type': phyx.TaxonomicUnitWrapper.TYPE_TAXON_CONCEPT, @@ -84,6 +88,7 @@ describe('TaxonomicUnitWrapper', function () { }); expect(wrapper.label).to.equal('Rana luteiventris'); }); + it('should return a wrapped external reference by surrounding it with "<>"', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@id': [ @@ -92,6 +97,7 @@ describe('TaxonomicUnitWrapper', function () { }); expect(wrapper.label).to.equal(''); }); + it('should provide both taxon name and occurrence ID in label, but ignore external reference', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@id': [ @@ -104,6 +110,7 @@ describe('TaxonomicUnitWrapper', function () { expect(wrapper.label).to.equal('Specimen MVZ 225749 identified as Rana luteiventris'); }); }); + describe('#fromLabel', function () { it('should return empty lists when inputs are empty or undefined', function () { expect(phyx.TaxonomicUnitWrapper.fromLabel()).to.be.undefined; @@ -112,6 +119,7 @@ describe('TaxonomicUnitWrapper', function () { expect(phyx.TaxonomicUnitWrapper.fromLabel('')).to.be.undefined; expect(phyx.TaxonomicUnitWrapper.fromLabel(' ')).to.be.undefined; }); + it('when given a scientific name, it should return a list of a single TU wrapping a scientific name', function () { expect(phyx.TaxonomicUnitWrapper.fromLabel('Rana luteiventris MVZ225749')) .to.be.deep.equal({ @@ -126,6 +134,7 @@ describe('TaxonomicUnitWrapper', function () { }, }); }); + it('when given a scientific name separated with underscores, it should return a list of a single TU wrapping the scientific name', function () { expect(phyx.TaxonomicUnitWrapper.fromLabel('Rana_luteiventris_MVZ_225749')) .to.be.deep.equal({ @@ -141,6 +150,7 @@ describe('TaxonomicUnitWrapper', function () { }); }); }); + describe('#asOWLEquivClass', function () { it('when given a taxon concept, only the complete name should be present in the equivClass', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ @@ -157,6 +167,7 @@ describe('TaxonomicUnitWrapper', function () { }, }); }); + it('when given a specimen, only the occurrence ID should be present in the equivClass', function () { const wrapper = new phyx.TaxonomicUnitWrapper({ '@type': phyx.TaxonomicUnitWrapper.TYPE_SPECIMEN, @@ -207,6 +218,7 @@ describe('TaxonomicUnitMatcher', function () { expect(new phyx.TaxonomicUnitMatcher(tunit1, tunit2).matchByNameComplete()).to.be.true; }); }); + describe('#matchByExternalReferences', function () { it('should be able to match tunit3 and tunit4 by external references', function () { expect(new phyx.TaxonomicUnitMatcher(tunit3, tunit4).matchByExternalReferences()).to.be.true; @@ -214,6 +226,7 @@ describe('TaxonomicUnitMatcher', function () { expect(new phyx.TaxonomicUnitMatcher(tunit3, tunit4).matchByNameComplete()).to.be.false; }); }); + describe('#matchByOccurrenceID', function () { it('should be able to match tunit2 and tunit3 by specimen identifiers', function () { expect(new phyx.TaxonomicUnitMatcher(tunit2, tunit3).matchByExternalReferences()).to.be.false; @@ -221,6 +234,7 @@ describe('TaxonomicUnitMatcher', function () { expect(new phyx.TaxonomicUnitMatcher(tunit2, tunit3).matchByNameComplete()).to.be.false; }); }); + describe('#matched and #matchReason', function () { it('should match tunit1 and tunit2 on the basis of identical complete names', function () { const matcher = new phyx.TaxonomicUnitMatcher(tunit1, tunit2);