########################################################################## # 16.POS.of.-3.previous.token tier extractor for Wagon: # Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Extracts from a set of .TextGrid.lab files 16.POS.of.-3.previous.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 15.POS.of.current.token # and write the output files into 10.wagon-features\16.POS.of.-3.previous.token # The filename of the output files are .wagon.16 # Assumes that you have a token/POS column in a file 055.POS-big-original\ejk-tok.-3.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.-3.POS word subFolderToProcess 10.wagon-features\15.POS.of.current.token word fileExtOfDoneFiles wagon.15 word outputSubFolder 10.wagon-features\16.POS.of.-3.previous.token word tierNameToAdd POS.of.-3.previous.token choice outputFileExt: 1 button wagon.16 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 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 three intervals should always be zero if iToken < 5 Set interval text... (numTiers+1) iToken 0 else Set interval text... (numTiers+1) iToken 'realPOS$' endif iLineNumPOS = iLineNumPOS + 1 endfor Edit pause Write to text file... 'outputSubFolder$'\'filePrefix$''outputFileExt$' Remove endfor select Strings fileList Remove #### END OF SCRIPT ####