########################################################################## # 19.POS.of.+1.following.token tier extractor for Wagon: # Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 19.POS.of.+1.following.token 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 18.POS.of.-1.previous.token # and write the output files into 10.wagon-features\19.POS.of.+1.following.token # The filename of the output files are .wagon.19 # Assumes that you have a token/POS column in a file 055.POS-big-original\ejk-tok.+1.POS # This script splits a column of token/POS pairs into POSs of each sentence separated by SFN (POS) ########################################################################## form Select files word tokenFile_(with_path) 055.POS-big-original\ejk-tok.+1.POS word subFolderToProcess 10.wagon-features\18.POS.of.-1.previous.token word fileExtOfDoneFiles wagon.18 word outputSubFolder 10.wagon-features\19.POS.of.+1.following.token word tierNameToAdd POS.of.+1.following.token choice outputFileExt: 1 button wagon.19 endform Read Strings from raw text file... 'tokenFile$' Rename... tokenFile # Get the list of filenames of TextGrid. files Create Strings as file list... fileList 'subFolderToProcess$'\*.'fileExtOfDoneFiles$' Sort numFiles = Get number of strings pause 'numFiles' labeled textgrids identified. Continue? # Initialize the line number for .POS file. Will be used for giving info when discrepancy exists btw/ # the numbers of POSs and intervals. And iLineNumPOS for extracting one token at a time from the .POS file. # And numPOS for number of POSs in one sentence in the .POS file lineNumPOS = 1 iLineNumPOS = 1 numPOS = 0 # Loop throught each file for iFile to numFiles select Strings fileList # Get the name for a TextGrid 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 for iToken from 2 to (numIntervals-1) # If the token is followed by "#", then take letters between / and # # Otherwise, take what's on the RHS of the slash select Strings tokenFile token$ = Get string... iLineNumPOS lengthOfToken = length(token$) positionOfSlash = index(token$, "/") restAfterSlash$ = right$(token$, (lengthOfToken-positionOfSlash)) lengthOfRestAfterSlash = length(restAfterSlash$) rightMostLetter$ = right$(restAfterSlash$, 1) if rightMostLetter$ = "#" realPOS$ = left$(restAfterSlash$, (lengthOfRestAfterSlash-1)) else realPOS$ = restAfterSlash$ endif # Put the POS label into each interval select TextGrid textGrid ############ The first interval should always be zero if iToken < (numIntervals-1) Set interval text... (numTiers+1) iToken 'realPOS$' else Set interval text... (numTiers+1) iToken 0 endif iLineNumPOS = iLineNumPOS + 1 endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList plus Strings tokenFile Remove #### END OF SCRIPT ####