__init__.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # Natural Language Toolkit (NLTK)
  2. #
  3. # Copyright (C) 2001-2020 NLTK Project
  4. # Authors: Steven Bird <stevenbird1@gmail.com>
  5. # Edward Loper <edloper@gmail.com>
  6. # URL: <http://nltk.org/>
  7. # For license information, see LICENSE.TXT
  8. """
  9. The Natural Language Toolkit (NLTK) is an open source Python library
  10. for Natural Language Processing. A free online book is available.
  11. (If you use the library for academic research, please cite the book.)
  12. Steven Bird, Ewan Klein, and Edward Loper (2009).
  13. Natural Language Processing with Python. O'Reilly Media Inc.
  14. http://nltk.org/book
  15. """
  16. import os
  17. # //////////////////////////////////////////////////////
  18. # Metadata
  19. # //////////////////////////////////////////////////////
  20. # Version. For each new release, the version number should be updated
  21. # in the file VERSION.
  22. try:
  23. # If a VERSION file exists, use it!
  24. version_file = os.path.join(os.path.dirname(__file__), "VERSION")
  25. with open(version_file, "r") as infile:
  26. __version__ = infile.read().strip()
  27. except NameError:
  28. __version__ = "unknown (running code interactively?)"
  29. except IOError as ex:
  30. __version__ = "unknown (%s)" % ex
  31. if __doc__ is not None: # fix for the ``python -OO``
  32. __doc__ += "\n@version: " + __version__
  33. # Copyright notice
  34. __copyright__ = """\
  35. Copyright (C) 2001-2020 NLTK Project.
  36. Distributed and Licensed under the Apache License, Version 2.0,
  37. which is included by reference.
  38. """
  39. __license__ = "Apache License, Version 2.0"
  40. # Description of the toolkit, keywords, and the project's primary URL.
  41. __longdescr__ = """\
  42. The Natural Language Toolkit (NLTK) is a Python package for
  43. natural language processing. NLTK requires Python 2.6 or higher."""
  44. __keywords__ = [
  45. "NLP",
  46. "CL",
  47. "natural language processing",
  48. "computational linguistics",
  49. "parsing",
  50. "tagging",
  51. "tokenizing",
  52. "syntax",
  53. "linguistics",
  54. "language",
  55. "natural language",
  56. "text analytics",
  57. ]
  58. __url__ = "http://nltk.org/"
  59. # Maintainer, contributors, etc.
  60. __maintainer__ = "Steven Bird, Edward Loper, Ewan Klein"
  61. __maintainer_email__ = "stevenbird1@gmail.com"
  62. __author__ = __maintainer__
  63. __author_email__ = __maintainer_email__
  64. # "Trove" classifiers for Python Package Index.
  65. __classifiers__ = [
  66. "Development Status :: 5 - Production/Stable",
  67. "Intended Audience :: Developers",
  68. "Intended Audience :: Education",
  69. "Intended Audience :: Information Technology",
  70. "Intended Audience :: Science/Research",
  71. "License :: OSI Approved :: Apache Software License",
  72. "Operating System :: OS Independent",
  73. "Programming Language :: Python :: 2.6",
  74. "Programming Language :: Python :: 2.7",
  75. "Topic :: Scientific/Engineering",
  76. "Topic :: Scientific/Engineering :: Artificial Intelligence",
  77. "Topic :: Scientific/Engineering :: Human Machine Interfaces",
  78. "Topic :: Scientific/Engineering :: Information Analysis",
  79. "Topic :: Text Processing",
  80. "Topic :: Text Processing :: Filters",
  81. "Topic :: Text Processing :: General",
  82. "Topic :: Text Processing :: Indexing",
  83. "Topic :: Text Processing :: Linguistic",
  84. ]
  85. from nltk.internals import config_java
  86. # support numpy from pypy
  87. try:
  88. import numpypy
  89. except ImportError:
  90. pass
  91. # Override missing methods on environments where it cannot be used like GAE.
  92. import subprocess
  93. if not hasattr(subprocess, "PIPE"):
  94. def _fake_PIPE(*args, **kwargs):
  95. raise NotImplementedError("subprocess.PIPE is not supported.")
  96. subprocess.PIPE = _fake_PIPE
  97. if not hasattr(subprocess, "Popen"):
  98. def _fake_Popen(*args, **kwargs):
  99. raise NotImplementedError("subprocess.Popen is not supported.")
  100. subprocess.Popen = _fake_Popen
  101. ###########################################################
  102. # TOP-LEVEL MODULES
  103. ###########################################################
  104. # Import top-level functionality into top-level namespace
  105. from nltk.collocations import *
  106. from nltk.decorators import decorator, memoize
  107. from nltk.featstruct import *
  108. from nltk.grammar import *
  109. from nltk.probability import *
  110. from nltk.text import *
  111. from nltk.tree import *
  112. from nltk.util import *
  113. from nltk.jsontags import *
  114. ###########################################################
  115. # PACKAGES
  116. ###########################################################
  117. from nltk.chunk import *
  118. from nltk.classify import *
  119. from nltk.inference import *
  120. from nltk.metrics import *
  121. from nltk.parse import *
  122. from nltk.tag import *
  123. from nltk.tokenize import *
  124. from nltk.translate import *
  125. from nltk.sem import *
  126. from nltk.stem import *
  127. # Packages which can be lazily imported
  128. # (a) we don't import *
  129. # (b) they're slow to import or have run-time dependencies
  130. # that can safely fail at run time
  131. from nltk import lazyimport
  132. app = lazyimport.LazyModule("nltk.app", locals(), globals())
  133. chat = lazyimport.LazyModule("nltk.chat", locals(), globals())
  134. corpus = lazyimport.LazyModule("nltk.corpus", locals(), globals())
  135. draw = lazyimport.LazyModule("nltk.draw", locals(), globals())
  136. toolbox = lazyimport.LazyModule("nltk.toolbox", locals(), globals())
  137. # Optional loading
  138. try:
  139. import numpy
  140. except ImportError:
  141. pass
  142. else:
  143. from nltk import cluster
  144. from nltk.downloader import download, download_shell
  145. try:
  146. import tkinter
  147. except ImportError:
  148. pass
  149. else:
  150. try:
  151. from nltk.downloader import download_gui
  152. except RuntimeError as e:
  153. import warnings
  154. warnings.warn(
  155. "Corpus downloader GUI not loaded "
  156. "(RuntimeError during import: %s)" % str(e)
  157. )
  158. # explicitly import all top-level modules (ensuring
  159. # they override the same names inadvertently imported
  160. # from a subpackage)
  161. from nltk import ccg, chunk, classify, collocations
  162. from nltk import data, featstruct, grammar, help, inference, metrics
  163. from nltk import misc, parse, probability, sem, stem, wsd
  164. from nltk import tag, tbl, text, tokenize, translate, tree, treetransforms, util
  165. # FIXME: override any accidentally imported demo, see https://github.com/nltk/nltk/issues/2116
  166. def demo():
  167. print("To run the demo code for a module, type nltk.module.demo()")