當前位置: 首頁>>代碼示例>>Python>>正文


Python DataModel.judged_documents_by_topic方法代碼示例

本文整理匯總了Python中datamodel.DataModel.judged_documents_by_topic方法的典型用法代碼示例。如果您正苦於以下問題:Python DataModel.judged_documents_by_topic方法的具體用法?Python DataModel.judged_documents_by_topic怎麽用?Python DataModel.judged_documents_by_topic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datamodel.DataModel的用法示例。


在下文中一共展示了DataModel.judged_documents_by_topic方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: CWR

# 需要導入模塊: from datamodel import DataModel [as 別名]
# 或者: from datamodel.DataModel import judged_documents_by_topic [as 別名]

#.........這裏部分代碼省略.........
        '''
        Updates the worker rationale list. If one or more worker IDs is 
        selected, this will display only the rationales by the selected 
        workers. Otherwise, this will display all rationales for the 
        selected Topic and Document.
        '''
        display_text = ''
        selected = [r for r in self._rationales if r.display.isChecked()]
        # If none are selected, display all.
        selected = selected if selected else self._rationales
        for r in selected:
            display_text += ('%s\n\n%s\n\n' % (r.rationale.label, r.rationale.rationale.rationale))
        self._worker_rationales.setText(display_text)

    def update_judgment_list(self, topic=None, document=None):
        '''
        Updates the worker judgment list. If one or more worker IDs is
        selected, this will display only the judgments of those selected
        workers. Otherwise, this will display the judgments from all workers.
        '''
        display_text = ''
        selected = [r for r in self._rationales if r.display.isChecked()]
        # If none are selected, display all.
        selected = selected if selected else self._rationales
        for r in selected:
            display_text += ('%s: %s\n' % (r.rationale.label, r.rationale.rationale.value))
        self._worker_judgments.setText(display_text)
        
    def update_rationale_text(self, text):
        '''
        This updates the text in the rationale display.
        '''
        self._rationale_display.set_text(text)
    
    def highlight_rationale(self, text):
        self._rationale_display.highlight(text)

    def load_document(self, url):
        self._rationale_display.load(QUrl(url))
        

#########################################################################################
# Signals                                                                               #
#########################################################################################

    def _topic_selected(self, item):
        '''
        Handler function - user selects a topic in the Topic View.
        
        Refreshes the list of documents in the Document View with 
        all documents for which a worker judgment has been loaded
        for that topic. Computes statistics across that topic.
        '''
        topic_id = item.text()

        # Update control selection.
        self._selected_topic = topic_id

        # Update statistics view.
        self.update_statistics(topic=str(topic_id))

        print ("Loading documents for topic %s" % topic_id)
        documents = self._dm.judged_documents_by_topic(topic_id)
        self.update_document_list([d.id for d in documents])

    def _document_selected(self, item):
        '''
        Handler function - user select a document in the Document View.
        
        Loads the text from that document into the rationale display
        and computes statistics for that document.
        '''
        document_id       = item.text()
        
        # Update control selection.
        self._selected_document = document_id

        # Grab control selections.
        selected_topic    = self._selected_topic
        selected_document = self._selected_document

        print ("Loading rationales for document %s, topic %s" % (selected_document, selected_topic))
        rationales = self._dm.judgments(selected_topic, selected_document)
        rationales = [Rationale(str(random.randint(1,10000)), r) for r in rationales]
        self.update_rationale_selection(rationales)

        # Update statistics view.
        self.update_statistics(str(selected_topic), str(selected_document))

        # Load document.
        document = next((d for d in self._dm.judged_documents() if d.id == selected_document), None)
        self.load_document(document.url)
        
    def _rationale_selection_changed(self, state):
        '''
        Handler function called when a user selects or deselects a rationale
        check box.
        '''
        worker = Thread(target=self.update_rationale_display)
        worker.start()
開發者ID:tylermcdonnell,項目名稱:cwr,代碼行數:104,代碼來源:cwr.py


注:本文中的datamodel.DataModel.judged_documents_by_topic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。