Example #1
0
 def getHTML(self):
     '''
     Returns html for a page where users mark either breaks or prominence
     
     
     '''
     pageTemplate = join(constants.htmlDir, "wavTemplate.html")
     
     txtFN = join(self.txtDir, self.transcriptName + ".txt")
     
     sentenceList = loader.loadTxtFile(txtFN)
     
     testType = self.pageName
     
     # Construct the HTML here
     
     htmlTxt = _doBreaksOrProminence(testType, 0, 0,
                                     self.name,
                                     self.textDict[self.instructText],
                                     self.textDict['play_button'],
                                     sentenceList, self.presentAudio,
                                     self.boundaryToken,
                                     self.syllableDemarcator)[0]
 
     if self.presentAudio is True:
         embedTxt = ""
         embed = audio.generateEmbed(self.wavDir,
                                     [self.name, ],
                                     self.webSurvey.audioExtList,
                                     "audio")
         embedTxt += "\n\n" + embed
         embedTxt += _getKeyPressEmbed(self.bindPlayKeyID,
                                       self.bindSubmitID)
     else:
         embedTxt = ""
     embedTxt += "\n\n"
     
     htmlTxt = html.makeNoWrap(htmlTxt)
     
     return htmlTxt, pageTemplate, {'embed': embedTxt}
    def getHTML(self):
        '''
        Listeners hear two files and decide if they are the same or different
        '''
        pageTemplate = join(self.webSurvey.htmlDir, "axbTemplate.html")
        availableFunctions = getToggleButtonsJS(1, "range%d")
        
        txtFN = join(self.txtDir, self.transcriptName + ".txt")
        sentenceList = loader.loadTxtFile(txtFN)
        transcriptTxt = "<br /><br />\n\n".join(sentenceList)

        audioLabel = self.textDict['play_button']
        playBtnSnippet = audio.generateAudioButton(self.mediaName, 0,
                                                   audioLabel,
                                                   0,
                                                   False)
        
        runOnMinThresholdJS = "enable_checkboxes();"
        embedTxt = ""
        
        mediaNames = [self.mediaName, ]
        
        if self.audioOrVideo == "audio":
            extList = self.webSurvey.audioExtList
        else:
            extList = self.webSurvey.videoExtList
        embedTxt += "\n\n" + audio.generateEmbed(self.wavDir,
                                                 list(set(mediaNames)),
                                                 extList,
                                                 self.audioOrVideo)
        embedTxt += "\n\n" + availableFunctions
        
        description = self.textDict[self.instructionText]

        htmlText = description + self._getHTMLTxt()
        htmlText %= (playBtnSnippet + "<br />" + transcriptTxt)
    
        return htmlText, pageTemplate, {'embed': embedTxt}
    def getHTML(self):
        '''
        Listeners hear two files and decide if they are the same or different
        '''
        pageTemplate = join(self.webSurvey.htmlDir, "axbTemplate.html")
        availableFunctions = getToggleButtonsJS(1, "range%d")
        
        txtFN = join(self.txtDir, self.transcriptName + ".txt")
        sentenceList = loader.loadTxtFile(txtFN)
        transcriptTxt = "<br /><br />\n\n".join(sentenceList)

        audioLabel = self.textDict['play_button']
        playBtnSnippet = audio.generateAudioButton(self.mediaName, 0,
                                                   audioLabel,
                                                   0,
                                                   False)
        
        runOnMinThresholdJS = "enable_checkboxes();"
        embedTxt = ""
        
        mediaNames = [self.mediaName, ]
        
        if self.audioOrVideo == "audio":
            extList = self.webSurvey.audioExtList
        else:
            extList = self.webSurvey.videoExtList
        embedTxt += "\n\n" + audio.generateEmbed(self.wavDir,
                                                 list(set(mediaNames)),
                                                 extList,
                                                 self.audioOrVideo)
        embedTxt += "\n\n" + availableFunctions
        
        description = self.textDict[self.instructionText]

        htmlText = description + self._getHTMLTxt()
        htmlText %= (playBtnSnippet + "<br />" + transcriptTxt)
    
        return htmlText, pageTemplate, {'embed': embedTxt}
