-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from VisLab/spec-tester
Started the implementation of special tag handling
- Loading branch information
Showing
7 changed files
with
187 additions
and
95 deletions.
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
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,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 |
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,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": [] | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.