Skip to content
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

LabelSegmenter interface #181

Open
shuttle1987 opened this issue Jul 28, 2018 · 0 comments
Open

LabelSegmenter interface #181

shuttle1987 opened this issue Jul 28, 2018 · 0 comments
Labels

Comments

@shuttle1987
Copy link
Member

While looking through the code to figure out handling of label segmentation I saw this bit:

LabelSegmenter = NamedTuple("LabelSegmenter",
                            [("segment_labels", Callable[[Utterance], Utterance]),
                            ("labels", Set[str])])

LabelSegmenter.__doc__ = (
    """ An immutable object that segments the phonemes of an utterance. This
    could probably actually have a __call__ implementation. That won't work
    because namedtuples can't have special methods. Perhaps it could instead
    just be a function which we give a labels attribute. Perhaps that
    obfuscates things a bit, but it could be okay.

What's mentioned in the docstring actually isn't true, a namedtuple is actually just a shortcut for creating a python class. You can subtype or just define the magic methods on it directly.

So something like:

LabelSegmenter.__call__ = lambda self, utterance: self.segment_labels(utterance)

Should be perfectly legal, no esoteric messing around is needed here to get that behavior. This might make the interface cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant