Skip to content

Commit

Permalink
single parent DTR assumption taxonomy discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalGawor committed May 28, 2024
1 parent 8ecaf86 commit 861f591
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.7] - TBD
- Data Type Registry integration. doglib.expand_datatype() returning MIME type taxonomy from DTR
- README
-

## [1.0.6] - TBD
- DOGlib distribution as a wheel for internal CLARIN use
Expand Down
3 changes: 3 additions & 0 deletions doglib/doglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def sniff(self, pid_string: Union[str, PID], format='dict', resolve_identifier_c
def is_pid(self, pid_string: Union[str, PID]) -> bool:
"""
Checks whether provided string is PID acceptable by DOG. For PID instance always returns True.
:param pid_string: PID, string to validate
:return: True if PID, False otherwise
"""
pid = pid_factory(pid_string)
return True if pid is not None else False
11 changes: 5 additions & 6 deletions doglib/dtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ def get_dtr_taxonomy_by_type(data_type: str) -> dict:
except (IndexError, KeyError) as error:
raise DataTypeNotFound(f"DataType <{data_type}> doesn't exist in the DTR taxonomy") from error
parents = dtr_taxonomy_json[0]["parents"]
taxonomy_root_id = dtr_type_id
if parents:
for parent_id, parent_name in parents.items():
taxonomy_root_id = get_taxonomy_root_node_by_id(parent_id)
dtr_type_id = get_taxonomy_root_node_by_id(parent_id)

return get_taxonomy_subtree_from_root_id(taxonomy_root_id)
return get_taxonomy_subtree_from_root_id(dtr_type_id)


def get_taxonomy_root_node_by_id(data_type_id: str) -> str:
Expand All @@ -57,11 +56,11 @@ def get_taxonomy_root_node_by_id(data_type_id: str) -> str:
raise DataTypeNotFound(f"DataType with id <{data_type_id}> doesn't exist in the DTR taxonomy") from error
parents = dtr_taxonomy_json["parents"]
# Assumption of single parent
taxonomy_root = dtr_type_id
taxonomy_root_id = dtr_type_id
if parents:
for parent_id, parent_name in parents.items():
taxonomy_root = get_taxonomy_root_node_by_id(parent_id)
return taxonomy_root
taxonomy_root_id = get_taxonomy_root_node_by_id(parent_id)
return taxonomy_root_id


def get_taxonomy_subtree_from_root_id(root_id: str) -> dict:
Expand Down

0 comments on commit 861f591

Please sign in to comment.