Skip to content
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
20 changes: 10 additions & 10 deletions hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def val_error_require_child(tag):


@hed_error(ValidationErrors.TAG_NOT_UNIQUE)
def val_error_multiple_unique(tag_prefix):
return f"Multiple unique tags with prefix - '{tag_prefix}'"
def val_error_multiple_unique(tag_namespace):
return f"Multiple unique tags with namespace - '{tag_namespace}'"


@hed_tag_error(ValidationErrors.TAG_PREFIX_INVALID)
def val_error_prefix_invalid(tag, tag_prefix):
return f"Prefixes can only contain alpha characters. - '{tag_prefix}'"
@hed_tag_error(ValidationErrors.TAG_NAMESPACE_PREFIX_INVALID)
def val_error_prefix_invalid(tag, tag_namespace):
return f"Prefixes can only contain alpha characters. - '{tag_namespace}'"


@hed_tag_error(ValidationErrors.TAG_EXTENSION_INVALID)
Expand Down Expand Up @@ -146,9 +146,9 @@ def val_error_hed_blank_column(column_number):
return f"Column number {column_number} has no column name"


@hed_tag_error(ValidationErrors.HED_LIBRARY_UNMATCHED, actual_code=ValidationErrors.TAG_PREFIX_INVALID)
def val_error_unknown_prefix(tag, unknown_prefix, known_prefixes):
return f"Tag '{tag} has unknown prefix '{unknown_prefix}'. Valid prefixes: {known_prefixes}"
@hed_tag_error(ValidationErrors.HED_LIBRARY_UNMATCHED, actual_code=ValidationErrors.TAG_NAMESPACE_PREFIX_INVALID)
def val_error_unknown_namespace(tag, unknown_prefix, known_prefixes):
return f"Tag '{tag} has unknown namespace '{unknown_prefix}'. Valid prefixes: {known_prefixes}"


@hed_tag_error(ValidationErrors.NODE_NAME_EMPTY, has_sub_tag=True)
Expand Down Expand Up @@ -217,8 +217,8 @@ def val_error_top_level_tags(tag, multiple_tags):


@hed_error(ValidationErrors.REQUIRED_TAG_MISSING)
def val_warning_required_prefix_missing(tag_prefix):
return f"Tag with prefix '{tag_prefix}' is required"
def val_warning_required_prefix_missing(tag_namespace):
return f"Tag with namespace '{tag_namespace}' is required"


@hed_tag_error(ValidationErrors.STYLE_WARNING, default_severity=ErrorSeverity.WARNING)
Expand Down
2 changes: 1 addition & 1 deletion hed/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ValidationErrors:
TAG_GROUP_ERROR = "TAG_GROUP_ERROR"
TAG_INVALID = "TAG_INVALID"
TAG_NOT_UNIQUE = 'TAG_NOT_UNIQUE'
TAG_PREFIX_INVALID = 'TAG_PREFIX_INVALID'
TAG_NAMESPACE_PREFIX_INVALID = 'TAG_NAMESPACE_PREFIX_INVALID'
TAG_REQUIRES_CHILD = 'TAG_REQUIRES_CHILD'
TILDES_UNSUPPORTED = 'TILDES_UNSUPPORTED'
UNITS_INVALID = 'UNITS_INVALID'
Expand Down
28 changes: 14 additions & 14 deletions hed/models/hed_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, hed_string, span=None, hed_schema=None, def_dict=None):
# This is not generally used anymore, but you can use it to replace a tag in place.
self._tag = None

self._schema_prefix = self._get_schema_prefix(self.org_tag)
self._namespace = self._get_schema_namespace(self.org_tag)

# This is the schema this tag was converted to.
self._schema = None
Expand Down Expand Up @@ -68,14 +68,14 @@ def copy(self):
return return_copy

@property
def schema_prefix(self):
""" Library prefix for this tag if one exists.
def schema_namespace(self):
""" Library namespace for this tag if one exists.

Returns:
prefix (str): The library prefix, including the colon.
namespace (str): The library namespace, including the colon.

"""
return self._schema_prefix
return self._namespace

@property
def short_tag(self):
Expand All @@ -89,7 +89,7 @@ def short_tag(self):

"""
if self._schema_entry:
return f"{self._schema_prefix}{self._schema_entry.short_tag_name}{self._extension_value}"
return f"{self._namespace}{self._schema_entry.short_tag_name}{self._extension_value}"

return str(self)

Expand Down Expand Up @@ -141,7 +141,7 @@ def short_base_tag(self, new_tag_val):
if self._schema:
if self.is_takes_value_tag():
new_tag_val = new_tag_val + "/#"
tag_entry = self._schema.get_tag_entry(new_tag_val, schema_prefix=self.schema_prefix)
tag_entry = self._schema.get_tag_entry(new_tag_val, schema_namespace=self.schema_namespace)

