-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HED Validator integration into bids schema based validator. #1648
Merged
Merged
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
b606bdd
add checks that can occur after dataset walk to allow for hed validat…
rwblair 0853771
fix call creating dataset object for hed validation
rwblair 88f1f2d
Merge branch 'master' of https://github.com/bids-standard/bids-valida…
rwblair 398e62e
update hed validator to latest version
rwblair 9a6caf9
update hed-validator map file. Add lookup for old style hed issues
rwblair f637904
add hed validator issues to main issues object. Await ds level checks…
rwblair 7b672a1
ignore deno deps in codespell
rwblair 9868a5d
codespell wants comma seperated list for skip flag
rwblair 893b2b6
import hed-validator via esm.sh and pin verison, remove old dist file…
rwblair aa092dd
typescript fixes and simple test
rwblair a42f3de
remove console logs, add test for validator not being triggered.
rwblair 0fd4a25
pin node version for esm.sh? Build works locally for me.
rwblair 63155b8
move hedargs from global into dscontext
rwblair 2569d48
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair 10ab783
stop casting hed-validator arguments to string. Bump hed validator to…
rwblair a89d682
fix detect hed to match columns in datastructure at time of call
rwblair 1c4af61
bumped hed valdiator in schema validator. debugging prints, and actua…
rwblair d927cab
Merge branch 'master' into schema/hedIntegration
effigies 506e3f9
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair 2b86dbc
enable hed validator checks at end of all context validation. update…
rwblair 4546fde
Merge branch 'schema/hedIntegration' of github.com:bids-standard/bids…
rwblair 1e0634f
remove accumulator, run hed valdiation as context level check. Bails …
rwblair 0ac20d3
call hed validate on json files that have hed entries.
rwblair c277c46
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair c9036c1
incomplete update using new hed api
rwblair 1395241
Overhaul hed validation calls to be similar to recent legacy validato…
rwblair d0db309
overhaul integration tests for hed validate
rwblair 30abfe0
remove hedArgs from dataset context since validation is done per file…
rwblair 08ccde0
Forgot to commit some hedargs removals.
rwblair f2f3b7c
update dataset context instantiations to use new schema arg.
rwblair fdb5027
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair 9577090
bump hed-validator in deno deps. Pass text of tsv file as a string to…
rwblair 6793466
use node18 for esm.sh import of hed-validator
rwblair 7378d3d
add Buffer polyfill for deno web validator.
rwblair 2a9e8e2
Update bids-validator/src/validators/bids.ts
rwblair 3e36450
Update bids-validator/src/validators/hed.ts
rwblair 11fd91a
Update bids-validator/src/validators/hed.ts
rwblair 7c65cf5
checkout LICENSE file from ffb2d63
rwblair 418d01d
Merge branch 'schema/hedIntegration' of github.com:bids-standard/bids…
rwblair 799f4b2
Merge branch 'master' into schema/hedIntegration
effigies e492d94
Update import of BIDSFile now that file.ts is removed.
rwblair 52e2a84
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair 899fbf1
mend
rwblair 79b500c
bump hed-javascript, pass columns instead of text to buildHedTsvFile
rwblair 5c94a5e
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair 5beb84f
skip deno.lock from codespell
rwblair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "https://esm.sh/hed-validator@3.15.2?deps=node@18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { formatAssertIssue, validatePath } from './common.ts' | ||
import { assert, assertEquals } from '../../deps/asserts.ts' | ||
import { BIDSFileDeno, readFileTree } from '../../files/deno.ts' | ||
import { DatasetIssues } from '../../issues/datasetIssues.ts' | ||
import { loadSchema } from '../../setup/loadSchema.ts' | ||
import { BIDSContext, BIDSContextDataset } from '../../schema/context.ts' | ||
import { BIDSFile } from '../../types/file.ts' | ||
import { FileTree } from '../../types/filetree.ts' | ||
import { GenericSchema } from '../../types/schema.ts' | ||
import { hedValidate } from '../../validators/hed.ts' | ||
|
||
function getFile(fileTree: FileTree, path: string) { | ||
let [current, ...nextPath] = path.split('/') | ||
if (nextPath.length === 0) { | ||
const target = fileTree.files.find(x => x.name === current) | ||
if (target) { | ||
return target | ||
} | ||
const dirTarget = fileTree.directories.find(x => x.name === nextPath[0]) | ||
return dirTarget | ||
} else { | ||
const nextTree = fileTree.directories.find(x => x.name === current) | ||
if (nextTree) { | ||
return getFile(nextTree, nextPath.join('/')) | ||
} | ||
} | ||
return undefined | ||
} | ||
|
||
Deno.test('hed-validator not triggered', async (t) => { | ||
const PATH = 'tests/data/bids-examples/ds003' | ||
const tree = await readFileTree(PATH) | ||
const schema = await loadSchema() | ||
const issues = new DatasetIssues() | ||
const dsContext = new BIDSContextDataset(undefined, schema, {'HEDVersion': ['bad_version']}) | ||
await t.step('detect hed returns false', async () => { | ||
const eventFile = getFile(tree, 'sub-01/func/sub-01_task-rhymejudgment_events.tsv') | ||
assert(eventFile !== undefined) | ||
assert(eventFile instanceof BIDSFileDeno) | ||
const context = new BIDSContext(tree, eventFile, issues, dsContext) | ||
await context.asyncLoads() | ||
await hedValidate(schema as unknown as GenericSchema, context) | ||
assert(issues.size === 0) | ||
}) | ||
}) | ||
|
||
Deno.test('hed-validator fails with bad schema version', async (t) => { | ||
const PATH = 'tests/data/bids-examples/eeg_ds003645s_hed_library' | ||
const tree = await readFileTree(PATH) | ||
const schema = await loadSchema() | ||
const issues = new DatasetIssues() | ||
const dsContext = new BIDSContextDataset(undefined, schema, {'HEDVersion': ['bad_version']}) | ||
await t.step('detect hed returns false', async () => { | ||
const eventFile = getFile(tree, 'sub-002/eeg/sub-002_task-FacePerception_run-3_events.tsv') | ||
assert(eventFile !== undefined) | ||
assert(eventFile instanceof BIDSFileDeno) | ||
const context = new BIDSContext(tree, eventFile, issues, dsContext) | ||
await context.asyncLoads() | ||
await hedValidate(schema as unknown as GenericSchema, context) | ||
assert(issues.size === 1) | ||
assert(issues.has('HED_ERROR')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import hedValidator from '../deps/hed-validator.ts' | ||
import { hedOldToNewLookup } from '../issues/list.ts' | ||
import { GenericSchema } from '../types/schema.ts' | ||
import { IssueFile, IssueFileOutput } from '../types/issues.ts' | ||
import { BIDSContext, BIDSContextDataset } from '../schema/context.ts' | ||
import { DatasetIssues } from '../issues/datasetIssues.ts' | ||
import { ColumnsMap } from '../types/columns.ts' | ||
|
||
function sidecarHasHed(sidecarData: BIDSContext["sidecar"]) { | ||
if (!sidecarData) { | ||
return false | ||
} | ||
return Object.keys(sidecarData).some(x => sidecarValueHasHed(sidecarData[x])) | ||
} | ||
|
||
function sidecarValueHasHed(sidecarValue: unknown) { | ||
return ( | ||
sidecarValue !== null && | ||
typeof sidecarValue === 'object' && | ||
'HED' in sidecarValue && | ||
sidecarValue.HED !== undefined | ||
) | ||
} | ||
|
||
let hedSchemas: object | undefined | null = undefined | ||
|
||
async function setHedSchemas(datasetDescriptionJson = {}) { | ||
const datasetDescriptionData = new hedValidator.bids.BidsJsonFile( | ||
'/dataset_description.json', | ||
datasetDescriptionJson, | ||
null, | ||
) | ||
try { | ||
hedSchemas = await hedValidator.bids.buildBidsSchemas( | ||
datasetDescriptionData, | ||
null, | ||
) | ||
return [] as HedIssue[] | ||
} catch (issueError) { | ||
hedSchemas = null | ||
return hedValidator.bids.BidsHedIssue.fromHedIssues( | ||
issueError, | ||
datasetDescriptionData.file, | ||
) | ||
} | ||
} | ||
|
||
export interface HedIssue { | ||
code: number | ||
file: IssueFile | ||
evidence: string | ||
} | ||
|
||
export async function hedValidate( | ||
schema: GenericSchema, | ||
context: BIDSContext, | ||
): Promise<void> { | ||
let file | ||
let hedValidationIssues = [] as HedIssue[] | ||
|
||
try { | ||
if (context.extension == '.tsv' && context.columns) { | ||
if (!('HED' in context.columns) && !sidecarHasHed(context.sidecar)) { | ||
return | ||
} | ||
hedValidationIssues = await setHedSchemas(context.dataset.dataset_description) | ||
|
||
file = await buildHedTsvFile(context) | ||
} else if (context.extension == '.json' && sidecarHasHed(context.json)) { | ||
hedValidationIssues = hedValidationIssues = await setHedSchemas(context.dataset.dataset_description) | ||
file = buildHedSidecarFile(context) | ||
} | ||
|
||
if (file !== undefined) { | ||
hedValidationIssues.push(...file.validate(hedSchemas)) | ||
} | ||
} catch (error) { | ||
context.issues.addNonSchemaIssue('HED_ERROR', [{ ...context.file, evidence: error}]) | ||
} | ||
|
||
hedValidationIssues.map((hedIssue) => { | ||
const code = hedIssue.code | ||
if (code in hedOldToNewLookup) { | ||
context.issues.addNonSchemaIssue( | ||
hedOldToNewLookup[code], | ||
[{ ...hedIssue.file, evidence: hedIssue.evidence }], | ||
) | ||
} | ||
}) | ||
} | ||
|
||
async function buildHedTsvFile(context: BIDSContext) { | ||
const tsvData = await context.file.text() | ||
const eventFile = new hedValidator.bids.BidsTsvFile( | ||
context.path, | ||
tsvData, | ||
context.file, | ||
[], | ||
context.sidecar, | ||
) | ||
return eventFile | ||
} | ||
|
||
function buildHedSidecarFile(context: BIDSContext) { | ||
const sidecarFile = new hedValidator.bids.BidsSidecar( | ||
context.path, | ||
context.json, | ||
context.file, | ||
) | ||
return sidecarFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would passing the
ColumnMap
(or a copy) work here, or would that expose too much internal data? The parameter type in hed-validator isMap<string, string[]>
, which appears to beColumnMap
's parent type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the columns map here generates an error:
TypeError: Cannot read properties of undefined (reading 'forEach')
This is coming from
convertParsedTSVData
:https://github.com/hed-standard/hed-javascript/blob/3be833f929cd3db5e259b315ba6cff6e1c677f59/bids/tsvParser.js#L45
via:
https://github.com/hed-standard/hed-javascript/blob/3be833f929cd3db5e259b315ba6cff6e1c677f59/bids/types/tsv.js#L53
I think this is because Map objects pass the check meant to catch the old style tsv data:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@happy5214 Does it make sense to go ahead as-is and then submit a PR once hed-validator can handle a
ColumnMap
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2041 should fix that issue. The type check was a bug that proved easy to fix.