Example #4
0
 def getHTML(self):
     '''
     Returns html for a page where users mark both breaks and prominence
     
     Subjects first mark up the boundaries.  They are then shown the same
     utterance with their original markings still present.  They are then
     asked to mark boundaries.
     
     'focus' - either 'meaning' or 'acoustics' -- used to print the correct
         instructions
     '''
     
     pageTemplate = join(constants.htmlDir, "wavTemplate.html")
     
     txtFN = join(self.txtDir, self.transcriptName + ".txt")
     
     sentenceList = loader.loadTxtFile(txtFN)
     
     # Construct the HTML here
     # There are two passes of the utterance.  The first is for boundaries.
     # After
     wordIDNum = 0
     htmlTxt = '<div id="ShownDiv" style="DISPLAY: block">'
 
     # HTML boundaries
     audioLabel = self.textDict['play_button']
     stepOneInstructText = self.textDict[self.stepOneInstructText]
     tmpHTMLTxt, numWords = _doBreaksOrProminence(self.pageName,
                                                  wordIDNum, 0,
                                                  self.name,
                                                  stepOneInstructText,
                                                  audioLabel,
                                                  sentenceList,
                                                  self.presentAudio,
                                                  self.boundaryToken,
                                                  None)
     htmlTxt += "<div>%s</div>" % tmpHTMLTxt
 
     # HTML from transitioning from the boundary portion of text
     # to the prominence portion
     continueButtonTxt = self.textDict['continue_button']
     htmlTxt += '''<br /><br /><input type="button" value="%s"
                 id="halfwaySubmitButton"
                 onclick="ShowHide(audioLoader.verifyFirstAudioPlayed(), %s)"></button>''' % (continueButtonTxt, _getTogglableWordEmbed(self))
     htmlTxt += '</div>\n\n<div id="HiddenDiv" style="DISPLAY: none">\n\n'
     
     # HTML prominence
     stepTwoInstructText = self.textDict[self.stepTwoInstructText]
     htmlTxt += _doBreaksOrProminence(self.pageName, numWords, 1,
                                      self.name,
                                      stepTwoInstructText,
                                      audioLabel,
                                      sentenceList,
                                      self.presentAudio,
                                      self.boundaryToken,
                                      None)[0]
     htmlTxt += "</div>"
                 
     # Add the javascript and style sheets here
     if self.presentAudio is True:
         embedTxt = ""
         embed = audio.generateEmbed(self.wavDir,
                                     [self.name, ],
                                     self.webSurvey.audioExtList,
                                     "audio")
         embedTxt += "\n\n" + embed
         embedTxt += "\n\n" + _getKeyPressEmbed(self.bindPlayKeyID,
                                                self.bindSubmitID,
                                                True)
             
     else:
         embedTxt = ""
     
     htmlTxt = html.makeNoWrap(htmlTxt)
     
     return htmlTxt, pageTemplate, {'embed': embedTxt}
    def getHTML(self):
        '''
        Listeners hear two files and decide if they are the same or different
        '''
        pageTemplate = join(self.webSurvey.htmlDir, "axbTemplate.html")
        availableFunctions = getToggleButtonsJS(len(self.responseButtonList))
        
        # Generate the media buttons
        playBtnLabelRow = ''
        playBtnSnippet = ''
        template = "<td class='buttons'>%s</td>"
        for i in range(len(self.mediaList)):
            
            # Don't generate an audio button if the list is empty
            if len(self.mediaList[i]) == 0:
                continue
            
            audioLabel = self.textDict['play_button']
            mediaButtonHTML = audio.generateAudioButton(self.mediaList[i], i,
                                                        audioLabel,
                                                        self.pauseDuration,
                                                        False)
            if self.buttonLabelList is not None:
                label = self.textDict[self.buttonLabelList[i]]
                playBtnLabelRow += template % label
            playBtnSnippet += template % mediaButtonHTML
        
        # Add optional button labels
        playBtnSnippet = '<tr>%s</tr>' % playBtnSnippet
        if self.buttonLabelList is not None:
            playBtnLabelRow = '<tr>%s</tr>' % playBtnLabelRow
        
        playBtnSnippet = playBtnLabelRow + playBtnSnippet
        
        # Add optional speech transcripts
        if self.transcriptList is not None:
            transcriptList = [loader.loadTxtFile(join(self.txtDir,
                                                      transcript + ".txt"))
                              for transcript in self.transcriptList]
            transcriptList = ["<td>%s</td>" % "<br />".join(transcript)
                              for transcript in transcriptList]
                              
            transcriptTxt = "<tr>%s</tr>" % "".join(transcriptList)
            playBtnSnippet = playBtnSnippet + transcriptTxt
        
        playBtnSnippet = ('<table class="center">%s</table>') % playBtnSnippet
        
        runOnMinThresholdJS = "enable_checkboxes();"
        embedTxt = ""
        
        mediaNames = [mediaName for mediaSubList in self.mediaList
                      for mediaName in mediaSubList]
        if self._doPlayMedia():
            if self.audioOrVideo == "video":
                extList = self.webSurvey.videoExtList
            else:
                extList = self.webSurvey.audioExtList
            embedTxt += "\n\n" + audio.generateEmbed(self.wavDir,
                                                     list(set(mediaNames)),
                                                     extList,
                                                     self.audioOrVideo)
        
        embedTxt += "\n\n" + availableFunctions
        embedTxt += self._getKeyPressEmbed()
        
        description = self.textDict[self.instructionText]

        htmlText = description + self._getHTMLTxt()
        htmlText %= (playBtnSnippet + "<br />")
    
        return htmlText, pageTemplate, {'embed': embedTxt}
    def getHTML(self):
        '''
        Listeners hear two files and decide if they are the same or different
        '''
        pageTemplate = join(self.webSurvey.htmlDir, "axbTemplate.html")
        availableFunctions = getToggleButtonsJS(len(self.responseButtonList))
        
        # Generate the media buttons
        playBtnLabelRow = ''
        playBtnSnippet = ''
        template = "<td class='buttons'>%s</td>"
        for i in range(len(self.mediaList)):
            
            # Don't generate an audio button if the list is empty
            if len(self.mediaList[i]) == 0:
                continue
            
            audioLabel = self.textDict['play_button']
            mediaButtonHTML = audio.generateAudioButton(self.mediaList[i], i,
                                                        audioLabel,
                                                        self.pauseDuration,
                                                        False)
            if self.buttonLabelList is not None:
                label = self.textDict[self.buttonLabelList[i]]
                playBtnLabelRow += template % label
            playBtnSnippet += template % mediaButtonHTML
        
        # Add optional button labels
        playBtnSnippet = '<tr>%s</tr>' % playBtnSnippet
        if self.buttonLabelList is not None:
            playBtnLabelRow = '<tr>%s</tr>' % playBtnLabelRow
        
        playBtnSnippet = playBtnLabelRow + playBtnSnippet
        
        # Add optional speech transcripts
        if self.transcriptList is not None:
            transcriptList = [loader.loadTxtFile(join(self.txtDir,
                                                      transcript + ".txt"))
                              for transcript in self.transcriptList]
            transcriptList = ["<td>%s</td>" % "<br />".join(transcript)
                              for transcript in transcriptList]
                              
            transcriptTxt = "<tr>%s</tr>" % "".join(transcriptList)
            playBtnSnippet = playBtnSnippet + transcriptTxt
        
        playBtnSnippet = ('<table class="center">%s</table>') % playBtnSnippet
        
        runOnMinThresholdJS = "enable_checkboxes();"
        embedTxt = ""
        
        mediaNames = [mediaName for mediaSubList in self.mediaList
                      for mediaName in mediaSubList]
        if self._doPlayMedia():
            if self.audioOrVideo == "video":
                extList = self.webSurvey.videoExtList
            else:
                extList = self.webSurvey.audioExtList
            embedTxt += "\n\n" + audio.generateEmbed(self.wavDir,
                                                     list(set(mediaNames)),
                                                     extList,
                                                     self.audioOrVideo)
        
        embedTxt += "\n\n" + availableFunctions
        embedTxt += self._getKeyPressEmbed()
        
        description = self.textDict[self.instructionText]

        htmlText = description + self._getHTMLTxt()
        htmlText %= (playBtnSnippet + "<br />")
    
        return htmlText, pageTemplate, {'embed': embedTxt}
