########################################################################## # 08.distance.in.eojeols.from.previous.AP&IP tier extractor for Wagon: # Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 08.distance.in.eojeols.from.previous.AP&IP data field for Wagon training # The script assumes that you already have the TextGrid files labelled by professional K-ToBI labelers. # The script will read in all the TextGrid.lab files one by one from the directory 07.distance.in.syllables.from.previous.AP&IP # and write the output files into 10.wagon-features\08.distance.in.eojeols.from.previous.AP&IP # The filename of the output files are .wagon.08 ########################################################################## form Select files word subFolderToProcess 10.wagon-features\07.distance.in.syllables.from.previous.AP&IP word fileExtOfDoneFiles wagon.07 word outputSubFolder 10.wagon-features\08.distance.in.eojeols.from.previous.AP&IP word tierNameToAdd1 dst.in.eoj.pr.AP word tierNameToAdd2 dst.in.eoj.pr.IP real tierDiffTol 0.05 choice outputFileExt: 1 button wagon.08 endform # Get the list of filenames of TextGrid.lab files Create Strings as file list... fileList 'subFolderToProcess$'\*.'fileExtOfDoneFiles$' Sort numFiles = Get number of strings pause 'numFiles' labeled textgrids identified. Continue? # Loop throught each file for iFile to numFiles select Strings fileList # Get the name for a TextGrid.lab file doneFile$ = Get string... iFile filePrefix$ = doneFile$ - fileExtOfDoneFiles$ Read from file... 'subFolderToProcess$'\'doneFile$' Rename... textGrid numIntervals = Get number of intervals... 1 # Get the number of tiers so that you can add an additional tier at the end numTiers = Get number of tiers Duplicate tier... 1 (numTiers+1) 'tierNameToAdd1$' Duplicate tier... 1 (numTiers+2) 'tierNameToAdd2$' # Set the first/last interval text to naught Set interval text... (numTiers+1) 1 Set interval text... (numTiers+1) numIntervals Set interval text... (numTiers+2) 1 Set interval text... (numTiers+2) numIntervals # Initialize the distance (in number of eojeols) from an immediately # preceding APand IP to 0 and 0, respectively distFromPrevAP = 0 distFromPrevIP = 0 # Counter for phonology tier iPhonoTier = 1 ############# Loop through each interval (eojeol) and extract info ############### for iToken from 2 to (numIntervals-1) # Initialize the number of eojeols actualNumEojeol = 0 ######### Get the interval text (i.e., token text) ####### tempIntervalText$ = Get label of interval... 1 iToken indexOfSlash = index(tempIntervalText$, "/") intervalText$ = left$(tempIntervalText$, (indexOfSlash-1)) rightMostLetter$ = right$(tempIntervalText$, 1) ######### Compute the number of eojeols for the interval ############ if rightMostLetter$ = "#" actualNumEojeol = actualNumEojeol + 1 endif ########## End of eojeol number block ####################### ################# AP/IP boundary type & various distances ################ # Get the RHS end time of the interval and compare that with the time point of the tier # # below, and if they're close enough, print the boundary type along with other distance # # measures, such as distance from previous AP/IP and from sentence beginning/end. # ############################################################## endTimeOfInterval = Get end point... 1 iToken pointLabel$ = Get label of point... 2 iPhonoTier # If the boundary exists within the prosodic word, skip it and go to the next phono tier point while (pointLabel$ = "??LHa") iPhonoTier = iPhonoTier + 1 pointLabel$ = Get label of point... 2 iPhonoTier endwhile rightmostPointLabel$ = right$(pointLabel$, 1) timePoint = Get time of point... 2 iPhonoTier dif = abs(timePoint - endTimeOfInterval) # If the difference in time between the RHS boundary in the interval tier and the point # in the point tier below, then the difference is within the tolerance range. # Go ahead and extract the point labels from the point tier if dif < tierDiffTol # For the AP symbol ending with "a" as in "LHa" if rightmostPointLabel$ = "a" # Compute the distance from an immediately preceding AP distFromPrevAP = distFromPrevAP + actualNumEojeol # Compute the distance from an immediately preceding IP distFromPrevIP = distFromPrevIP + actualNumEojeol # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromPrevAP' Set interval text... (numTiers+2) iToken 'distFromPrevIP' distFromPrevAP = 0 # Increaset the iPhonoTier by one iPhonoTier = iPhonoTier +1 elsif rightmostPointLabel$ = "%" distFromPrevAP = distFromPrevAP + actualNumEojeol distFromPrevIP = distFromPrevIP + actualNumEojeol # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromPrevAP' Set interval text... (numTiers+2) iToken 'distFromPrevIP' # Reset the distance from an immediately preceding IP & AP to zero distFromPrevIP = 0 distFromPrevAP = 0 # Increaset the iPhonoTier by one iPhonoTier = iPhonoTier +1 else distFromPrevAP = distFromPrevAP + actualNumEojeol distFromPrevIP = distFromPrevIP + actualNumEojeol # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromPrevAP' Set interval text... (numTiers+2) iToken 'distFromPrevIP' endif # Otherwise, do not print the boundary types from the point tier below. # Just calculate the relevant distances else distFromPrevAP = distFromPrevAP + actualNumEojeol distFromPrevIP = distFromPrevIP + actualNumEojeol # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromPrevAP' Set interval text... (numTiers+2) iToken 'distFromPrevIP' endif endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList Remove #### END OF SCRIPT ####