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

Concat, Append and Add methods #193

Merged
merged 107 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
30a6745
start, end, shift, intervals
JoFrhwld Mar 1, 2024
138b8e1
start, end tier setters
JoFrhwld Mar 1, 2024
756464e
typo fix
JoFrhwld Mar 1, 2024
69fecd7
setter tests
JoFrhwld Mar 1, 2024
554a871
tiershifts
JoFrhwld Mar 1, 2024
ba8f05b
point shift
JoFrhwld Mar 2, 2024
39d35e2
time set point tier
JoFrhwld Mar 2, 2024
fde54ca
point tier shift
JoFrhwld Mar 2, 2024
5a12c34
tiergroup shift
JoFrhwld Mar 2, 2024
b355f2b
PointsGroup shift
JoFrhwld Mar 2, 2024
0b05a73
entire textgrid shift
JoFrhwld Mar 2, 2024
f683ed8
docs update
JoFrhwld Mar 2, 2024
e9bd3fb
Merge pull request #174 from Forced-Alignment-and-Vowel-Extraction/17…
JoFrhwld Mar 2, 2024
59ae99a
SequenceInterval init refactor
JoFrhwld Mar 2, 2024
5ad3198
Merge pull request #175 from Forced-Alignment-and-Vowel-Extraction/16…
JoFrhwld Mar 2, 2024
793e67c
Merge branch 'dev' into feature/tg-builder
JoFrhwld Jun 15, 2024
2c4856c
new sequence list class
JoFrhwld Jun 17, 2024
2f38ed7
Rolling out new SequenceList
JoFrhwld Jun 17, 2024
c6a2d17
move interval list to top
JoFrhwld Jun 17, 2024
e1feb20
ensuring validation happens
JoFrhwld Jun 17, 2024
b1fe2a1
more interval list work
JoFrhwld Jun 17, 2024
8d5adb9
shift subset list when shifting interval
JoFrhwld Jun 17, 2024
de20a38
refactor to SequenceList
JoFrhwld Jun 17, 2024
f135251
refactor to sequencelist
JoFrhwld Jun 17, 2024
be99226
use sequencelist
JoFrhwld Jun 17, 2024
0d8bd1c
added overlap check fore sequence list
JoFrhwld Jun 17, 2024
8e1a2be
convert sequence list to property for setting behavior
JoFrhwld Jun 17, 2024
177efa9
add and concat for tiers
JoFrhwld Jun 17, 2024
b5eb9b9
make sure cloned classes play nice
JoFrhwld Jun 17, 2024
94986c1
cleanup methpds to fill gaps
JoFrhwld Jun 17, 2024
1353324
tiergroup add and concat
JoFrhwld Jun 17, 2024
16fee06
working atg append
JoFrhwld Jun 17, 2024
49807ce
restrict same interval from being added twice
JoFrhwld Jun 18, 2024
c36fe83
add and append methods for Sequence Intervals
JoFrhwld Jun 18, 2024
5269fa4
match __add__ expectations
JoFrhwld Jun 18, 2024
41656bd
add and append tier methods
JoFrhwld Jun 18, 2024
9b363e4
re_relate method
JoFrhwld Jun 18, 2024
415a0b3
spacing
JoFrhwld Jun 18, 2024
85c7c7c
imports and cleanup
JoFrhwld Jun 18, 2024
cf1c66a
more principled tier xmin and xmax
JoFrhwld Jun 18, 2024
16dc6fd
tiers need to be within tier groups for rerelate
JoFrhwld Jun 18, 2024
27c8c2e
safer class matching for sequence lists
JoFrhwld Jun 18, 2024
e8e90fb
build tiers from sequence lists
JoFrhwld Jun 18, 2024
d8a7d80
re-relate on tier cleanup
JoFrhwld Jun 18, 2024
29ab996
append to subclass tier if in a tier group
JoFrhwld Jun 18, 2024
4e40d1f
manage tier appending
JoFrhwld Jun 18, 2024
3e4d86c
manage re-relation
JoFrhwld Jun 18, 2024
fad5407
new sequence base class
JoFrhwld Jun 20, 2024
7504cae
update sequences and points with base class
JoFrhwld Jun 20, 2024
90b7c00
roll out class casting
JoFrhwld Jun 20, 2024
ccb368d
sequence list work
JoFrhwld Jun 20, 2024
532ee10
mixin work
JoFrhwld Jun 20, 2024
ca615eb
SequenceInterval work
JoFrhwld Jun 20, 2024
a36d686
tiers work
JoFrhwld Jun 20, 2024
379ad1a
return praatio method
JoFrhwld Jun 20, 2024
a206b9e
typo fix on pop
JoFrhwld Jun 20, 2024
552cf08
safer set fol and set initial
JoFrhwld Jun 20, 2024
4b10af9
safer cast
JoFrhwld Jun 20, 2024
5a483e2
fixing point init
JoFrhwld Jun 20, 2024
cc0ccf7
dummy start for points for sequencelist compatibility
JoFrhwld Jun 20, 2024
51253e4
use cast in point tier
JoFrhwld Jun 20, 2024
330c283
cleanup sequence init
JoFrhwld Jun 20, 2024
7952aeb
fusion fix
JoFrhwld Jun 20, 2024
105755a
no need to set point start
JoFrhwld Jun 20, 2024
fb0546b
changed default point
JoFrhwld Jun 20, 2024
ec0e442
fixed duplicate interval
JoFrhwld Jun 20, 2024
3565484
New contains checks on tuples
JoFrhwld Jun 20, 2024
a1a0180
better get index at time
JoFrhwld Jun 20, 2024
b4cb66e
sequece cleanup
JoFrhwld Jun 20, 2024
c09bbca
tiergroup cleanup
JoFrhwld Jun 20, 2024
0fd98ed
tiergroup cleanup
JoFrhwld Jun 20, 2024
d617172
drop print statement
JoFrhwld Jun 20, 2024
50bcaff
atg cleanup
JoFrhwld Jun 20, 2024
f198ec1
fix get interval at time
JoFrhwld Jun 20, 2024
e09bf40
more exports
JoFrhwld Jun 20, 2024
ed3118c
sequence list tests
JoFrhwld Jun 20, 2024
6e76d5c
SequenceList tests
JoFrhwld Jun 21, 2024
1df4310
More typing for SequenceList
JoFrhwld Jun 21, 2024
f99d575
warns for add and append on points
JoFrhwld Jun 21, 2024
672f508
more typing
JoFrhwld Jun 21, 2024
0cb9cb4
better typing on custom_classes
JoFrhwld Jun 21, 2024
d15aecf
more typing
JoFrhwld Jun 21, 2024
a67943e
typing
JoFrhwld Jun 21, 2024
615f6ed
add seq_types to tiers and tier groups
JoFrhwld Jun 21, 2024
971dcee
seq_type on tier group
JoFrhwld Jun 21, 2024
4183e52
tier group appends
JoFrhwld Jun 21, 2024
56bf2c9
more typing
JoFrhwld Jun 21, 2024
ddf0978
safer sequence list checks
JoFrhwld Jun 21, 2024
d5dc0e2
add append tests
JoFrhwld Jun 21, 2024
1084c21
more tier append tests
JoFrhwld Jun 21, 2024
38573e8
maintain reference when appending to atg
JoFrhwld Jun 21, 2024
012ddb0
cleanup tests
JoFrhwld Jun 21, 2024
82f130d
typo catch
JoFrhwld Jun 21, 2024
b8f79ad
move ends
JoFrhwld Jun 21, 2024
5955e1f
xmax fix
JoFrhwld Jun 21, 2024
3d196c6
safer max
JoFrhwld Jun 21, 2024
5305146
rewrite tier group concat
JoFrhwld Jun 21, 2024
e68622a
double run atg cleanup
JoFrhwld Jun 21, 2024
92bf6e7
double run atg cleanup
JoFrhwld Jun 21, 2024
cff5a78
test project up
JoFrhwld Jun 21, 2024
bc2cc18
add for sequence interval doesn;t need to be listed
JoFrhwld Jun 21, 2024
3e5738f
sequence list doc strings
JoFrhwld Jun 21, 2024
2fd7b3c
add sequence list to reference
JoFrhwld Jun 21, 2024
16aeca4
types and docstrings
JoFrhwld Jun 21, 2024
5739f9f
tiers docstrings
JoFrhwld Jun 21, 2024
3c5ca4c
warnings filter error
JoFrhwld Jun 24, 2024
079cef2
docs
JoFrhwld Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
55 changes: 55 additions & 0 deletions doc_src/reference/TierGroup.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# TierGroup { #aligned_textgrid.sequences.tiers.TierGroup }

