本文整理匯總了Python中nltk.compat.raw_input方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.raw_input方法的具體用法?Python compat.raw_input怎麽用?Python compat.raw_input使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nltk.compat
的用法示例。
在下文中一共展示了compat.raw_input方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _simple_interactive_download
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import raw_input [as 別名]
def _simple_interactive_download(self, args):
if args:
for arg in args:
try: self._ds.download(arg, prefix=' ')
except (IOError, ValueError) as e: print(e)
else:
while True:
print()
print('Download which package (l=list; x=cancel)?')
user_input = compat.raw_input(' Identifier> ')
if user_input.lower()=='l':
self._ds.list(self._ds.download_dir, header=False,
more_prompt=True, skip_installed=True)
continue
elif user_input.lower() in ('x', 'q', ''):
return
elif user_input:
for id in user_input.split():
try: self._ds.download(id, prefix=' ')
except (IOError, ValueError) as e: print(e)
break
示例2: converse
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import raw_input [as 別名]
def converse(self, quit="quit"):
input = ""
while input != quit:
input = quit
try: input = compat.raw_input(">")
except EOFError:
print(input)
if input:
while input[-1] in "!.": input = input[:-1]
print(self.respond(input))
示例3: list
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import raw_input [as 別名]
def list(self, download_dir=None, show_packages=True,
show_collections=True, header=True, more_prompt=False,
skip_installed=False):
lines = 0 # for more_prompt
if download_dir is None:
download_dir = self._download_dir
print('Using default data directory (%s)' % download_dir)
if header:
print('='*(26+len(self._url)))
print(' Data server index for <%s>' % self._url)
print('='*(26+len(self._url)))
lines += 3 # for more_prompt
stale = partial = False
categories = []
if show_packages: categories.append('packages')
if show_collections: categories.append('collections')
for category in categories:
print('%s:' % category.capitalize())
lines += 1 # for more_prompt
for info in sorted(getattr(self, category)(), key=str):
status = self.status(info, download_dir)
if status == self.INSTALLED and skip_installed: continue
if status == self.STALE: stale = True
if status == self.PARTIAL: partial = True
prefix = {self.INSTALLED:'*', self.STALE:'-',
self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
name = textwrap.fill('-'*27 + (info.name or info.id),
75, subsequent_indent=27*' ')[27:]
print(' [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
lines += len(name.split('\n')) # for more_prompt
if more_prompt and lines > 20:
user_input = compat.raw_input("Hit Enter to continue: ")
if (user_input.lower() in ('x', 'q')): return
lines = 0
print()
msg = '([*] marks installed packages'
if stale: msg += '; [-] marks out-of-date or corrupt packages'
if partial: msg += '; [P] marks partially installed collections'
print(textwrap.fill(msg+')', subsequent_indent=' ', width=76))
示例4: run
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import raw_input [as 別名]
def run(self):
print('NLTK Downloader')
while True:
self._simple_interactive_menu(
'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
user_input = compat.raw_input('Downloader> ').strip()
if not user_input: print(); continue
command = user_input.lower().split()[0]
args = user_input.split()[1:]
try:
if command == 'l':
print()
self._ds.list(self._ds.download_dir, header=False,
more_prompt=True)
elif command == 'h':
self._simple_interactive_help()
elif command == 'c':
self._simple_interactive_config()
elif command in ('q', 'x'):
return
elif command == 'd':
self._simple_interactive_download(args)
elif command == 'u':
self._simple_interactive_update()
else:
print('Command %r unrecognized' % user_input)
except compat.HTTPError as e:
print('Error reading from server: %s'%e)
except compat.URLError as e:
print('Error connecting to server: %s'%e.reason)
# try checking if user_input is a package name, &
# downloading it?
print()
示例5: _simple_interactive_update
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import raw_input [as 別名]
def _simple_interactive_update(self):
while True:
stale_packages = []
stale = partial = False
for info in sorted(getattr(self._ds, 'packages')(), key=str):
if self._ds.status(info) == self._ds.STALE:
stale_packages.append((info.id, info.name))
print()
if stale_packages:
print('Will update following packages (o=ok; x=cancel)')
for pid, pname in stale_packages:
name = textwrap.fill('-'*27 + (pname),
75, subsequent_indent=27*' ')[27:]
print(' [ ] %s %s' % (pid.ljust(20, '.'), name))
print()
user_input = compat.raw_input(' Identifier> ')
if user_input.lower()=='o':
for pid, pname in stale_packages:
try: self._ds.download(pid, prefix=' ')
except (IOError, ValueError) as e: print(e)
break
elif user_input.lower() in ('x', 'q', ''):
return
else:
print('Nothing to update.')
return