当前位置: 首页>>代码示例>>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;未经允许,请勿转载。