########################################################################## # 03.distance.in.syllables.from-to.previous-following.comma tier extractor for Wagon: # Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 03.distance.in.syllables.from-to.previous-following.comma 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 02.token.length.in.syllables # and write the output files into 10.wagon-features\03.distance.in.syllables.from-to.previous-following.comma # The filename of the output files are .wagon.03 ########################################################################## form Select files word subFolderToProcess 10.wagon-features\02.token.length.in.syllables word fileExtOfDoneFiles wagon.02 word outputSubFolder 10.wagon-features\03.distance.in.syllables.from-to.previous-following.comma word tierNameToAdd1 dst.in.syl.pr.comma word tierNameToAdd2 dst.in.syl.ne.comma choice outputFileExt: 1 button wagon.03 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 syllables) from an immediately # preceding COMMA to 0 distFromPrevCO = 0 ######### Compute the distance, totalNumBtwCO, to the following COMMA ########### # This is only for the interval from the sentence beginning to the "first" occurrence of COMMA # ################################################################ totalNumBtwCO = 0 numTotalCharCO = 0 iTokenCO = 2 ######### Get the interval text (i.e., token text) ####### tempIntervalText$ = Get label of interval... 1 iTokenCO indexOfSlash = index(tempIntervalText$, "/") intervalTextCO$ = left$(tempIntervalText$, (indexOfSlash-1)) numTotalCharCO = length(intervalTextCO$) repeat numSylCO = 1 if (intervalTextCO$ = "PERIOD" or intervalTextCO$ = "NPERIOD" or intervalTextCO$ = "COMMA" or intervalTextCO$ = "HYPHEN" ... or intervalTextCO$ = "PLUS" or intervalTextCO$ = "COLON" or intervalTextCO$ = "LRB-" or intervalTextCO$ = "RRB-" ... or intervalTextCO$ = "DRQUOTE" or intervalTextCO$ = "DLQUOTE" or intervalTextCO$ = "SLQUOTE" ... or intervalTextCO$ = "SRQUOTE" or intervalTextCO$ = "LRB" or intervalTextCO$ = "RRB") numSylCO = numSylCO - 1 else while index(intervalTextCO$, "-") indexOfHyphenCO = index(intervalTextCO$, "-") # Calculate the number of the rest of the characters starting from the location of "-" subNumTotalCharCO = numTotalCharCO - indexOfHyphenCO intervalTextCO$ = right$(intervalTextCO$, subNumTotalCharCO) numTotalCharCO = length(intervalTextCO$) numSylCO = numSylCO + 1 endwhile endif totalNumBtwCO = totalNumBtwCO + numSylCO # Get the label for the (next) interval text iTokenCO = iTokenCO + 1 tempIntervalText$ = Get label of interval... 1 iTokenCO if tempIntervalText$ = "" intervalTextCO$ = "" else indexOfSlash = index(tempIntervalText$, "/") intervalTextCO$ = left$(tempIntervalText$, (indexOfSlash-1)) numTotalCharCO = length(intervalTextCO$) endif # Repeat this block until you come to the sentence end, indicated by or to the COMMA until (intervalTextCO$ = "" or intervalTextCO$ = "COMMA") ############# End of distance to "first" COMMA block ###################### ############# Loop through each interval (token) and extract info ###############100 for iToken from 2 to (numIntervals-1) # Initialize the number of syllable for the eojeol actualNumSyl = 1 ######### Get the interval text (i.e., token text) ####### 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 eojeol (e.g. "peu-lang-seu" is 3-syllable long) # If there is no "-" in the eojeol, then the number of syllable for that eojeol 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 ############################ ########## Compute the distance from/to previous/next COMMA ############ # If the current interval text is "COMMA", compute the distance of the interval to the # # immediately following comma and use that to compute the distances. # # This is for the interval from the first COMMA to the rest of the sentence. # ########################################################### tempIntervalText$ = Get label of interval... 1 iToken indexOfSlash = index(tempIntervalText$, "/") intervalText$ = left$(tempIntervalText$, (indexOfSlash-1)) # If the interval text is COMMA, then we need to calculate the inter-COMMA distance again # after we print out if intervalText$ = "COMMA" distFromPrevCO = distFromPrevCO + actualNumSyl # Compute the distance to the next COMMA distFromNextCO = totalNumBtwCO - actualNumSyl # Initialize the distance from previous COMMA distFromPrevCO = 0 ########## Compute the inter-COMMA distance ################## totalNumBtwCO = 1 numTotalCharCO = 0 iTokenCO = iToken + 1 # Get the label for the (next) interval text tempIntervalText$ = Get label of interval... 1 iTokenCO indexOfSlash = index(tempIntervalText$, "/") intervalTextCO$ = left$(tempIntervalText$, (indexOfSlash-1)) numTotalCharCO = length(intervalTextCO$) repeat numSylCO2 = 1 # If the interval text is one of these, don't increase the number of syllables if (intervalTextCO$ = "PERIOD" or intervalTextCO$ = "NPERIOD" ... or intervalTextCO$ = "HYPHEN" or intervalTextCO$ = "PLUS" ... or intervalTextCO$ = "COLON" or intervalTextCO$ = "LRB-" ... or intervalTextCO$ = "RRB-" or intervalTextCO$ = "LRB" ... or intervalTextCO$ = "RRB" or intervalTextCO$ = "DLQUOTE" ... or intervalTextCO$ = "DRQUOTE" or intervalTextCO$ = "SLQUOTE" ... or intervalTextCO$ = "SRQUOTE") numSylCO2 = numSylCO2 -1 # Otherwise, calculate the number of syllables for that interval else while index(intervalTextCO$, "-") indexOfHyphenCO = index(intervalTextCO$, "-") # Calculate the number of the rest of the # characters starting from the location of "-" subNumTotalCharCO = numTotalCharCO - indexOfHyphenCO intervalTextCO$ = right$(intervalTextCO$, subNumTotalCharCO) numTotalCharCO = length(intervalTextCO$) numSylCO2 = numSylCO2 + 1 endwhile endif totalNumBtwCO = totalNumBtwCO + numSylCO2 # Increase the counter by one and move to the next interval text iTokenCO = iTokenCO + 1 tempIntervalText$ = Get label of interval... 1 iTokenCO if tempIntervalText$ = "" intervalTextCO$ = "" else indexOfSlash = index(tempIntervalText$, "/") intervalTextCO$ = left$(tempIntervalText$, (indexOfSlash-1)) numTotalCharCO = length(intervalTextCO$) endif # and keep doing this until you come to either the end of sentence or next COMMA until (intervalTextCO$ = "" or intervalTextCO$ = "COMMA") # Debugged, but don't know for sure why this happened totalNumBtwCO = totalNumBtwCO - 1 ########### End of inter-COMMA distance block ################## else distFromPrevCO = distFromPrevCO + actualNumSyl distFromNextCO = totalNumBtwCO - actualNumSyl totalNumBtwCO = totalNumBtwCO - actualNumSyl endif ################# End of distance from/to previous/next COMMA ############ # Set interval text according to above result Set interval text... (numTiers+1) iToken 'distFromPrevCO' Set interval text... (numTiers+2) iToken 'distFromNextCO' endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList Remove #### END OF SCRIPT ####