Skip to content
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

Started the implementation of special tag handling #189

Merged
merged 1 commit into from
Sep 10, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist/
/venv/
spec_tests/*.txt
spec_tests/temp*.json
spec_tests/temp.spec.js

# Unit test / coverage reports
htmlcov/
Expand Down
5 changes: 5 additions & 0 deletions common/issues/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export default {
level: 'error',
message: stringTemplate`Descendant tag required - "${'tag'}".`,
},
childForbidden: {
hedCode: 'TAG_INVALID',
level: 'error',
message: stringTemplate`Child tag or value not allowed - "${'tag'}".`,
},
requiredPrefixMissing: {
hedCode: 'REQUIRED_TAG_MISSING',
level: 'warning',
Expand Down
4 changes: 2 additions & 2 deletions spec_tests/jsonTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = chai.assert
import { beforeAll, describe, afterAll } from '@jest/globals'

import * as hed from '../validator/event'
import { BidsIssue } from '../bids/types/issues'
import { BidsHedIssue } from '../bids/types/issues'
import { buildSchemas } from '../validator/schema/init'
import { SchemaSpec, SchemasSpec } from '../common/schema/types'
import path from 'path'
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('HED validation using JSON tests', () => {
const log = [header]
totalTests += 1
for (const issue of issues) {
if (issue instanceof BidsIssue) {
if (issue instanceof BidsHedIssue) {
errors.push(`${issue.hedIssue.hedCode}`)
} else {
errors.push(`${issue.hedCode}`)
Expand Down
57 changes: 57 additions & 0 deletions validator/event/special.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import specialTags from './specialTags.json'
import { ParsedHedGroup } from '../../parser/parsedHedGroup'
import { ParsedHedTag } from '../../parser/parsedHedTag'

export class SpecialTagValidator {
/**
* Map of properties for special tags.
* @type {Object<string,*>}
*/
specialTags

constructor() {
this.specialTags = specialTags
}

// Example method to check if a tag exists in specialTags
isSpecialTag(tag) {
return tag._schemaTag.name in this.specialTags
}

/** Check a list of tags for whether they can have children **/
checkTags(tagList) {
const issueList = []
for (const tag of tagList) {
if (!this.isSpecialTag(tag)) {
continue
}
const specReq = this.specialTags[tag._schemaTag.name]
if (!specReq['child'] && tag._remainder.length > 0) {
issueList.push({ internalCode: 'childForbidden', parameters: { tag: tag } })
} else if (specReq['child'] && tag._remainder.length === 0) {
issueList.push({ internalCode: 'childRequired', parameters: { tag: tag } })
}
}
return issueList
}

checkTagGroup(tagGroup) {
const issueList = []
const topTags = tagGroup.tag.filter((tag) => tag instanceof ParsedHedTag)
const topSubgroups = tagGroup.tag.filter((tag) => tag instanceof ParsedHedGroup)
}

checktopTags(tag, topSubgroups) {
const issueList = []
if (this.isSpecialTag(tag)) {
return issueList
}
const specReq = this.specialTags[tag._schemaTag.name]
for (const tag of tagList) {
}
}

// Add more methods as needed...
}

export default SpecialTagValidator
121 changes: 121 additions & 0 deletions validator/event/specialTags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"Definition": {
"child": true,
"requireChild": true,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "DEFINITION_INVALID",
"subgroupTagsNotAllowed": [
"Def",
"Def-expand",
"Event-context",
"Definition",
"Onset",
"Inset",
"Offset",
"Delay",
"Duration"
],
"defTagRequired": false,
"otherAllowedTags": []
},
"Def": {
"child": true,
"tagGroup": false,
"topLevelTagGroup": false,
"maxNumberSubgroups": null,
"minNumberSubgroups": null,
"ERROR_CODE": "DEF_INVALID",
"subgroupTagsNotAllowed": [],
"defTagRequired": false,
"otherAllowedTags": []
},
"Def-expand": {
"child": true,
"tagGroup": true,
"topLevelTagGroup": false,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "DEF_EXPAND_INVALID",
"subgroupTagsNotAllowed": [
"Def",
"Def-expand",
"Event-context",
"Definition",
"Onset",
"Inset",
"Offset",
"Delay",
"Duration"
],
"defTagRequired": false,
"otherAllowedTags": []
},
"Onset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": true,
"otherAllowedTags": []
},
"Inset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": true,
"otherAllowedTags": []
},
"Offset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 0,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": [],
"defTagRequired": true,
"otherAllowedTags": []
},
"Delay": {
"child": true,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 1,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": ["Duration"]
},
"Duration": {
"child": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 1,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": ["Delay"]
},
"Event-context": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": null,
"minNumberSubgroups": 0,
"ERROR_CODE": "TAG_GROUP_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": []
}
}
2 changes: 1 addition & 1 deletion validator/event/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const NAME_CLASS_REGEX = /^[\w\-\u0080-\uFFFF]+$/
const uniqueType = 'unique'
const requiredType = 'required'
const requireChildType = 'requireChild'
const specialTags = require('../specialTags.json')
const specialTags = require('./specialTags.json')

// Validation tests
/**
Expand Down
92 changes: 0 additions & 92 deletions validator/specialTags.json

This file was deleted.

Loading