Skip to content

Commit

Permalink
Corrected handling of delay with temporal tag
Browse files Browse the repository at this point in the history
  • Loading branch information
VisLab committed Jan 2, 2025
1 parent 45d3bcc commit c987cc3
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 260 deletions.
5 changes: 2 additions & 3 deletions bids/validator/sidecarValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ export class BidsHedSidecarValidator extends BidsValidator {
for (const [sidecarKeyName, hedData] of this.bidsFile.parsedHedData) {
if (hedData instanceof ParsedHedString) {
// Value options have HED as string.
issues.push(...this._checkDetails(sidecarKeyName, hedData, true))
issues.push(...this._checkDetails(sidecarKeyName, hedData))
} else if (hedData instanceof Map) {
// Categorical options have HED as a Map.
for (const valueString of hedData.values()) {
const placeholdersAllowed = this.bidsFile.sidecarKeys.get(sidecarKeyName).hasDefinitions
issues.push(...this._checkDetails(sidecarKeyName, valueString, placeholdersAllowed))
issues.push(...this._checkDetails(sidecarKeyName, valueString))
}
} else {
IssueError.generateAndThrow('internalConsistencyError', {
Expand Down
2 changes: 1 addition & 1 deletion common/issues/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default {
tooManyGroupTopTags: {
hedCode: 'TAG_GROUP_ERROR',
level: 'error',
message: stringTemplate`Group "${'string'}" has too many or too few tags at the top level.`,
message: stringTemplate`Group "${'string'}" has too many or too few tags or Def-expand groups at the top level.`,
},
multipleTopLevelTagGroupTags: {
hedCode: 'TAG_GROUP_ERROR',
Expand Down
2 changes: 1 addition & 1 deletion data/json/reservedTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"forbiddenSubgroupTags": [],
"isTemporalTag": true,
"requiresDef": true,
"otherAllowedNonDefTags": ["Def", "Delay"]
"otherAllowedNonDefTags": ["Delay"]
},
"Onset": {
"name": "Onset",
Expand Down
3 changes: 1 addition & 2 deletions parser/definitionManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { generateIssue, IssueError } from '../common/issues/issues'
import { parseHedString } from './parser'
//import { filterNonEqualDuplicates } from './parseUtils'
import { filterByTagName } from './parseUtils'

export class Definition {
Expand Down Expand Up @@ -219,7 +218,7 @@ export class DefinitionManager {
}

/**
* Evaluate the definition based on a parsed HED tag
* Evaluate the definition based on a parsed HED tag.
* @param {ParsedHedTag} tag - The tag to evaluate against the definitions.
* @param {Schemas} hedSchemas - The schemas to be used to assist in the evaluation.
* @param {boolean} placeholderAllowed - If true then placeholder is allowed in the def tag.
Expand Down
28 changes: 7 additions & 21 deletions parser/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ export function filterTagMapByNames(tagMap, tagNames) {
return keys.flatMap((key) => tagMap.get(key))
}

/*/!**
* Extract the ParsedHedTag tags that have a name from a specified list of names
* @param {ParsedHedTag[]} tags - to be filtered by name
* @param {[string]} tagList - List of tag names to filter by.
* @returns {ParsedHedTag[]} - A list of tags whose
*!/
export function filterByTagNames(tags, tagList) {
if (!tags || !tagList) {
return []
}
return tags.filter((tag) => tagList.includes(tag.schemaTag.name))
}*/

/**
* Convert a list of ParsedHedTag objects into a comma-separated string of their string representations.
* @param {ParsedHedTag []} tagList - The HED tags whose string representations should be put in a comma-separated list.
Expand All @@ -68,10 +54,10 @@ export function getTagListString(tagList) {
}

/**
* Create a map of the ParsedHedTags by type
* @param { ParsedHedTag[] } tagList
* @param {Set} tagNames
* @returns {Map<string, ParsedHedTag[]>}
* Create a map of the ParsedHedTags by type.
* @param { ParsedHedTag[] } tagList - The HED tags to be categorized.
* @param {Set} tagNames - The tag names to use as categories.
* @returns {Map<string, ParsedHedTag[]>} - A map of tag name to a list of tags with that name.
*/
export function categorizeTagsByName(tagList, tagNames = null) {
// Initialize the map with keys from tagNames and an "other" key
Expand All @@ -89,9 +75,9 @@ export function categorizeTagsByName(tagList, tagNames = null) {
}

/**
* Return a list of duplicate strings
* @param { string[] } itemList - A list of strings to look for duplicates in
* @returns {string []} - a list of unique duplicate strings (multiple copies not repeated
* Return a list of duplicate strings.
* @param { string[] } itemList - A list of strings to look for duplicates in.
* @returns {string []} - a list of unique duplicate strings (multiple copies not repeated.
*/
export function getDuplicates(itemList) {
const checkSet = new Set()
Expand Down
92 changes: 47 additions & 45 deletions parser/parsedHedGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,41 @@ import {
*/
export default class ParsedHedGroup extends ParsedHedSubstring {
/**
* The parsed HED tags or parsedHedGroups or parsedColumnSplices in the HED tag group at the top level
* The parsed HED tags, groups, or splices in the HED tag group at the top level.
* @type {ParsedHedSubstring[]}
*/
tags

/**
* The top-level parsed HED tags in this string.
* @type {ParsedHedTag[]}
*/
topTags

/**
* The top-level parsed HED groups in this string.
* @type {ParsedHedGroup[]}
*/
topGroups

/**
* The top-level column splices in this string
* @type {ParsedHedColumnSplice[]}
*/
topSplices

/**
* All the parsed HED tags in this string.
* @type {ParsedHedTag[]}
*/
allTags

/**
* Any HED tags with special handling. This only covers top-level tags in the group
* Any HED tags with special handling. This only covers top-level tags in the group.
* @type {Map<string, ParsedHedTag[]>}
*/
specialTags

/**
* Whether this HED tag group has child groups with a Def-expand tag.
* @type {boolean}
Expand All @@ -48,12 +66,28 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
*/
defExpandChildren

/**
* True if this group has a Def-expand tag at the top level.
* @type {boolean}
*/
isDefExpandGroup

/**
* True if this group has a Definition tag at the top level.
* @type {boolean}
*/
isDefinitionGroup

/**
* The total number of top-level Def tags and top-level Def-expand groups.
* @type {Number}
*/
defCount

/**
* The unique top-level tag requiring a Def or Def-expand group, if any.
* @type {ParsedHedTag | null}
*/
requiresDefTag

/**
Expand All @@ -74,11 +108,20 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
this._initializeGroups()
}

/**
* Recursively create a list of all the tags in this group.
* @returns {ParsedHedTag[]}
* @private
*/
_getAllTags() {
const subgroupTags = this.topGroups.flatMap((tagGroup) => tagGroup.allTags)
return this.topTags.concat(subgroupTags)
}

/**
* Sets information about the special tags, particularly definition-related tags in this group.
* @private
*/
_initializeGroups() {
const special = ReservedChecker.getInstance()
this.specialTags = categorizeTagsByName(this.topTags, special.specialNames)
Expand All @@ -91,10 +134,11 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
}

/**
* Filter top subgroups that include a special at the top-level of the group
* Filter top subgroups that include a special at the top-level of the group.
*
* @param {string} tagName - The schemaTag name to filter by.
* @returns {Array} - Array of subgroups containing the specified tag.
* @private
*/
_filterSubgroupsByTagName(tagName) {
return Array.from(this.topLevelGroupIterator()).filter((subgroup) => subgroup.specialTags.has(tagName))
Expand Down Expand Up @@ -147,18 +191,6 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
return this.specialTags.get(tagName) ?? []
}

isSpecialGroup(tagName) {
return this.specialTags.has(tagName)
}

/**
* Whether this HED tag group is an onset, offset, or inset group.
* @returns {boolean}
*/
get isTemporalGroup() {
return this.isSpecialGroup('Onset') || this.isSpecialGroup('Offset') || this.isSpecialGroup('Inset')
}

get defTags() {
const tags = this.getSpecial('Def')
for (const group of this.defExpandChildren) {
Expand All @@ -178,22 +210,6 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
)
}

/**
* The deeply nested array of parsed tags.
* @returns {ParsedHedTag[]}
*/
nestedGroups() {
const groups = []
for (const innerTag of this.tags) {
if (innerTag instanceof ParsedHedTag) {
groups.push(innerTag)
} else if (innerTag instanceof ParsedHedGroup) {
groups.push(innerTag.nestedGroups())
}
}
return groups
}

/**
* Return a normalized string representation
* @returns {string}
Expand All @@ -220,20 +236,6 @@ export default class ParsedHedGroup extends ParsedHedSubstring {
return `(${sortedNormalizedItems.join(',')})` // Using curly braces to indicate unordered group
}

/**
* Iterator over the full HED groups and subgroups in this HED tag group.
*
* @yields {ParsedHedTag[]} The subgroups of this tag group.
*/
*subGroupArrayIterator() {
for (const innerTag of this.tags) {
if (innerTag instanceof ParsedHedGroup) {
yield* innerTag.subGroupArrayIterator()
}
}
yield this.tags
}

/**
* Iterator over the ParsedHedGroup objects in this HED tag group.
* @param {string | null} tagName - The name of the tag whose groups are to be iterated over or null if all tags.
Expand Down
2 changes: 1 addition & 1 deletion parser/parsedHedString.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ParsedHedString {
*/
columnSplices
/**
* The top-level tag groups in the string, split into arrays.
* The tags in the top-level tag groups in the string, split into arrays.
* @type {ParsedHedTag[][]}
*/
topLevelGroupTags
Expand Down
Loading

0 comments on commit c987cc3

Please sign in to comment.