Skip to content

querying views contain vocab types with type URI string doesn't work #263

Closed

Description

@keighrim

Bug Description

When calling these methods

def get_all_views_contain(self, at_types: Union[ThingTypesBase, str, List[Union[str, ThingTypesBase]]]) -> List[View]:
"""
Returns the list of all views in the MMIF if given types
are present in that view's 'contains' metadata.
:param at_types: a list of types or just a type to check for. When given more than one types, all types must be found.
:return: the list of views that contain the type
"""
if isinstance(at_types, list):
return [view for view in self.views
if all(map(lambda x: x in view.metadata.contains, at_types))]
else:
return [view for view in self.views if at_types in view.metadata.contains]
def get_views_contain(self, at_types: Union[ThingTypesBase, str, List[Union[str, ThingTypesBase]]]) -> List[View]:
"""
An alias to `get_all_views_contain` method.
"""
return self.get_all_views_contain(at_types)
def get_view_contains(self, at_types: Union[ThingTypesBase, str, List[Union[str, ThingTypesBase]]]) -> Optional[View]:
"""
Returns the last view appended that contains the given
types in its 'contains' metadata.
:param at_types: a list of types or just a type to check for. When given more than one types, all types must be found.
:return: the view, or None if the type is not found
"""
# will return the *latest* view
# works as of python 3.6+ (checked by setup.py) because dicts are deterministically ordered by insertion order
for view in reversed(self.views):
if isinstance(at_types, list):
if all(map(lambda x: x in view.metadata.contains, at_types)):
return view
else:
if at_types in view.metadata.contains:
return view
return None

if I pass the at_type query as a full URI string, it returns zero results.

Reproduction steps

Use this test code

views = mmif_obj.get_all_views_contain(AnnotationTypes.TimeFrame)
self.assertEqual(4, len(views))

And try with

        views = mmif_obj.get_all_views_contain('http://mmif.clams.ai/vocabulary/TimeFrame/v3')

The mmif_obj from the example file should have 4 views that contains TimeFrame/v3, but I get an empty list returned.

Expected behavior

No response

Screenshots

No response

Additional context

Instead of URI, users can use AnnotationTypes class variables (e.g., AnnotationTypes.TimeFrame). But that will perform a "fuzzy" match (#209) to search for the views.

When the URI string is passed, I think the SDK should to full match including the version numbers, instead of the fuzzy match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛BSomething isn't working

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions