########################################################################## # 12.distance.in.eojeols.from.sentence.beginning&end tier extractor for Wagon: # Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 12.distance.in.eojeols.from.sentence.beginning&end 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 11.distance.in.syllables.from.sentence.beginning&end # and write the output files into 10.wagon-features\12.distance.in.eojeols.from.sentence.beginning&end # The filename of the output files are .wagon.12 ########################################################################## form Select files word subFolderToProcess 10.wagon-features\11.distance.in.syllables.from.sentence.beginning&end word fileExtOfDoneFiles wagon.11 word outputSubFolder 10.wagon-features\12.distance.in.eojeols.from.sentence.beginning&end word tierNameToAdd1 dst.in.eoj.S.start word tierNameToAdd2 dst.in.eoj.S.end choice outputFileExt: 1 button wagon.12 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 ######## Block for calculating the total number of eojeols for the whole sentence ####### ######## This will be used to compute the distance from the sentence end ####### ################################################################ # Initialize the number of total eojeols for the sentence totalNum = 0 for iToken from 2 to (numIntervals-1) ######### Get the interval text (i.e., token text) ####### tempIntervalText$ = Get label of interval... 1 iToken rightMostLetter$ = right$(tempIntervalText$, 1) # If the token is followed by a eojeol boundary "#", then increase the number of eojeols by one if rightMostLetter$ = "#" totalNum = totalNum + 1 endif endfor ################# End of sentence length detection block #################### # Initialize the distance (in number of eojeols) from the sentence beginning to zero distFromSentBegin = 0 ############# Loop through each interval 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 rightMostLetter$ = right$(tempIntervalText$, 1) # If the token is followed by a eojeol boundary "#", then increase the number of eojeols by one if rightMostLetter$ = "#" actualNumEojeol = actualNumEojeol + 1 endif # Compute the distance from the sentence beginning distFromSentBegin = distFromSentBegin + actualNumEojeol # Compute the distance from the end of the sentence distFromSentEnd = totalNum - distFromSentBegin # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromSentBegin' Set interval text... (numTiers+2) iToken 'distFromSentEnd' endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList Remove #### END OF SCRIPT ####