`sequences.tiers.TierGroup(self, tiers=[SequenceTier()])`

Tier Grouping

## Parameters

| Name | Type | Description | Default |
|---------|----------------------|---------------------------------------------------------------------------------------------|--------------------|
| `tiers` | list\[SequenceTier\] | A list of sequence tiers that are meant to be in hierarchical relationships with eachother | `[SequenceTier()]` |

## Attributes

| Name | Type | Description |
|---------------|----------------------------------|------------------------------------------------|
| tier_list | list\[SequenceTier\] | List of sequence tiers that have been related. |
| entry_classes | list\[Type\[SequenceInterval\]\] | A list of the entry classes for each tier. |
| tier_names | list\[str\] | A list of tier names |
| xmax | float | Maximum time |
| xmin | float | Minimum time |
| \[\] | | Indexable. Returns a SequenceTier |

## Methods

| Name | Description |
| --- | --- |
| [get_intervals_at_time](#aligned_textgrid.sequences.tiers.TierGroup.get_intervals_at_time) | Get intervals at time |
| [show_structure](#aligned_textgrid.sequences.tiers.TierGroup.show_structure) | Show the hierarchical structure |

### get_intervals_at_time { #aligned_textgrid.sequences.tiers.TierGroup.get_intervals_at_time }

`sequences.tiers.TierGroup.get_intervals_at_time(time)`

Get intervals at time

Returns a list of intervals at `time` for each tier.

#### Parameters

| Name | Type | Description | Default |
|--------|--------|-------------------|------------|
| `time` | float | Time in intervals | _required_ |

#### Returns

| Type | Description |
|-------------|--------------------------------------------------------------|
| list\[int\] | A list of interval indices, one for each tier in `tier_list` |

### show_structure { #aligned_textgrid.sequences.tiers.TierGroup.show_structure }

`sequences.tiers.TierGroup.show_structure()`

Show the hierarchical structure
10 changes: 9 additions & 1 deletion docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ format:
light: flatly
dark: darkly
toc: true
code-annotations: hover

# tell quarto to read the generated sidebar
metadata-files:
Expand Down Expand Up @@ -99,6 +100,8 @@ quartodoc:
These classes define common attributes and methods available
to intervals and points.
contents:
- package: aligned_textgrid.mixins.within
name: WithinMixins
- package: aligned_textgrid.mixins.mixins
name: PrecedenceMixins
- package: aligned_textgrid.mixins.mixins
Expand All @@ -121,7 +124,10 @@ quartodoc:
don't have hierarchical relationships defined.
contents:
- package: aligned_textgrid.points.points
name: SequencePoint
name: SequencePoint
- title: SequenceList
contents:
- SequenceList
- title: Tiers
desc: Tiers Classes
- subtitle: Common Features
Expand All @@ -143,6 +149,8 @@ quartodoc:
name: SequencePointTier
- package: aligned_textgrid.sequences.tiers
name: TierGroup
- package: aligned_textgrid.points.tiers
name: PointsGroup
- title: TextGrids
desc: TextGrid Classes
contents:
Expand Down
2 changes: 1 addition & 1 deletion docs/objects.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/aligned_textgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from aligned_textgrid.sequences.sequences import SequenceInterval, Top, Bottom
from aligned_textgrid.sequences.word_and_phone import Word, Phone
from aligned_textgrid.points.points import SequencePoint
from aligned_textgrid.points.tiers import SequencePointTier
from aligned_textgrid.sequences.tiers import SequenceTier
from aligned_textgrid.points.tiers import SequencePointTier, PointsGroup
from aligned_textgrid.sequences.tiers import SequenceTier, TierGroup
from aligned_textgrid.aligned_textgrid import AlignedTextGrid
from aligned_textgrid.sequence_list import SequenceList
from aligned_textgrid.custom_classes import custom_classes
from aligned_textgrid.outputs.to_dataframe import to_df
__all__ = [
"SequenceInterval",
"SequencePoint",
"PointsGroup",
"Top",
"Bottom",
"Word",
"Phone",
"SequenceTier",
"SequencePointTier",
"TierGroup",
"SequenceList",
"AlignedTextGrid",
"custom_classes",
"to_df"
Expand Down
153 changes: 148 additions & 5 deletions src/aligned_textgrid/aligned_textgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
*,
textgrid_path: str = None
):
self.entry_classes = None
self.entry_classes = self._reclone_classes(entry_classes)
if textgrid_path:
textgrid = textgrid_path
Expand Down Expand Up @@ -168,6 +169,17 @@

unique_classes = list(set(flat_classes))

orig_classes = []
orig_class_names = []
if self.entry_classes:
orig_classes = [c for tg in self.entry_classes for c in tg]
orig_class_names = [c.__name__ for c in orig_classes]


already_cloned = [c.__name__ in orig_classes for c in flat_classes]
if all(already_cloned):
return

Check warning on line 181 in src/aligned_textgrid/aligned_textgrid.py

View check run for this annotation

Codecov / codecov/patch

src/aligned_textgrid/aligned_textgrid.py#L181

Added line #L181 was not covered by tests

points = [c for c in unique_classes if issubclass(c, SequencePoint)]
tops = [
c
Expand All @@ -176,8 +188,23 @@
if issubclass(c.superset_class, Top)
]

points_clone = [clone_class(p) for p in points]
tops_clone = [clone_class(t) for t in tops]
points_clone = []
for p in points:
if p.__name__ in orig_class_names:
points_clone.append(

Check warning on line 194 in src/aligned_textgrid/aligned_textgrid.py

View check run for this annotation

Codecov / codecov/patch

src/aligned_textgrid/aligned_textgrid.py#L194

Added line #L194 was not covered by tests
orig_classes[orig_class_names.index(p.__name__)]
)
else:
points_clone.append(clone_class(p))
tops_clone = []
for t in tops:
if t.__name__ in orig_class_names:
tops_clone.append(
orig_classes[orig_class_names.index(t.__name__)]
)
else:
tops_clone.append(clone_class(t))

full_seq_clone = []
for tclone in tops_clone:
full_seq_clone += get_class_hierarchy(tclone, [])
Expand Down Expand Up @@ -329,23 +356,139 @@
setattr(self, name, self.tier_groups[idx])

@property
def tier_names(self):
def tier_names(self) -> list[str]:
if len(self) == 0:
raise ValueError('No tier names in an empty TextGrid.')
return [x.tier_names for x in self.tier_groups]

@property
def xmin(self):
def xmin(self)->np.array:
if len(self) == 0:
raise ValueError('No minimum time for empty TextGrid.')
return np.array([tgroup.xmin for tgroup in self.tier_groups]).min()

@property
def xmax(self):
def xmax(self)->np.array:
if len(self) == 0:
raise ValueError('No maximum time for empty TextGrid.')
return np.array([tgroup.xmax for tgroup in self.tier_groups]).max()

def append(self, tier_group:TierGroup):
"""Append a new TierGroup to an existing
AlignedTextGrid.

Examples:
```{python}
#| warning: false
from aligned_textgrid import Word, Phone, SequenceTier, TierGroup, AlignedTextGrid

speaker1 = TierGroup([
SequenceTier([
Word((0,10, "Hi"))
]),
SequenceTier([
Phone((0,5, "HH")),
Phone((5,10, "AY"))
])
])

speaker2 = TierGroup([
SequenceTier([
Word((10,20, "Hi"))
]),
SequenceTier([
Phone((10,15, "HH")),
Phone((15,20, "AY"))
])
])

atg = AlignedTextGrid()

atg.append(speaker1)
atg.append(speaker2)

print(atg)
```

Args:
tier_group (TierGroup):
The TierGroup to append to the AlignedTextGrid
"""
new_classes = self._reclone_classes(tier_group.entry_classes)
for cl, tier in zip(new_classes, tier_group):
entries = [cl._cast(i) for i in tier]
tier.__init__(entries)

tier_group.__init__(tier_group)

self.tier_groups.append(tier_group)
self.entry_classes = [[tier.entry_class for tier in tg] for tg in self.tier_groups]

def cleanup(self)->None:
"""Cleanup gaps in AlignedTextGrid

If any tiers have time gaps between
intervals, missing subset or superset intervals
or TierGroups with different start and ent times,
this will clean them up by adding intervals with
a blank label.

"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
for tg in self.tier_groups:
tg.cleanup()

interval_tgs = [tg for tg in self if isinstance(tg, TierGroup)]
tg_starts = np.array([tg.xmin for tg in interval_tgs])
tg_ends = np.array([tg.xmax for tg in interval_tgs])

if np.allclose(tg_starts.min(), tg_starts.max()) and \
np.allclose(tg_ends.min(), tg_ends.max()):
return

for tg in self.tier_groups:
if np.allclose(tg.xmin, tg_starts.min()):
continue

start = tg_starts.min()
end = tg.xmin

tg_classes = tg.entry_classes

empty_intervals = [c((start, end, "")) for c in tg_classes]
for tier, interval in zip(tg, empty_intervals):
tier.append(interval)


for tg in self.tier_groups:
if np.allclose(tg.xmax, tg_starts.max()):
continue

Check warning on line 466 in src/aligned_textgrid/aligned_textgrid.py

View check run for this annotation

Codecov / codecov/patch

src/aligned_textgrid/aligned_textgrid.py#L466

Added line #L466 was not covered by tests

start = tg.xmax
end = tg_ends.max()

tg_classes = tg.entry_classes

empty_intervals = [c((start, end, "")) for c in tg_classes]
for tier, interval in zip(tg, empty_intervals):
tier.append(interval)

def shift(
self,
increment: float
):
"""Shift all times (interval starts & ends and point times)
by the given increment.

Args:
increment (float):
The increment by which to shift all times.
Could be positive or negative.
"""
for gr in self:
gr.shift(increment)

def interleave_class(
self,
name:str,
Expand Down
Loading
Loading