# Set up the file names for the tests local_hed_file = '../../data/schema_data/HED7.2.0.xml' # path HED v7.1.1 stored locally example_data_path = '../../data/spreadsheet_data' # path to example data valid_tsv_file = os.path.join(example_data_path, 'ValidTwoColumnHED7_1_1.tsv') valid_tsv_file_no_header = os.path.join( example_data_path, 'ValidTwoColumnHED7_1_1NoHeader.tsv') valid_tsv_file_separate_cols = os.path.join(example_data_path, 'LKTEventCodesHED2.tsv') unsupported_csv_format = os.path.join(example_data_path, 'UnsupportedFormatCSV.csv') multiple_sheet_xlsx_file = os.path.join(example_data_path, 'ExcelMultipleSheets.xlsx') hed_schema_cached = load_schema_version(xml_version_number='7.1.1') hed_validator_old = HedValidator(hed_schema=hed_schema_cached) hed_schema_local = load_schema(local_hed_file) hed_validator_local = HedValidator(hed_schema=hed_schema_local) hed_validator_local_warnings = HedValidator(hed_schema=hed_schema_local) # Example 1a: Valid TSV file with default version of HED print(valid_tsv_file) input_file = HedInput(valid_tsv_file, tag_columns=[2]) validation_issues = input_file.validate_file(hed_validator_old, check_for_warnings=True) the_title = '[Example 1a] ValidTwoColumnHED7_1_1 is probably okay with default version of HED' print(get_printable_issue_string(validation_issues, title=the_title)) # Example 1b: Valid TSV file with specified local version of HED print(valid_tsv_file) input_file = HedInput(valid_tsv_file, tag_columns=[2])
if issues: return issues for event_obj in self.events_dict.values(): contents = event_obj.contents if not contents: contents = EventsInput(file=event_obj.file_path, sidecars=event_obj.sidecars) if keep_events: event_obj.my_contents = contents issues += contents.validate_file(validators=validators, check_for_warnings=check_for_warnings) return issues if __name__ == '__main__': path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../tests/data/bids/eeg_ds003654s_hed') bids = BidsEventFiles(path) for file_obj in bids.sidecar_dict.values(): print(file_obj) for file_obj in bids.events_dict.values(): print(file_obj) print("Now validating.....") hed_schema = \ load_schema('https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED8.0.0.xml') validator = HedValidator(hed_schema=hed_schema) validation_issues = bids.validate(validators=[validator], check_for_warnings=False) issue_str = get_printable_issue_string(validation_issues, skip_filename=False) print(f"Issues: {issue_str}")
example_data_path = 'data' # path to example data valid_tsv_file = os.path.join(example_data_path, 'ValidTwoColumnHED7_1_1.tsv') valid_tsv_file_no_header = os.path.join( example_data_path, 'ValidTwoColumnHED7_1_1NoHeader.tsv') valid_tsv_file_separate_cols = os.path.join(example_data_path, 'ValidSeparateColumnTSV.txt') unsupported_csv_format = os.path.join(example_data_path, 'UnsupportedFormatCSV.csv') multiple_sheet_xlsx_file = os.path.join(example_data_path, 'ExcelMultipleSheets.xlsx') # Example 1a: Valid TSV file with default version of HED print(valid_tsv_file) input_file = HedFileInput(valid_tsv_file, tag_columns=[2]) hed_input_reader = HedValidator(input_file) issues = hed_input_reader.get_validation_issues() print( hed_input_reader.get_printable_issue_string( '[Example 1a] ValidTwoColumnHED7_1_1 is probably okay with default version of HED' )) # Example 1b: Valid TSV file with specified local version of HED print(valid_tsv_file) input_file = HedFileInput(valid_tsv_file, tag_columns=[2]) hed_input_reader = HedValidator(input_file, hed_xml_file=local_hed_file) print( hed_input_reader.get_printable_issue_string( '[Example 1b] ValidTwoColumnHED7_1_1 should have no issues with local version 7.1.1' ))
""" Examples of HED validation of a tag string """ from hed.validator.hed_validator import HedValidator if __name__ == '__main__': local_hed_file = 'data/HED7.1.1.xml' # path HED v7.1.1 stored locally # Example 1a: Valid HED string for HED <= v7.1.1 hed_string_1 = 'Event/Label/ButtonPuskDeny, Event/Description/Button push to deny access to the ID holder,' \ 'Event/Category/Participant response, ' \ '(Participant ~ Action/Button press/Keyboard ~ Participant/Effect/Body part/Arm/Hand/Finger)' hed_input_reader = HedValidator(hed_string_1, hed_xml_file=local_hed_file) print( hed_input_reader.get_printable_issue_string( '[Example 1a] hed_string_1 should have no issues with HEDv7.1.1')) # Example 1b: Try with the latest version of HED.xml hed_input_reader = HedValidator(hed_string_1) print( hed_input_reader.get_printable_issue_string( '[Example 1b] hed_string_1 probably has no issues with the latest HED version' )) # Example 2a: Invalid HED string (junk in last tag) hed_string_2 = 'Event/Category/Participant response,' \ '(Participant ~ Action/Button press/Keyboard ~ Participant/Effect/Body part/Arm/Hand/Finger),' \ 'dskfjkf/dskjdfkj/sdkjdsfkjdf/sdlfdjdsjklj' hed_input_reader = HedValidator(hed_string_2) print(
hed_xml_url = 'https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED8.0.0.xml' hed_library_url1 = \ 'https://raw.githubusercontent.com/hed-standard/hed-schema-library/main/hedxml/HED_score_0.0.1.xml' hed_library_url2 = \ 'https://raw.githubusercontent.com/hed-standard/hed-schema-library/main/hedxml/HED_test_1.0.2.xml' hed_schema = load_schema(hed_xml_url) hed_schema_lib1 = load_schema(hed_library_url1) hed_schema_lib1.set_library_prefix("sc") hed_schema_lib2 = load_schema(hed_library_url2) hed_schema_lib2.set_library_prefix("test") events_file = os.path.join( '../../../datasets/eeg_ds003654s_hed_library/sub-003/eeg/sub-003_task-FacePerception_run-2_events.tsv' ) json_file = os.path.join( '../../../datasets/eeg_ds003654s_hed_library/task-FacePerception_events.json' ) schema_group = HedSchemaGroup( [hed_schema, hed_schema_lib1, hed_schema_lib2]) validator = HedValidator(hed_schema=schema_group) sidecar = Sidecar(json_file) input_file = EventsInput(events_file, sidecars=sidecar) issues = input_file.validate_file_sidecars(validator, check_for_warnings=False) issues += input_file.validate_file(validator, check_for_warnings=False) print( get_printable_issue_string( issues, "Validating a Bids event file with its JSON sidecar"))