我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用nltk.downloader()。
def _download(self, *e): # If we're using threads, then delegate to the threaded # downloader instead. if self._use_threads: return self._download_threaded(*e) marked = [self._table[row, 'Identifier'] for row in range(len(self._table)) if self._table[row, 0] != ''] selection = self._table.selected_row() if not marked and selection is not None: marked = [self._table[selection, 'Identifier']] download_iter = self._ds.incr_download(marked, self._ds.download_dir) self._log_indent = 0 self._download_cb(download_iter, marked)
def _progress_alive(self): c = self._progressbar if not self._downloading: c.itemconfig('gradient', state='hidden') else: c.itemconfig('gradient', state='normal') x1, y1, x2, y2 = c.bbox('gradient') if x1 <= -100: c.move('gradient', (self._gradient_width*6)-4, 0) else: c.move('gradient', -4, 0) afterid = self.top.after(200, self._progress_alive) self._afterid['_progress_alive'] = afterid #///////////////////////////////////////////////////////////////// # Threaded downloader #/////////////////////////////////////////////////////////////////
def _info_or_id(self, info_or_id): if isinstance(info_or_id, compat.string_types): return self.info(info_or_id) else: return info_or_id # [xx] When during downloading is it 'safe' to abort? Only unsafe # time is *during* an unzip -- we don't want to leave a # partially-unzipped corpus in place because we wouldn't notice # it. But if we had the exact total size of the unzipped corpus, # then that would be fine. Then we could abort anytime we want! # So this is really what we should do. That way the threaded # downloader in the gui can just kill the download thread anytime # it wants.
def __init__(self, dataserver, use_threads=True): self._ds = dataserver self._use_threads = use_threads # For the threaded downloader: self._download_lock = threading.Lock() self._download_msg_queue = [] self._download_abort_queue = [] self._downloading = False # For tkinter after callbacks: self._afterid = {} # A message log. self._log_messages = [] self._log_indent = 0 self._log('NLTK Downloader Started!') # Create the main window. top = self.top = Tk() top.geometry('+50+50') top.title('NLTK Downloader') top.configure(background=self._BACKDROP_COLOR[1]) # Set up some bindings now, in case anything goes wrong. top.bind('<Control-q>', self.destroy) top.bind('<Control-x>', self.destroy) self._destroyed = False self._column_vars = {} # Initialize the GUI. self._init_widgets() self._init_menu() try: self._fill_table() except compat.HTTPError as e: showerror('Error reading from server', e) except compat.URLError as e: showerror('Error connecting to server', e.reason) self._show_info() self._select_columns() self._table.select(0) # Make sure we get notified when we're destroyed, so we can # cancel any download in progress. self._table.bind('<Destroy>', self._destroy)