Example #7
0
def transposeRPT(path, txtPath, pageName, outputPath):
    '''
    Transposes RPT data
    
    Input files: one file per subject
    Output files: one file per stimuli
    '''
    utils.makeDir(outputPath)

    # Load response data
    responseDataList = []
    fnList = utils.findFiles(path, filterExt=".csv")
    for fn in fnList:
        a = user_response.loadUserResponse(join(path, fn))
        responseDataList.append(a)
    
    # Load the demarcator, if there is one
    # and load the order info if present
    demarcator = None
    pageName, pageArgs, _, _ = responseDataList[0][0]
    if pageName == "syllable_marking":
        
        # The demarcator can either be an arg or a keyword arg.
        # Either way, it should be the last item in the list
        demarcator = pageArgs[-1]
        if "syllableDemarcator" in demarcator:
            demarcator = demarcator.split("=")[1]
    
    # Sort response if sequence order information is available
    parsedTuple = transpose_utils.parseResponse(responseDataList)
    responseDataList, _, orderListOfLists = parsedTuple
    orderList = []
    if len(orderListOfLists) > 0:
        orderList = [",".join(row) for row
                     in utils.safeZip(orderListOfLists, True)]
    
    # Load Words
    txtDict = {}
    for fn in utils.findFiles(txtPath, filterExt=".txt"):
        name = os.path.splitext(fn)[0]
        txtList = loader.loadTxtFile(join(txtPath, fn))
        
        txtList = [tmpTxt.replace(" ", ",") for tmpTxt in txtList]
        
        # Remove HTML tags
        txtList = [word for word in txtList if "<" not in word]
        
        txt = ",".join(txtList)
        
        if demarcator is None:
            txtDict[name] = [word for word in txt.split(",") if word != ""]
        else:
            txtDict[name] = [syllable for word in txt.split(",") if word != ""
                             for syllable in word.split(demarcator)]
    
    returnDict, idKeyList = _transposeRPT(responseDataList)
    
    doUserSeqHeader = len(orderListOfLists) > 0
    headerRow, anonHeaderRow = _buildHeader(fnList, pageName,
                                            doUserSeqHeader,
                                            idKeyList[0])
    
    # Format the output rpt scores
    aggrOutputList = [headerRow, anonHeaderRow]
    for i in range(len(idKeyList)):
        
        stimulusID = idKeyList[i]

        wordList = txtDict[stimulusID.split(",")[2]]
        stimulusIDList = [stimulusID for _ in wordList]
        aspectSumList = [stimulusIDList, wordList, ]
        aspectList = []

        try:
            bScoreList, bSumList = _getScores(returnDict[stimulusID],
                                              B)
        except KeyError:
            pass
        try:
            pScoreList, pSumList = _getScores(returnDict[stimulusID],
                                              P)
        except KeyError:
            pass
        
        if pageName == "boundary":
            aspectSumList.extend([bSumList, ])
            aspectList.extend([bScoreList, ])
        elif pageName in ["prominence", "syllable_marking"]:
            aspectSumList.extend([pSumList, ])
            aspectList.extend([pScoreList, ])
        elif pageName == "boundary_and_prominence":
            aspectSumList.extend([bSumList, pSumList, ])
            aspectList.extend([bScoreList, pScoreList, ])
    
        # Extend header with sequence order information
        if doUserSeqHeader:
            orderStr = orderList[i]
            numAnnotators = range(max([len(bSumList), len(pSumList)]))
            tmpOrderList = [orderStr for _ in numAnnotators]
            aspectList.extend([tmpOrderList, ])
            
        dataList = aspectSumList + aspectList
        combinedList = [_unifyRow(row) for row in
                        utils.safeZip(dataList, enforceLength=True)]
        aggrOutputList.extend([",".join(row) for row in combinedList])
        
    outputTxt = "\n".join(aggrOutputList)
    
    outputFN = join(outputPath, pageName + ".csv")
    with io.open(outputFN, "w", encoding="utf-8") as fd:
        fd.write(outputTxt)
