Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Some API suggestions for next major releaseΒ #49

@mmcauliffe

Description

@mmcauliffe

As I'm going through to make MFA compatible with v6.0, one thing that sticks out to me is that several aspects of PraatIO could be more pythonic and make it easier for integrating with other packages.

  • Use PEP8 snake case rather than camel case (e.g. Textgrid.tier_names instead of TextGrid.tierNames). This might cause a bit of desync with the underlying TextGrid parameters, but it would also be nice to unify TextGrid.minTimestamp, TextGrid.maxTimestamp with IntervalTier.minT, IntervalTier.maxT. (I'll stick to using camel case for consistency in my other thoughts)
  • Add magic functions to TextGrid classes
    • __len__ so len(textgrid_object) returns len(textgrid_object._tierDict), len(interval_tier) returns len(interval_tier.entries)
    • __getitem__ so textgrid_object[tier_name] returns textgrid_object._tierDict[tier_name] and interval_tier[0] returns interval_tier.entries[0]
      • __setitem__ could call TextGrid.addTier for TextGrid and IntervalTier.insertEntry for IntervalTier with the defaults (and if there's an error, then prompt the user to use the more fully featured function (or have a separate IntervalTier.append and IntervalTier.insert that mirrors python list functionality, though an interval doesn't necessarily have to be added at the end, but that's usually how I think about TextGrid creation)
      • It might be good to split IntervalTier.insertEntry into three functions rather than have a string switch on its behavior, so something like IntervalTier.insertEntry, IntervalTier.mergeEntry, IntervalTier.replaceEntry, so it's easier for IDE autocompletes, easier debugging
    • __iter__ so for tier in textgrid_object yields each tier in textgrid_object.tiers and for interval in interval_tier returns each interval in interval_tier.entries
    • Use dataclasses for Intervals/Points rather than namedtuples so that they're mutable. I realize that changes to intervals have to be evaluated in the context of the tier and so that's likely why they're immutable, but I wonder if when adding intervals to a tier, you could store a reference to the tier in the interval, and then when changing any parameters of it, call the tier's validation logic? Or have a signal/slot style where every time an interval gets added, the tier connects a validation function to the interval's dataChanged signal.

It also might be helpful to have includeBlankSpaces default to true for exporting to textgrids (and it might also be worth breaking up the TextGrid.save method into different methods for the output format), since it's a bit of a gotcha if you try to open up TextGrids in Praat later on. Not having blank intervals was the root cause of some issues for MFA in https://twitter.com/betsysneller/status/1621607813632892929, though I don't think they were using PraatIO to generate the textgrids.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions