当前位置: 首页>>代码示例>>Python>>正文


Python Corpus.extend_corpus方法代码示例

本文整理汇总了Python中orangecontrib.text.corpus.Corpus.extend_corpus方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.extend_corpus方法的具体用法?Python Corpus.extend_corpus怎么用?Python Corpus.extend_corpus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在orangecontrib.text.corpus.Corpus的用法示例。


在下文中一共展示了Corpus.extend_corpus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OWNYT

# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import extend_corpus [as 别名]

#.........这里部分代码省略.........
        self.error(1)
        # If a query is running, stop it.
        if self.query_running:
            self.query_running = False
            return

        if self.nyt_api:
            num_steps = min(math.ceil(self.all_hits/10), 100)

            # Update buttons.
            self.retrieve_other_button.setText('Stop retrieving')
            self.open_set_api_key_dialog_button.setEnabled(False)
            self.run_query_button.setEnabled(False)

            # Accumulate remaining results in these lists.
            remaining_docs = []
            num_metas = len(self.output_corpus.domain.metas)
            remaining_metas = np.empty((0, num_metas), dtype=object)
            remaining_classes = []

            self.query_running = True
            self.progressBarInit()
            for i in range(int(self.num_retrieved/10), num_steps):
                # Stop querying if the flag is not set.
                if not self.query_running:
                    break

                # Update the progress bar.
                self.progressBarSet(100.0 * (i/num_steps))

                res, cached, error = self.nyt_api.execute_query(i)

                if res:
                    docs, metas, meta_vars, class_values = parse_record_json(res, self.nyt_api.includes_fields)
                    remaining_docs += docs
                    remaining_metas = np.vstack((remaining_metas, np.array(metas)))
                    remaining_classes += class_values

                    # Update the info label.
                    self.num_retrieved += len(res["response"]["docs"])
                    info_label = "Records: {}\nRetrieved: {}".format(self.all_hits, self.num_retrieved)
                    if self.all_hits > 1000:
                        info_label += " (max 1000)"
                    self.query_info_label.setText(info_label)

                    if not cached:  # Only wait if an actual request was made.
                        sleep(1)
                else:
                    if error:
                        if isinstance(error, HTTPError):
                            self.error(1, "An error occurred(HTTP {})".format(error.code))
                        elif isinstance(error, URLError):
                            self.error(1, "An error occurred(URL {})".format(error.reason))
                        break
            self.progressBarFinished()
            self.query_running = False

            # Update the corpus.
            self.output_corpus.extend_corpus(remaining_docs, remaining_metas, remaining_classes, meta_vars)
            self.send(Output.CORPUS, self.output_corpus)

            if self.num_retrieved == min(self.all_hits, 1000):
                self.retrieve_other_button.setText('All available records retrieved')
                self.retrieve_other_button.setEnabled(False)
            else:
                self.retrieve_other_button.setText('Retrieve remaining records ({})'
                                                   .format(min(self.all_hits, 1000)-self.num_retrieved))
                self.retrieve_other_button.setFocus()

            self.open_set_api_key_dialog_button.setEnabled(True)
            self.run_query_button.setEnabled(True)

    def check_api_key(self, api_key):
        nyt_api = NYT(api_key)
        self.api_key = api_key
        self.api_key_updated(nyt_api.check_api_key())

    def api_key_updated(self, is_valid):
        self.api_key_is_valid = is_valid
        self.enable_controls()

        if is_valid:
            self.api_key_valid_label.setPixmap(QPixmap(_i("valid.svg"))
                                               .scaled(15, 15, QtCore.Qt.KeepAspectRatio))
            self.nyt_api = NYT(self.api_key)    # Set the NYT API object, if key is valid.
        else:
            self.api_key_valid_label.setPixmap(QPixmap(_i("invalid.svg"))
                                               .scaled(15, 15, QtCore.Qt.KeepAspectRatio))

    def enable_controls(self):
        for control in self.nyt_controls:
            control.setEnabled(self.api_key_is_valid)
        if not self.api_key_is_valid:
            self.open_set_api_key_dialog_button.setFocus()
        elif self.api_key_is_valid:
            self.run_query_button.setFocus()

    def open_set_api_key_dialog(self):
        api_dlg = APIKeyDialog(self, "New York Times API key")
        api_dlg.exec_()
开发者ID:kernc,项目名称:orange3-text,代码行数:104,代码来源:ownyt.py


注:本文中的orangecontrib.text.corpus.Corpus.extend_corpus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。