-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plan for new API / interface #120
Comments
thinking about this again. The main issue with the current architecture of the tool, such as it is, is that it conflates two things:
The class Factoring all of this out would leave the core idea of So. A major breaking-changes 4.0 version could introduce an interface like this for all formats import abc
class Format(abc.ABC):
@classmethod
@abstractmethod
def from_file(cls, file):
...
@abstractmethod
def to_seq():
"""convert to ``crowsetta.Sequence``"""
... This assumes the existence of some separate tool that can build datasets. This works as long as each annotation file only annotates a single audio file.
A possibly useful nice-to-have would be def to_csv(csv_path):
self.to_df().to_csv(csv_path) But I'm not sure this is actually useful, it's not like these file formats are so complicated. |
Again thinking about this more. I think actually the abstraction of an Because we need a way to know what the annotations are annotating. That information is not present in the I don't have a good name for this. I have thought about Also I'm realizing that currently there's no way to determine the |
so if I do They should all be If a single annotation file annotates multiple sources, then its and the core idea still is that I convert an so the interface looks something like class Annotation:
format = 'format-name'
def __init__(annot_path: [str, Path], source_path: [str, Path], kwargs):
self.annot_path = annot_path
self.source_path = source_path
self.format = self.format # set instance-level attribute to class-level attribute?
# by *kwargs* I mean to indicate annotation format-specific attributes
@abstractmethod
@classmethod
def from_file(cls, annot_path: [str, Path]) -> [Annotation, list[Annotation]]:
...
# class method is responsible for determining source path from annotation file when loading it
@abstractmethod
def to_seq(self) -> SeqAnnotation:
... # class is responsible for converting from annotation attributes to a seq. On a per-instance basis |
Further notes:
and
|
|
|
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
- add `interface` sub-pacakge with base.py + defines `BaseFormat` - add seq sub-package in `interface` with base.py + defines `SeqLike` interface - add bbox sub-package in `interface` with base.py + definfes `BBoxLike` interface - import BaseFormat and sub-packages in interface/__init__.py - import inside __init__ in Transcriber to avoid circular imports
Need to think about this more before spending forever toying with decorators etc -- will a user just get a format they want from the
format
namespace or will they need to invoke some method likeshow
orget
?I like just over-riding
__dir__
and__getattr__
to be able to do this:the goal of having each format be a class is to provide the ability to work with formats directly
I also think it's better to strongly suggest camel-case classing by defaulting to that instead of letting a user pass a string name like
notmat
-- in WIP toy code I have a decorator with a parameterformat_name
that associates a string with the class and uses this when putting into aFORMATS
dictI guess I was thinking of the current way of interacting with a
Transcriber
where a user specifiesscribe = Transcriber(format='notmat')
when creating an instanceShould there still be a
Transcriber
? or is it just a cute workaround for me not understanding how to write an interface 🤔Currently what the
Transcriber
does is basically (under the tentative new interface as in #105)from_file() -> 'to_generic
all in one step.With this new interface a user could do:
obviating the need to instantiate a magical class ,and instead writing what to me is more Pythonic code.
Would be good to have examples with these list comprehensions
The text was updated successfully, but these errors were encountered: