From 346d59c523f889eed417e97472457ba5e7367ffe Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:11:19 -0600 Subject: [PATCH] Additional cleanup of unused code --- bids/types/tsv.js | 39 +++++++++++++++---------------- tests/utils/map.spec.js | 35 ---------------------------- utils/array.js | 17 -------------- utils/hedData.js | 32 -------------------------- utils/hedStrings.js | 11 --------- utils/map.js | 51 ----------------------------------------- 6 files changed, 18 insertions(+), 167 deletions(-) delete mode 100644 tests/utils/map.spec.js delete mode 100644 utils/map.js diff --git a/bids/types/tsv.js b/bids/types/tsv.js index ad0f919e..c2b116d6 100644 --- a/bids/types/tsv.js +++ b/bids/types/tsv.js @@ -98,17 +98,29 @@ export class BidsTsvElement { */ hedString + /** + * The ParsedHedString representation of this row + * @type {ParsedHedString} + */ parsedHedString /** - * The file this row belongs to. + * The file this row belongs to (usually just the path). * @type {Object} */ file + /** + * The onset represented by this row or a NaN. + * @type {Number} + */ onset + /** + * The line number(s) (including the header) represented by this row. + */ tsvLine + /** * Constructor. * @@ -141,7 +153,12 @@ export class BidsTsvElement { * A row in a BIDS TSV file. */ export class BidsTsvRow extends BidsTsvElement { + /** + * The map of column name to value for this row. + * @type {Map} + */ rowCells + /** * Constructor. * @@ -156,23 +173,3 @@ export class BidsTsvRow extends BidsTsvElement { this.rowCells = rowCells } } - -/** - * A BIDS events.tsv file. - * - * @deprecated Use {@link BidsTsvFile}. Will be removed in version 4.0.0. - */ -export class BidsEventFile extends BidsTsvFile { - /** - * Constructor. - * - * @param {string} name The name of the event TSV file. - * @param {string[]} potentialSidecars The list of potential JSON sidecars. - * @param {object} mergedDictionary The merged sidecar data. - * @param {{headers: string[], rows: string[][]}|string} tsvData This file's TSV data. - * @param {object} file The file object representing this file. - */ - constructor(name, potentialSidecars, mergedDictionary, tsvData, file) { - super(name, tsvData, file, potentialSidecars, mergedDictionary) - } -} diff --git a/tests/utils/map.spec.js b/tests/utils/map.spec.js deleted file mode 100644 index 028cf2f8..00000000 --- a/tests/utils/map.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -import chai from 'chai' -const assert = chai.assert -import { describe, it } from '@jest/globals' - -import isEqual from 'lodash/isEqual' - -import * as mapUtils from '../../utils/map' - -describe('Map utility functions', () => { - describe('Non-equal duplicate filtering', () => { - it('must filter non-equal duplicates', () => { - const keyValueList = [ - ['first', 21], - ['second', 42], - ['duplicate', 63], - ['duplicate', 64], - ['third', 75], - ['fourth', 100], - ] - const expectedMap = new Map([ - ['first', 21], - ['second', 42], - ['third', 75], - ['fourth', 100], - ]) - const expectedDuplicates = [ - ['duplicate', 63], - ['duplicate', 64], - ] - const [actualMap, actualDuplicates] = mapUtils.filterNonEqualDuplicates(keyValueList, isEqual) - assert.deepStrictEqual(actualMap, expectedMap, 'Filtered map') - assert.sameDeepMembers(actualDuplicates, expectedDuplicates, 'Duplicate map') - }) - }) -}) diff --git a/utils/array.js b/utils/array.js index 0ce6ce40..cc5cfd5e 100644 --- a/utils/array.js +++ b/utils/array.js @@ -30,20 +30,3 @@ export function recursiveMap(fn, array) { return fn(array) } } - -// /** -// * Apply a function recursively to an array. -// * -// * @template T,U -// * @param {function(T, U[]): U} fn The function to apply. -// * @param {T[]} array The array to map. -// * @param {U[]} [issues] An optional array to collect issues. -// * @returns {U[]} The mapped array. -// */ -// export function recursiveMapNew(fn, array, issues = []) { -// if (Array.isArray(array)) { -// return array.map((element) => recursiveMap(fn, element, issues)) -// } else { -// return fn(array, issues) -// } -// } diff --git a/utils/hedData.js b/utils/hedData.js index 80403901..5e75e83a 100644 --- a/utils/hedData.js +++ b/utils/hedData.js @@ -1,7 +1,4 @@ import lt from 'semver/functions/lt' -// -// import ParsedHedTag from '../parser/parsedHedTag' -// import { TagSpec } from '../parser/tokenizer' /** * Determine the HED generation for a base schema version number. @@ -18,32 +15,3 @@ export const getGenerationForSchemaVersion = function (version) { return 3 } } - -// export const mergeParsingIssues = function (previousIssues, currentIssues) { -// for (const [key, currentIssue] of Object.entries(currentIssues)) { -// previousIssues[key] = previousIssues[key] !== undefined ? previousIssues[key].concat(currentIssue) : currentIssue -// } -// } - -// /** -// * Get the parent tag objects for a given short tag. -// * -// * @param {Schemas} hedSchemas The HED schema collection. -// * @param {string} shortTag A short-form HED 3 tag. -// * @returns {Map} A Map mapping a {@link Schema} to a {@link ParsedHedTag} object representing the full tag. -// */ -// export const getParsedParentTags = function (hedSchemas, shortTag) { -// const parentTags = new Map() -// for (const [schemaNickname, schema] of hedSchemas.schemas) { -// try { -// const parentTag = new ParsedHedTag( -// new TagSpec(shortTag, 0, shortTag.length - 1, schemaNickname), -// hedSchemas, -// shortTag, -// ) -// parentTags.set(schema, parentTag) -// // eslint-disable-next-line no-empty -// } catch (e) {} -// } -// return parentTags -// } diff --git a/utils/hedStrings.js b/utils/hedStrings.js index 1f77af51..9f6c7875 100644 --- a/utils/hedStrings.js +++ b/utils/hedStrings.js @@ -25,17 +25,6 @@ export const getTagSlashIndices = function (tag) { return indices } -// /** -// * Get the levels of a tag. -// * -// * @param {string} tag A HED tag string. -// * @returns {string[]} The levels of this tag. -// */ -// export const getTagLevels = function (tag) { -// const tagSlashIndices = getTagSlashIndices(tag) -// return tagSlashIndices.map((tagSlashIndex) => tag.slice(0, tagSlashIndex)) -// } - /** * Get the last part of a HED tag. * diff --git a/utils/map.js b/utils/map.js deleted file mode 100644 index 34a2aaec..00000000 --- a/utils/map.js +++ /dev/null @@ -1,51 +0,0 @@ -// import identity from 'lodash/identity' -import isEqual from 'lodash/isEqual' - -/** - * Filter non-equal duplicates from a key-value list, - * - * @template K,V - * @param {[K,V][]} list A list of key-value pairs. - * @param {function(V, V): boolean} equalityFunction An equality function for the value data. - * @returns {[Map, [K,V][]]} A map and any non-equal duplicate keys found. - */ -export const filterNonEqualDuplicates = function (list, equalityFunction = isEqual) { - const map = new Map() - const duplicateKeySet = new Set() - const duplicates = [] - for (const [key, value] of list) { - if (!map.has(key)) { - map.set(key, value) - } else if (!equalityFunction(map.get(key), value)) { - duplicates.push([key, value]) - duplicateKeySet.add(key) - } - } - for (const key of duplicateKeySet) { - const value = map.get(key) - map.delete(key) - duplicates.push([key, value]) - } - return [map, duplicates] -} - -// /** -// * Group a list by a given grouping function. -// * -// * @template T, U -// * @param {T[]} list The list to group. -// * @param {function (T): U} groupingFunction A function mapping a list value to the key it is to be grouped under. -// * @returns {Map} The grouped map. -// */ -// export const groupBy = function (list, groupingFunction = identity) { -// const groupingMap = new Map() -// for (const listEntry of list) { -// const groupingValue = groupingFunction(listEntry) -// if (groupingMap.has(groupingValue)) { -// groupingMap.get(groupingValue).push(listEntry) -// } else { -// groupingMap.set(groupingValue, [listEntry]) -// } -// } -// return groupingMap -// }