self._schema_entry = tag_entry
else:
Expand Down Expand Up @@ -246,7 +246,7 @@ def long_tag(self):

"""
if self._schema_entry:
return f"{self._schema_prefix}{self._schema_entry.long_tag_name}{self._extension_value}"
return f"{self._namespace}{self._schema_entry.long_tag_name}{self._extension_value}"
return str(self)

@property
Expand Down Expand Up @@ -336,7 +336,7 @@ def convert_to_canonical_forms(self, hed_schema):
list: A list of issues found during conversion. Each element is a dictionary.

"""
tag_entry, remainder, tag_issues = hed_schema.find_tag_entry(self, self.schema_prefix)
tag_entry, remainder, tag_issues = hed_schema.find_tag_entry(self, self.schema_namespace)
self._schema_entry = tag_entry
self._schema = hed_schema
if self._schema_entry:
Expand Down Expand Up @@ -554,14 +554,14 @@ def any_parent_has_attribute(self, attribute):
return self._schema_entry.any_parent_has_attribute(attribute=attribute)

@staticmethod
def _get_schema_prefix(org_tag):
""" Finds the library prefix for the tag.
def _get_schema_namespace(org_tag):
""" Finds the library namespace for the tag.

Parameters:
org_tag (str): A string representing a tag.

Returns:
str: Library prefix string or empty.
str: Library namespace string or empty.

"""
first_slash = org_tag.find("/")
Expand Down Expand Up @@ -633,7 +633,7 @@ def replace_placeholder(self, placeholder_value):
def __hash__(self):
if self._schema_entry:
return hash(
self._schema_prefix + self._schema_entry.short_tag_name.lower() + self._extension_value.lower())
self._namespace + self._schema_entry.short_tag_name.lower() + self._extension_value.lower())
else:
return hash(self.lower())

Expand Down Expand Up @@ -667,7 +667,7 @@ def __deepcopy__(self, memo):

# copy all other attributes except schema and schema_entry
new_tag._tag = copy.deepcopy(self._tag, memo)
new_tag._schema_prefix = copy.deepcopy(self._schema_prefix, memo)
new_tag._namespace = copy.deepcopy(self._namespace, memo)
new_tag._extension_value = copy.deepcopy(self._extension_value, memo)
new_tag._parent = copy.deepcopy(self._parent, memo)
new_tag._expandable = copy.deepcopy(self._expandable, memo)
Expand Down
73 changes: 36 additions & 37 deletions hed/schema/hed_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self):
self.epilogue = ""

self._is_hed3_schema = None
# This is the specified library name_prefix - tags will be {schema_prefix}:{tag_name}
self._schema_prefix = ""
# This is the specified library name_prefix - tags will be {schema_namespace}:{tag_name}
self._namespace = ""

self._sections = self._create_empty_sections()

Expand All @@ -46,16 +46,16 @@ def version(self):
return self.header_attributes['version']

def get_formatted_version(self, as_string=False):
""" The HED version string including prefix and library name if any of this schema.
""" The HED version string including namespace and library name if any of this schema.

Returns:
str: The complete version of this schema including library name and prefix.
str: The complete version of this schema including library name and namespace.

"""
library = self.library
if library:
library = library + '_'
return self._schema_prefix + library + self.version
return self._namespace + library + self.version

@property
def library(self):
Expand Down Expand Up @@ -104,11 +104,11 @@ def get_save_header_attributes(self, save_merged=False):

return header_attributes

def schema_for_prefix(self, prefix):
""" Return HedSchema object for this prefix.
def schema_for_namespace(self, namespace):
""" Return HedSchema object for this namespace.

Parameters:
prefix (str): The schema library name prefix.
namespace (str): The schema library name namespace.

Returns:
HedSchema: The HED schema object for this schema.
Expand All @@ -117,7 +117,7 @@ def schema_for_prefix(self, prefix):
-This is mostly a placeholder for HedSchemaGroup and may be refactored out later.

"""
if self._schema_prefix != prefix:
if self._namespace != namespace:
return None
return self

Expand All @@ -131,7 +131,7 @@ def valid_prefixes(self):
Notes:
- The return value is always length 1 if using a HedSchema.
"""
return [self._schema_prefix]
return [self._namespace]

# ===============================================
# Creation and saving functions
Expand Down Expand Up @@ -210,17 +210,17 @@ def save_as_xml(self, filename=None, save_merged=True):
return filename
return local_xml_file

def set_schema_prefix(self, schema_prefix):
""" Set library prefix associated for this schema.
def set_schema_prefix(self, schema_namespace):
""" Set library namespace associated for this schema.

Parameters:
schema_prefix (str): Should be empty, or end with a colon.(Colon will be automated added if missing).
schema_namespace (str): Should be empty, or end with a colon.(Colon will be automated added if missing).

