Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions spec_tests/jsonTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ describe('HED validation using JSON tests', () => {
assert.instanceOf(parsedTsv, Map, `${events} cannot be parsed`)
const bidsTsv = new BidsTsvFile(
`events`,
parsedTsv,
{ relativePath: 'combo test tsv' },
[],
parsedTsv,
JSON.parse(side),
defManager,
)
Expand All @@ -191,7 +190,7 @@ describe('HED validation using JSON tests', () => {
defManager.addDefinitions(defList)
const parsedTsv = parseTSV(events)
assert.instanceOf(parsedTsv, Map, `${events} cannot be parsed`)
const bidsTsv = new BidsTsvFile(`events`, parsedTsv, { relativePath: 'events test' }, [], {}, defManager)
const bidsTsv = new BidsTsvFile(`events`, { relativePath: 'events test' }, parsedTsv, {}, defManager)
eventsIssues = bidsTsv.validate(hedSchema)
} catch (e) {
eventsIssues = [convertIssue(e)]
Expand All @@ -206,7 +205,7 @@ describe('HED validation using JSON tests', () => {
try {
const defManager = new DefinitionManager()
defManager.addDefinitions(defList)
const bidsSide = new BidsSidecar(`sidecar`, JSON.parse(side), { relativePath: 'bidsFile test' }, defManager)
const bidsSide = new BidsSidecar(`sidecar`, { relativePath: 'bidsFile test' }, JSON.parse(side), defManager)
issues = bidsSide.validate(hedSchema)
} catch (e) {
issues = [convertIssue(e)]
Expand All @@ -224,7 +223,7 @@ describe('HED validation using JSON tests', () => {
defManager.addDefinitions(defList)
const parsedTsv = parseTSV(hTsv)
assert.instanceOf(parsedTsv, Map, `${str} cannot be parsed`)
const bidsTsv = new BidsTsvFile(`string`, parsedTsv, { relativePath: 'string test tsv' }, [], {}, defManager)
const bidsTsv = new BidsTsvFile(`string`, { relativePath: 'string test tsv' }, parsedTsv, {}, defManager)
stringIssues = bidsTsv.validate(hedSchema)
} catch (e) {
stringIssues = [convertIssue(e)]
Expand Down
4 changes: 2 additions & 2 deletions src/bids/tsvParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const isContentfulRow = (row) => row && !/^\s*$/.test(row)
* Parse a TSV file.
*
* @param {string} contents The contents of a TSV file.
* @returns {Map[]} The parsed contents of the TSV file.
* @returns {Map} The parsed contents of the TSV file.
*/
export function parseTSV(contents) {
const columns = new Map()
Expand All @@ -40,7 +40,7 @@ export function parseTSV(contents) {
* Convert parsed TSV file data from the old BIDS format to the new BIDS format.
*
* @param {{headers: string[], rows: string[][]}} oldParsedTsv Parsed TSV data using the old format
* @returns {Map[]} The parsed contents of the TSV file, using the new format.
* @returns {Map} The parsed contents of the TSV file, using the new format.
*/
export function convertParsedTSVData(oldParsedTsv) {
const columns = new Map()
Expand Down
23 changes: 8 additions & 15 deletions src/bids/types/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export class BidsFile {
* @type {string}
*/
name

/**
* The file object representing this file data.
* The Object representing this file data.
* This is used to generate {@link BidsIssue} objects.
* @type {object}
* @type {Object}
*/

file
/**
* The validator class used to validate this file.
Expand All @@ -25,32 +27,23 @@ export class BidsFile {
/**
*
* @param {string} name - The name of the file -- used for messages.
* @param {object} file - The representation of the file for error messages.
* @param validatorClass
* @param {Object} file - The representation of the file for error messages.
* @param {BidsValidator} validatorClass - The validator class corresponding to this file.
*/
constructor(name, file, validatorClass) {
this.name = name
this.file = file
this._validatorClass = validatorClass
}

/**
* Determine whether this file has any HED data.
*
* @returns {boolean} - True if this file has HED data.
*/
hasHedData() {
return false
}

/**
* Validate this validator's tsv file.
*
* @param {Schemas} schemas - The HED schemas used to validate this file.
* @returns {BidsIssue[]} - Any issues found during validation of this TSV file.
*/
validate(schemas) {
if (!this.hasHedData()) {
if (!this.hasHedData) {
return []
}
if (!schemas) {
Expand All @@ -72,7 +65,7 @@ export class BidsFile {

/**
* The validator class used to validate this file.
* @returns {*}
* @returns {BidsValidator}
*/
get validatorClass() {
return this._validatorClass
Expand Down
30 changes: 21 additions & 9 deletions src/bids/types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ const ILLEGAL_SIDECAR_KEYS = new Set(['hed', 'n/a'])
export class BidsJsonFile extends BidsFile {
/**
* This file's JSON data.
* @type {object}
* @type {Object}
*/
jsonData

constructor(name, jsonData, file) {
/**
*
* @param {string} name - The name of the JSON file.
* @param {Object} file - The object representing this file.
* @param {Object} jsonData - The JSON data for this file.
*/
constructor(name, file, jsonData) {
super(name, file, BidsHedSidecarValidator)
this.jsonData = jsonData
}
Expand All @@ -32,39 +38,45 @@ export class BidsSidecar extends BidsJsonFile {
* @type {Map}
*/
sidecarKeys

/**
* The extracted HED data for this bidsFile (string --> string | Object: string, string
* @type {Map}
*/
hedData

/**
* The parsed HED data for this bidsFile (string --> ParsedHedString | Map: string --> ParsedHedString
* The parsed HED data for this bidsFile (string --> ParsedHedString | Map: string --> ParsedHedString).
* @type {Map}
*/
parsedHedData

/**
* The extracted HED value strings.
* @type {string[]}
*/
hedValueStrings

/**
* The extracted HED categorical strings.
* @type {string[]}
*/
hedCategoricalStrings

/**
* The mapping of column splice references (string --> Set of string)
* The mapping of column splice references (string --> Set of string).
* @type {Map}
*/
columnSpliceMapping

/**
* The set of column splice references.
* @type {Set<string>}
*/
columnSpliceReferences

/**
* The object that manages definitions
* The object that manages definitions.
* @type {DefinitionManager}
*/
definitions
Expand All @@ -73,12 +85,12 @@ export class BidsSidecar extends BidsJsonFile {
* Constructor.
*
* @param {string} name The name of the bidsFile file.
* @param {Object} sidecarData The raw JSON data.
* @param {Object} file The file object representing this file.
* @param {Object} sidecarData The raw JSON data.
* @param {DefinitionManager } defManager - The external definitions to use
*/
constructor(name, sidecarData = {}, file, defManager = null) {
super(name, sidecarData, file)
constructor(name, file, sidecarData = {}, defManager = undefined) {
super(name, file, sidecarData)
this.columnSpliceMapping = new Map()
this.columnSpliceReferences = new Set()
this._setDefinitions(defManager)
Expand Down Expand Up @@ -168,7 +180,7 @@ export class BidsSidecar extends BidsJsonFile {
*
* @returns {boolean}
*/
hasHedData() {
get hasHedData() {
return this.sidecarKeys.size > 0
}

Expand Down
36 changes: 13 additions & 23 deletions src/bids/types/tsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ import { IssueError } from '../../issues/issues'
export class BidsTsvFile extends BidsFile {
/**
* This file's parsed TSV data.
* @type {Map[]}
* @type {Map}
*/
parsedTsv
/**
* HED strings in the "HED" column of the TSV data.
* @type {string[]}
*/
hedColumnHedStrings
/**
* The list of potential JSON sidecars.
* @type {string[]}
*/
potentialSidecars

/**
* The pseudo-bidsFile object representing the merged bidsFile data.
* @type {BidsSidecar}
Expand All @@ -34,16 +30,13 @@ export class BidsTsvFile extends BidsFile {
/**
* Constructor.
*
* @todo This interface is provisional and subject to modification in version 4.0.0.
*
* @param {string} name The name of the TSV file.
* @param {{headers: string[], rows: string[][]|Map[]|string} tsvData This file's TSV data.
* @param {object} file The file object representing this file.
* @param {string[]} potentialSidecars The list of potential JSON sidecars.
* @param {object} mergedDictionary The merged bidsFile data.
* @param {DefinitionManager} defManager
*/
constructor(name, tsvData, file, potentialSidecars = [], mergedDictionary = {}, defManager) {
* @param {string} name - The name of the TSV file.
* @param {Object} file - The file object representing this file.
* @param {{headers: string[], rows: string[][]}|Map|string} tsvData - This file's TSV data.
* @param {Object} mergedDictionary - The merged bidsFile data.
* @param {DefinitionManager} defManager - The definition manager for this file.
*/
constructor(name, file, tsvData, mergedDictionary = {}, defManager = undefined) {
super(name, file, BidsHedTsvValidator)

if (typeof tsvData === 'string') {
Expand All @@ -56,8 +49,7 @@ export class BidsTsvFile extends BidsFile {
IssueError.generateAndThrow('internalError', { message: 'parsedTsv has an invalid type' })
}

this.potentialSidecars = potentialSidecars
this.mergedSidecar = new BidsSidecar(name, mergedDictionary, this.file, defManager)
this.mergedSidecar = new BidsSidecar(name, this.file, mergedDictionary, defManager)
this._parseHedColumn()
}

Expand All @@ -73,12 +65,10 @@ export class BidsTsvFile extends BidsFile {
/**
* Determine whether this file has any HED data.
*
* @todo To be replaced with property in version 4.0.0.
*
* @returns {boolean}
*/
hasHedData() {
return this.parsedTsv.has('HED') || this.mergedSidecar.hasHedData()
get hasHedData() {
return this.parsedTsv.has('HED') || this.mergedSidecar.hasHedData
}

/**
Expand Down Expand Up @@ -139,7 +129,7 @@ export class BidsTsvElement {
}

/**
* Override of {@link Object.prototype.toString}.
* Override of {@link object.prototype.toString}.
*
* @returns {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/bids/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Determine whether a bidsFile value has HED data.
*
* @param {object} sidecarValue A BIDS bidsFile value.
* @param {Object} sidecarValue A BIDS bidsFile value.
* @returns {boolean} Whether the bidsFile value has HED data.
*/
export const sidecarValueHasHed = function (sidecarValue) {
Expand Down
2 changes: 1 addition & 1 deletion src/bids/validator/tsvValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export class BidsHedTsvParser {
columnMap.set('HED', rowCells.get('HED'))
}

if (!this.tsvFile.mergedSidecar.hasHedData()) {
if (!this.tsvFile.mergedSidecar.hasHedData) {
return columnMap
}

Expand Down
32 changes: 1 addition & 31 deletions src/parser/definitionChecker.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { generateIssue } from '../issues/issues'
import { getTagListString } from './parseUtils'
import Set from 'lodash/_Set'

const DEFINITION_TAGS = new Set(['Definition', 'Def', 'Def-expand'])

const DEF_GROUP_TAGS = new Set(['Definition', 'Def-expand'])

export class DefinitionChecker {
/**
* Check Def-expand or definition syntax for compatible tags and number of groups
* @param {ParsedHedString} hedString - A group to check for Def-expand syntax.
*/

constructor(hedString) {
this.hedString = hedString
this.definitionTags = this.hedString.tags.filter((tag) => tag.schemaTag.name === 'Definition')
Expand Down Expand Up @@ -158,33 +157,4 @@ export class DefinitionChecker {
}
return []
}

// _checkDefinitionSyntax(parsedString) {
//
// // This checks whether there are any definitions in the string if the definition is allowed.
// const definitionContextIssues = this._checkDefinitionContext(parsedString)
// if (definitionContextIssues.length > 0) {
// return definitionContextIssues
// }
//
// // If
// const definitionStructureIssues = this._checkDefinitionStructure(parsedString)
// return definitionStructureIssues
// }
//
//
//

// return issues
// const definitionTags = parsedString.tags.filter((tag) => tag.schemaTag.name === 'Definition')
// if (definitionTags.length > 0) {
// return [
// generateIssue('illegalDefinitionContext', {
// definition: getTagListString(definitionTags),
// string: parsedString.hedString,
// }),
// ]
// }
// return []
// }
}
2 changes: 1 addition & 1 deletion src/parser/parsedHedTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TagConverter from './tagConverter'
import { ReservedChecker } from './reservedChecker'

const TWO_LEVEL_TAGS = new Set(['Definition', 'Def', 'Def-expand'])
const allowedRegEx = /^[^{}\,]*$/
const allowedRegEx = /^[^{},]*$/

/**
* A parsed HED tag.
Expand Down
2 changes: 1 addition & 1 deletion src/parser/reservedChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ReservedChecker {
* Perform syntactical checks on the provided HED string to detect violations.
*
* @param {ParsedHedString} hedString - The HED string to be checked.
* @returns {Issue[]} An array of issues if violations are found otherwise, an empty array.
* @returns {Issue[]} - An array of issues if violations are found otherwise, an empty array.
*/
checkHedString(hedString) {
const checks = [
Expand Down
2 changes: 1 addition & 1 deletion src/schema/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Schema {
/**
* Constructor.
*
* @param {object} xmlData The schema XML data.
* @param {Object} xmlData The schema XML data.
* @param {SchemaEntries} entries A collection of schema entries.
*/
constructor(xmlData, entries) {
Expand Down
Loading
Loading