########################################################################## # 02.token.length.in.syllables tier extractor for Wagon: Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 02.token.length.in.syllables 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 10.wagon-features\01.morpheme.identity # and write the output files into 10.wagon-features\02.token.length.in.syllables # The filename of the output files are .wagon.02 ########################################################################## form Select files word subFolderToProcess 10.wagon-features\01.morpheme.identity word fileExtOfDoneFiles wagon.01 word outputSubFolder 10.wagon-features\02.token.length.in.syllables word tierNameToAdd tok.len.in.sylls choice outputFileExt: 1 button wagon.02 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) 'tierNameToAdd$' # Set the first/last interval text to naught Set interval text... (numTiers+1) 1 Set interval text... (numTiers+1) numIntervals ############# Loop through each interval (token) and extract info ############### for iToken from 2 to (numIntervals-1) # Initialize the number of syllable for the token actualNumSyl = 1 ######### Get the interval text (i.e., token text), excluding the label ####### tempIntervalText$ = Get label of interval... 1 iToken indexOfSlash = index(tempIntervalText$, "/") intervalText$ = left$(tempIntervalText$, (indexOfSlash-1)) ######### Compute the number of syllables for the interval ################# # If the interval is one of the "unpronounced" symbols, do not increase the number # # Otherwise, loop through each hyphen "-" and count the number of syllables # ########################################################### if (intervalText$ = "PERIOD" or intervalText$ = "NPERIOD" or intervalText$ = "COMMA" or intervalText$ = "HYPHEN" ... or intervalText$ = "PLUS" or intervalText$ = "COLON" or intervalText$ = "LRB-" or intervalText$ = "RRB-" ... or intervalText$ = "DRQUOTE" or intervalText$ = "DLQUOTE" or intervalText$ = "SLQUOTE" ... or intervalText$ = "SRQUOTE" or intervalText$ = "LRB" or intervalText$ = "RRB") actualNumSyl = actualNumSyl-1 else numTotalChar = length(intervalText$) # Count the number of syllables for that token (e.g. "peu-lang-seu" is 3-syllable long) # If there is no "-" in the eojeol, then the number of syllable for that token is numSyl, i.e. 1 syllable. # Otherwise, repeat the following procedure to count the number of hyphens while index(intervalText$, "-") indexOfHyphen = index(intervalText$, "-") # Calculate the number of the rest of the characters starting from the location of "-" subNumTotalChar = numTotalChar - indexOfHyphen intervalText$ = right$(intervalText$, subNumTotalChar) numTotalChar = length(intervalText$) actualNumSyl = actualNumSyl+1 endwhile endif ########## End of syllable number block ############################ # Set interval text according to above result Set interval text... (numTiers+1) iToken 'actualNumSyl' endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList Remove #### END OF SCRIPT ####