| 1 |
# test_TextGridNavigator.praat |
| 2 |
# djmw 20210211 |
| 3 |
|
| 4 |
appendInfoLine: "test_TextGridNavigator.praat" |
| 5 |
|
| 6 |
textgrid = Read from file: "TIMIT_train_dr1_fcjf0_sa1_extended.TextGrid" |
| 7 |
|
| 8 |
numberOfTiers = Get number of tiers |
| 9 |
numberOfIntervals# = zero# (numberOfTiers) |
| 10 |
for itier to numberOfTiers |
| 11 |
numberOfIntervals# [itier] = Get number of intervals: itier |
| 12 |
endfor |
| 13 |
|
| 14 |
@test_topic |
| 15 |
@test_topicAndBefore |
| 16 |
@test_topicAndBeforeAndAfter |
| 17 |
@test_twoNavigationContexts |
| 18 |
@test_threeNavigationContexts |
| 19 |
@test_timing |
| 20 |
|
| 21 |
removeObject: textgrid |
| 22 |
|
| 23 |
appendInfoLine: "test_TextGridNavigator.praat OK" |
| 24 |
|
| 25 |
procedure test_topic |
| 26 |
appendInfoLine: tab$, "test topic" |
| 27 |
|
| 28 |
.index1# = {3, 5, 8, 11, 15, 21, 23, 25, 29, 32, 35 } |
| 29 |
.numberOfVowels = size (.index1#) |
| 30 |
.startTime1# = zero# (.numberOfVowels) |
| 31 |
.endTime1# = zero# (.numberOfVowels) |
| 32 |
selectObject: textgrid |
| 33 |
for .i to .numberOfVowels |
| 34 |
.startTime1# [.i] = Get start time of interval: 1, .index1# [.i] |
| 35 |
.endTime1# [.i] = Get end time of interval: 1, .index1# [.i] |
| 36 |
endfor |
| 37 |
|
| 38 |
# locate vowels from the set "ix eh ih ux ao ah" |
| 39 |
selectObject: textgrid |
| 40 |
.navigator = To TextGridNavigator (topic only): 1, "ix eh ih ux ao ah", "is equal to", "OR", "Match start to Match end" |
| 41 |
Find first |
| 42 |
for .i to .numberOfVowels |
| 43 |
.index = Get index: 1, "topic" |
| 44 |
assert .index = .index1# [.i] |
| 45 |
.startTime = Get start time: 1, "topic" |
| 46 |
assert .startTime = .startTime1# [.i]; '.index' '.startTime' |
| 47 |
.endTime = Get end time: 1, "topic" |
| 48 |
assert .endTime = .endTime1# [.i]; '.index' '.endTime' |
| 49 |
Find next |
| 50 |
endfor |
| 51 |
|
| 52 |
Modify Topic match criterion: 1, "is not equal to", "AND" |
| 53 |
.numberOfMatches = Get number of matches |
| 54 |
assert .numberOfMatches = numberOfIntervals# [1] - .numberOfVowels |
| 55 |
Modify Topic match criterion: 1, "is equal to", "OR" |
| 56 |
.numberOfMatches = Get number of matches |
| 57 |
assert .numberOfMatches = .numberOfVowels |
| 58 |
selectObject: .navigator, textgrid |
| 59 |
Replace search tiers |
| 60 |
selectObject: .navigator |
| 61 |
.numberOfMatches = Get number of matches |
| 62 |
assert .numberOfMatches = .numberOfVowels |
| 63 |
removeObject: .navigator |
| 64 |
appendInfoLine: tab$, "test topic OK" |
| 65 |
endproc |
| 66 |
|
| 67 |
procedure test_topicAndBefore |
| 68 |
appendInfoLine: tab$, "test topic + before" |
| 69 |
|
| 70 |
# locate vowels from the set "ix eh ih ux ao ah" that also have one of "sh hv jh k s q r w y" before them |
| 71 |
selectObject: textgrid |
| 72 |
.navigator = To TextGridNavigator: 1, "ix eh ih ux ao ah", "is equal to", "OR", |
| 73 |
... "sh hv jh k s q r w y", "is equal to", "OR", "", "is equal to", "AND", "before", "no", "Topic start to Topic end" |
| 74 |
|
| 75 |
.index1# = {3, 5, 8, 15, 21, 23, 25, 29, 35 } |
| 76 |
.label1$# = {"sh", "hv", "jh", "s", "r" , "s", "w", "w", "y" } |
| 77 |
.combi1$# = {"sh |ix", "hv | eh", "jh | ih", "s | ux", "r | ix", "s | ix", "w | ao", "w | ao", "y | ih" } |
| 78 |
|
| 79 |
.time = 0.0 |
| 80 |
for .i to size (.index1#) |
| 81 |
Find next after time: .time |
| 82 |
.index = Get index: 1, "topic" |
| 83 |
assert .index = .index1# [.i]; '.index' |
| 84 |
.label$ = Get label: 1, "before" |
| 85 |
assert .label$ = .label1$# [.i]; '.index' '.label$' |
| 86 |
.time = Get end time: 1, "before" |
| 87 |
endfor |
| 88 |
removeObject: .navigator |
| 89 |
appendInfoLine: tab$, "test topic + before OK" |
| 90 |
endproc |
| 91 |
|
| 92 |
procedure test_topicAndBeforeAndAfter |
| 93 |
appendInfoLine: tab$, "test before + topic + after" |
| 94 |
|
| 95 |
# locate vowels from the set "ix eh ih ux ao ah" that also have one of "sh hv jh k s q r w y" |
| 96 |
# before them and one of "hv q sh" after them |
| 97 |
selectObject: textgrid |
| 98 |
.navigator = To TextGridNavigator: 1, "ix eh ih ux ao ah", "is equal to", "OR", |
| 99 |
... "sh hv jh k s q r w y", "is equal to", "OR", |
| 100 |
... "hv q sh", "is equal to", "OR", |
| 101 |
... "before and after", "no", "Topic start to Topic end" |
| 102 |
Modify Topic match criterion: 1, "is equal to", "OR" |
| 103 |
Modify Before match criterion: 1, "is equal to", "OR" |
| 104 |
Modify After match criterion: 1, "is equal to", "OR" |
| 105 |
Modify combination criterion: 1, "before and after", "no" |
| 106 |
Modify match domain: 1, "Topic start to Topic end" |
| 107 |
Modify Before range: 1, 1, 1 |
| 108 |
Modify After range: 1, 1, 1 |
| 109 |
.index1# = {3, 15, 25} |
| 110 |
.index_before1# = {2, 14, 24} |
| 111 |
.index_after1# = {4, 16, 26} |
| 112 |
.beforeLabels$# = {"sh", "s", "w" } |
| 113 |
.afterLabels$# = {"hv", "q", "sh"} |
| 114 |
|
| 115 |
Find first |
| 116 |
for .i to size (.index1#) |
| 117 |
.index = Get index: 1, "topic" |
| 118 |
assert .index = .index1# [.i]; '.index' |
| 119 |
.index_before = Get index: 1, "before" |
| 120 |
assert .index_before = .index_before1# [.i] |
| 121 |
.label$ = Get label: 1, "before" |
| 122 |
assert .label$ = .beforeLabels$# [.i]; '.index' '.label$' |
| 123 |
.index_after = Get index: 1, "after" |
| 124 |
assert .index_after = .index_after1# [.i] |
| 125 |
.label$ = Get label: 1, "after" |
| 126 |
assert .label$ = .afterLabels$# [.i]; '.index' '.label$' |
| 127 |
Find next |
| 128 |
endfor |
| 129 |
.numberOfMatches = Get number of matches |
| 130 |
assert .numberOfMatches = size (.index1#) |
| 131 |
.numberOfTopicMatches = Get number of Topic matches: 1 |
| 132 |
assert .numberOfTopicMatches = 11 |
| 133 |
.numberOfBeforeMatches = Get number of Before matches: 1 |
| 134 |
assert .numberOfBeforeMatches = 12 |
| 135 |
.numberOfAfterMatches = Get number of After matches: 1 |
| 136 |
assert .numberOfAfterMatches = 4 |
| 137 |
|
| 138 |
appendInfoLine: tab$, tab$, "Check lists of labels, times, domains" |
| 139 |
|
| 140 |
.labels$# = List labels: "before" |
| 141 |
assert size (.labels$#) = size (.index1#) |
| 142 |
for .i to size (.labels$#) |
| 143 |
assert .labels$# [.i] = .beforeLabels$# [.i] |
| 144 |
endfor |
| 145 |
.labels$# = List labels: "after" |
| 146 |
assert size (.labels$#) = size (.index1#) |
| 147 |
for .i to size (.labels$#) |
| 148 |
assert .labels$# [.i] = .afterLabels$# [.i] |
| 149 |
endfor |
| 150 |
topicIndices# = List indices: "topic" |
| 151 |
beforeIndices# = List indices: "before" |
| 152 |
afterIndices# = List indices: "after" |
| 153 |
topicStartTimes# = List start times: "topic" |
| 154 |
topicEndTimes# = List end times: "topic" |
| 155 |
beforeStartTimes# = List start times: "before" |
| 156 |
beforeEndTimes# = List end times: "before" |
| 157 |
afterStartTimes# = List start times: "after" |
| 158 |
afterEndTimes# = List end times: "after" |
| 159 |
domainstt## = List domains: "Topic start to Topic end" |
| 160 |
assert numberOfRows (domainstt## ) == size (.index1#) |
| 161 |
domainsmm## = List domains: "Match start to Match end" |
| 162 |
assert numberOfRows (domainsmm## ) == size (.index1#) |
| 163 |
for .index to numberOfRows (domainstt## ) |
| 164 |
selectObject: textgrid |
| 165 |
topicStartTime = Get start time of interval: 1, topicIndices# [.index] |
| 166 |
topicEndTime = Get end time of interval: 1, topicIndices# [.index] |
| 167 |
assert topicStartTime = topicStartTimes# [.index] |
| 168 |
assert topicEndTime = topicEndTimes# [.index] |
| 169 |
|
| 170 |
beforeStartTime = Get start time of interval: 1, beforeIndices# [.index] |
| 171 |
beforeEndTime = Get end time of interval: 1, beforeIndices# [.index] |
| 172 |
assert beforeStartTime = beforeStartTimes# [.index] |
| 173 |
assert beforeEndTime = beforeEndTimes# [.index] |
| 174 |
|
| 175 |
afterStartTime = Get start time of interval: 1, afterIndices# [.index] |
| 176 |
afterEndTime = Get end time of interval: 1, afterIndices# [.index] |
| 177 |
assert afterStartTime = afterStartTimes# [.index] |
| 178 |
assert afterEndTime = afterEndTimes# [.index] |
| 179 |
|
| 180 |
assert topicStartTime = domainstt## [.index, 1] |
| 181 |
assert topicEndTime = domainstt## [.index, 2] |
| 182 |
assert beforeStartTime = domainsmm## [.index, 1] |
| 183 |
assert afterEndTime = domainsmm## [.index, 2] |
| 184 |
endfor |
| 185 |
appendInfoLine: tab$, tab$, "Check lists of labels, times, domains OK" |
| 186 |
removeObject: .navigator |
| 187 |
appendInfoLine: tab$, "test before + topic + after OK" |
| 188 |
endproc |
| 189 |
|
| 190 |
procedure test_twoNavigationContexts |
| 191 |
appendInfoLine: tab$, "test two navigation contexts" |
| 192 |
|
| 193 |
.index1# = {5, 15, 25, 29, 35} |
| 194 |
.numberOfMatches = size (.index1#) |
| 195 |
.index1_before# = {4, 14, 24, 28, 34} |
| 196 |
.label1$# = {"eh", "ux", "ao", "ao", "ih"} |
| 197 |
.index3# = {3, 6, 9, 11, 13} |
| 198 |
# only vowels in these words should match |
| 199 |
.label3$# = {"had", "suit", "wash", "water", "year"} |
| 200 |
.startTime3# = zero# (.numberOfMatches) |
| 201 |
.endTime3# = zero# (.numberOfMatches) |
| 202 |
selectObject: textgrid |
| 203 |
for .i to .numberOfMatches |
| 204 |
.startTime3# [.i] = Get start time of interval: 3, .index3# [.i] |
| 205 |
.endTime3# [.i] = Get end time of interval: 3, .index3# [.i] |
| 206 |
endfor |
| 207 |
appendInfoLine: tab$,tab$, "From small to large" |
| 208 |
|
| 209 |
# locate vowels from the set "ix eh ih ux ao ah" that also have one of "sh hv jh k s q r w y" before them |
| 210 |
selectObject: textgrid |
| 211 |
.navigator = To TextGridNavigator: 1, "ix eh ih ux ao ah", "is equal to", "OR", |
| 212 |
... "sh hv jh k s q r w y", "is equal to", "OR", "", "is equal to", "AND", "before", "no", "Topic start to Topic end" |
| 213 |
Rename: "small_LARGE" |
| 214 |
# locate words from the set "suit wash water year" on tier 3 |
| 215 |
selectObject: .navigator, textgrid |
| 216 |
Add search tier (topic only): 3, "had suit wash water year", "is equal to", "OR", "Topic start to Topic end", |
| 217 |
... "overlaps before and after" |
| 218 |
selectObject: .navigator |
| 219 |
Find first |
| 220 |
for .i to .numberOfMatches |
| 221 |
.index = Get index: 1, "topic" |
| 222 |
assert .index = .index1# [.i]; '.index' |
| 223 |
.index_before = Get index: 1, "before" |
| 224 |
assert .index_before = .index1_before# [.i] |
| 225 |
.label$ = Get label: 1, "topic" |
| 226 |
assert .label$ = .label1$# [.i] |
| 227 |
.indexc2 = Get index: 3, "topic" |
| 228 |
assert .indexc2 = .index3#[.i]; '.indexc2' '.index3# [.i]' |
| 229 |
.label2$ = Get label: 3, "topic" |
| 230 |
assert .label2$ = .label3$# [.i] |
| 231 |
.startTime = Get start time: 3, "topic" |
| 232 |
assert .startTime = .startTime3# [.i]; '.indexc2' '.startTime' |
| 233 |
.endTime = Get end time: 3, "topic" |
| 234 |
assert .endTime = .endTime3# [.i]; '.indexc2' '.endTime' |
| 235 |
Find next |
| 236 |
endfor |
| 237 |
appendInfoLine: tab$,tab$, "From small to large OK" |
| 238 |
appendInfoLine: tab$,tab$, "From large to small" |
| 239 |
|
| 240 |
selectObject: textgrid |
| 241 |
.navigator2 = To TextGridNavigator (topic only): 3, "had suit wash water year", "is equal to", "OR", "Topic start to Topic end" |
| 242 |
Rename: "LARGE_small" |
| 243 |
selectObject: .navigator2, textgrid |
| 244 |
Add search tier: 1, "ix eh ih ux ao ah", "is equal to", "OR", "sh hv jh k s q r w y", "is equal to", "OR", |
| 245 |
... "", "is equal to", "AND", "before", "no", "Topic start to Topic end", "is inside" |
| 246 |
selectObject: .navigator |
| 247 |
Find first |
| 248 |
for .i to .numberOfMatches |
| 249 |
.index = Get index: 1, "topic" |
| 250 |
assert .index = .index1# [.i]; '.index' |
| 251 |
.index_before = Get index: 1, "before" |
| 252 |
assert .index_before = .index1_before# [.i] |
| 253 |
.label$ = Get label: 1, "topic" |
| 254 |
assert .label$ = .label1$# [.i] |
| 255 |
.indexc2 = Get index: 3, "topic" |
| 256 |
assert .indexc2 = .index3#[.i]; '.indexc2' '.index3# [.i]' |
| 257 |
.label2$ = Get label: 3, "topic" |
| 258 |
assert .label2$ = .label3$# [.i] |
| 259 |
.startTime = Get start time: 3, "topic" |
| 260 |
assert .startTime = .startTime3# [.i]; '.indexc2' '.startTime' |
| 261 |
.endTime = Get end time: 3, "topic" |
| 262 |
assert .endTime = .endTime3# [.i]; '.indexc2' '.endTime' |
| 263 |
Find next |
| 264 |
endfor |
| 265 |
|
| 266 |
removeObject: .navigator, .navigator2 |
| 267 |
appendInfoLine: tab$,tab$, "From large to small OK" |
| 268 |
appendInfoLine: tab$, "test two navigation contexts OK" |
| 269 |
endproc |
| 270 |
|
| 271 |
procedure test_threeNavigationContexts |
| 272 |
appendInfoLine: tab$, "test three navigation contexts" |
| 273 |
|
| 274 |
.index1# = {15, 29, 35} |
| 275 |
.numberOfMatches = size (.index1#) |
| 276 |
.index1_before# = {14, 28, 34} |
| 277 |
.label1$# = { "ux", "ao", "ih"} |
| 278 |
.index3# = {6, 11, 13} |
| 279 |
.indext4# = {5, 9, 11} |
| 280 |
.label3$# = {"suit", "water", "year"} |
| 281 |
.startTime3# = zero# (.numberOfMatches) |
| 282 |
.endTime3# = zero# (.numberOfMatches) |
| 283 |
.startTimet4# = zero# (.numberOfMatches) |
| 284 |
.endTimet4# = zero# (.numberOfMatches) |
| 285 |
selectObject: textgrid |
| 286 |
for .i to .numberOfMatches |
| 287 |
.startTime3# [.i] = Get start time of interval: 3, .index3# [.i] |
| 288 |
.endTime3# [.i] = Get end time of interval: 3, .index3# [.i] |
| 289 |
.startTimet4# [.i] = Get start time of interval: 4, .indext4# [.i] |
| 290 |
.endTimet4# [.i] = Get end time of interval: 4, .indext4# [.i] |
| 291 |
endfor |
| 292 |
|
| 293 |
# locate vowels from the set "ix eh ih ux ao ah" that also have one of "sh hv jh k s q r w y" before them |
| 294 |
selectObject: textgrid |
| 295 |
.navigator = To TextGridNavigator: 1, "ix eh ih ux ao ah", "is equal to", "OR", |
| 296 |
... "sh hv jh k s q r w y", "is equal to", "OR", "", "is equal to", "AND", "before", "no", "Topic start to Topic end" |
| 297 |
selectObject: .navigator, textgrid |
| 298 |
Add search tier (topic only): 3, "had suit wash water year", "is equal to", "OR", "Topic start to Topic end", |
| 299 |
... "overlaps before and after" |
| 300 |
Add search tier (topic only): 4, "N", "is equal to", "OR", "Topic start to Topic end", "overlaps before and after" |
| 301 |
selectObject: .navigator |
| 302 |
Find first |
| 303 |
for .i to .numberOfMatches |
| 304 |
.index = Get index: 1, "topic" |
| 305 |
assert .index = .index1# [.i]; '.index' |
| 306 |
.index_before = Get index: 1, "before" |
| 307 |
assert .index_before = .index1_before# [.i] |
| 308 |
.label$ = Get label: 1, "topic" |
| 309 |
assert .label$ = .label1$# [.i] |
| 310 |
.indexc2 = Get index: 3, "topic" |
| 311 |
assert .indexc2 = .index3#[.i]; '.indexc2' '.index3# [.i]' |
| 312 |
.label2$ = Get label: 3, "topic" |
| 313 |
assert .label2$ = .label3$# [.i] |
| 314 |
.startTime = Get start time: 3, "topic" |
| 315 |
assert .startTime = .startTime3# [.i]; '.indexc2' '.startTime' |
| 316 |
.endTime = Get end time: 3, "topic" |
| 317 |
assert .endTime = .endTime3# [.i]; '.indexc2' '.endTime' |
| 318 |
.indexc3 = Get index: 4, "topic" |
| 319 |
assert .indexc3 = .indext4#[.i]; '.indexc3' '.indext4# [.i]' |
| 320 |
.startTime = Get start time: 4, "topic" |
| 321 |
assert .startTime = .startTimet4# [.i]; '.indexc3' '.startTime' |
| 322 |
.endTime = Get end time: 4, "topic" |
| 323 |
assert .endTime = .endTimet4# [.i]; '.indexc3' '.endTime' |
| 324 |
Find next |
| 325 |
endfor |
| 326 |
removeObject: .navigator |
| 327 |
appendInfoLine: tab$, "test three navigation contexts OK" |
| 328 |
endproc |
| 329 |
|
| 330 |
procedure test_timing |
| 331 |
stopwatch |
| 332 |
.numberOfCreations = 1000 |
| 333 |
for .i to .numberOfCreations |
| 334 |
selectObject: textgrid |
| 335 |
.navigator = To TextGridNavigator: 1, "ix eh ih ux ao ah", "is equal to", "OR", |
| 336 |
... "sh hv jh k s q r w y", "is equal to", "OR", "", "is equal to", "AND", "before", "no", "Topic start to Topic end" |
| 337 |
selectObject: .navigator, textgrid |
| 338 |
Add search tier (topic only): 3, "had suit wash water year", "is equal to", "OR", "Topic start to Topic end", |
| 339 |
... "overlaps before and after" |
| 340 |
Add search tier (topic only): 4, "N", "is equal to", "OR", "Topic start to Topic end", "overlaps before and after" |
| 341 |
selectObject: .navigator |
| 342 |
domains## = List domains: "Topic start to Topic end" |
| 343 |
if .i < .numberOfCreations |
| 344 |
removeObject: .navigator |
| 345 |
endif |
| 346 |
endfor |
| 347 |
time1 = stopwatch |
| 348 |
.numberOfMatches = 10000 |
| 349 |
for .i to .numberOfMatches |
| 350 |
domains## = List domains: "Topic start to Topic end" |
| 351 |
endfor |
| 352 |
removeObject: .navigator |
| 353 |
time2 = stopwatch |
| 354 |
appendInfoLine: tab$, .numberOfCreations, " navigator creations + matches (3 tiers) took ", fixed$ (time1, 3), " s." |
| 355 |
appendInfoLine: tab$, .numberOfMatches, " navigator matches (3 tiers) took ", fixed$ (time2, 3), " s." |
| 356 |
endproc |
| 357 |
|