"""
if schema_prefix and schema_prefix[-1] != ":":
schema_prefix += ":"
if schema_namespace and schema_namespace[-1] != ":":
schema_namespace += ":"

self._schema_prefix = schema_prefix
self._namespace = schema_namespace

def check_compliance(self, check_for_warnings=True, name=None, error_handler=None):
""" Check for HED3 compliance of this schema.
Expand Down Expand Up @@ -387,7 +387,7 @@ def __eq__(self, other):
# s = f"{key} unmatched: '{str(dict1[key].name)}' vs '{str(dict2[key].name)}'"
# print(s)
return False
if self._schema_prefix != other._schema_prefix:
if self._namespace != other._namespace:
return False
return True

Expand Down Expand Up @@ -424,27 +424,27 @@ def get_tags_with_attribute(self, key, section_key=HedSectionKey.AllTags):

"""
return self._sections[section_key].get_entries_with_attribute(key, return_name_only=True,
schema_prefix=self._schema_prefix)
schema_namespace=self._namespace)

def get_tag_entry(self, name, key_class=HedSectionKey.AllTags, schema_prefix=""):
def get_tag_entry(self, name, key_class=HedSectionKey.AllTags, schema_namespace=""):
""" Return the schema entry for this tag, if one exists.

Parameters:
name (str): Any form of basic tag(or other section entry) to look up.
This will not handle extensions or similar.
If this is a tag, it can have a schema prefix, but it's not required
If this is a tag, it can have a schema namespace, but it's not required
key_class (HedSectionKey or str): The type of entry to return.
schema_prefix (str): Only used on AllTags. If incorrect, will return None.
schema_namespace (str): Only used on AllTags. If incorrect, will return None.

Returns:
HedSchemaEntry: The schema entry for the given tag.

"""
if key_class == HedSectionKey.AllTags:
if schema_prefix != self._schema_prefix:
if schema_namespace != self._namespace:
return None
if name.startswith(self._schema_prefix):
name = name[len(self._schema_prefix):]
if name.startswith(self._namespace):
name = name[len(self._namespace):]

return self._get_tag_entry(name, key_class)

Expand All @@ -462,14 +462,14 @@ def _get_tag_entry(self, name, key_class=HedSectionKey.AllTags):
"""
return self._sections[key_class].get(name)

def find_tag_entry(self, tag, schema_prefix=""):
def find_tag_entry(self, tag, schema_namespace=""):
""" Find the schema entry for a given source tag.

Note: Will not identify tags if schema_prefix is set incorrectly
Note: Will not identify tags if schema_namespace is set incorrectly

Parameters:
tag (str, HedTag): Any form of tag to look up. Can have an extension, value, etc.
schema_prefix (str): The schema prefix of the tag, if any.
schema_namespace (str): The schema namespace of the tag, if any.

Returns:
HedTagEntry: The located tag entry for this tag.
Expand All @@ -480,18 +480,18 @@ def find_tag_entry(self, tag, schema_prefix=""):
Works left to right (which is mostly relevant for errors).

"""
if schema_prefix != self._schema_prefix:
if schema_namespace != self._namespace:
validation_issues = ErrorHandler.format_error(ValidationErrors.HED_LIBRARY_UNMATCHED, tag,
schema_prefix, self.valid_prefixes)
schema_namespace, self.valid_prefixes)
return None, None, validation_issues
return self._find_tag_entry(tag, schema_prefix)
return self._find_tag_entry(tag, schema_namespace)

def _find_tag_entry(self, tag, schema_prefix=""):
def _find_tag_entry(self, tag, schema_namespace=""):
""" Find the schema entry for a given source tag.

Parameters:
tag (str, HedTag): Any form of tag to look up. Can have an extension, value, etc.
schema_prefix (str): The schema prefix of the tag, if any.
schema_namespace (str): The schema namespace of the tag, if any.

Returns:
HedTagEntry: The located tag entry for this tag.
Expand All @@ -503,9 +503,9 @@ def _find_tag_entry(self, tag, schema_prefix=""):

"""
clean_tag = str(tag)
prefix = schema_prefix
clean_tag = clean_tag[len(prefix):]
prefix_tag_adj = len(prefix)
namespace = schema_namespace
clean_tag = clean_tag[len(namespace):]
prefix_tag_adj = len(namespace)
working_tag = clean_tag.lower()

# Most tags are in the schema directly, so test that first
Expand Down Expand Up @@ -581,8 +581,7 @@ def _update_all_entries(self):
""" Call finalize_entry on every schema entry(tag, unit, etc). """
for key_class, section in self._sections.items():
self._initialize_attributes(key_class)
for entry in section.values():
entry.finalize_entry(self)
section._finalize_section(self)

def _initialize_attributes(self, key_class):
""" Set the valid attributes for a section.
Expand Down
Loading