Example #8
0
def transposeRPT(path, txtPath, pageName, outputPath):
    '''
    Transposes RPT data
    
    Input files: one file per subject
    Output files: one file per stimuli
    '''
    utils.makeDir(outputPath)

    # Load response data
    responseDataList = []
    fnList = utils.findFiles(path, filterExt=".csv")
    for fn in fnList:
        a = user_response.loadUserResponse(join(path, fn))
        responseDataList.append(a)

    # Load the demarcator, if there is one
    # and load the order info if present
    demarcator = None
    pageName, pageArgs, _, _ = responseDataList[0][0]
    if pageName == "syllable_marking":

        # The demarcator can either be an arg or a keyword arg.
        # Either way, it should be the last item in the list
        demarcator = pageArgs[-1]
        if "syllableDemarcator" in demarcator:
            demarcator = demarcator.split("=")[1]

    # Sort response if sequence order information is available
    parsedTuple = transpose_utils.parseResponse(responseDataList)
    responseDataList, _, orderListOfLists = parsedTuple
    orderList = []
    if len(orderListOfLists) > 0:
        orderList = [
            ",".join(row) for row in utils.safeZip(orderListOfLists, True)
        ]

    # Load Words
    txtDict = {}
    for fn in utils.findFiles(txtPath, filterExt=".txt"):
        name = os.path.splitext(fn)[0]
        txtList = loader.loadTxtFile(join(txtPath, fn))

        txtList = [tmpTxt.replace(" ", ",") for tmpTxt in txtList]

        # Remove HTML tags
        txtList = [word for word in txtList if "<" not in word]

        txt = ",".join(txtList)

        if demarcator is None:
            txtDict[name] = [word for word in txt.split(",") if word != ""]
        else:
            txtDict[name] = [
                syllable for word in txt.split(",") if word != ""
                for syllable in word.split(demarcator)
            ]

    returnDict, idKeyList = _transposeRPT(responseDataList)

    doUserSeqHeader = len(orderListOfLists) > 0
    headerRow, anonHeaderRow = _buildHeader(fnList, pageName, doUserSeqHeader,
                                            idKeyList[0])

    # Format the output rpt scores
    aggrOutputList = [headerRow, anonHeaderRow]
    for i in range(len(idKeyList)):

        stimulusID = idKeyList[i]

        wordList = txtDict[stimulusID.split(",")[2]]
        stimulusIDList = [stimulusID for _ in wordList]
        aspectSumList = [
            stimulusIDList,
            wordList,
        ]
        aspectList = []

        try:
            bScoreList, bSumList = _getScores(returnDict[stimulusID], B)
        except KeyError:
            pass
        try:
            pScoreList, pSumList = _getScores(returnDict[stimulusID], P)
        except KeyError:
            pass

        if pageName == "boundary":
            aspectSumList.extend([
                bSumList,
            ])
            aspectList.extend([
                bScoreList,
            ])
        elif pageName in ["prominence", "syllable_marking"]:
            aspectSumList.extend([
                pSumList,
            ])
            aspectList.extend([
                pScoreList,
            ])
        elif pageName == "boundary_and_prominence":
            aspectSumList.extend([
                bSumList,
                pSumList,
            ])
            aspectList.extend([
                bScoreList,
                pScoreList,
            ])

        # Extend header with sequence order information
        if doUserSeqHeader:
            orderStr = orderList[i]
            numAnnotators = range(max([len(bSumList), len(pSumList)]))
            tmpOrderList = [orderStr for _ in numAnnotators]
            aspectList.extend([
                tmpOrderList,
            ])

        dataList = aspectSumList + aspectList
        combinedList = [
            _unifyRow(row)
            for row in utils.safeZip(dataList, enforceLength=True)
        ]
        aggrOutputList.extend([",".join(row) for row in combinedList])

    outputTxt = "\n".join(aggrOutputList)

    outputFN = join(outputPath, pageName + ".csv")
    with io.open(outputFN, "w", encoding="utf-8") as fd:
        fd.write(outputTxt)