Package nltk :: Module text :: Class Text
[hide private]
[frames] | no frames]

Class Text

source code

object --+    
         |    
      list --+
             |
            Text

A text object, which can be loaded with a sequence of words, and which supports counting, concordancing, collocation discovery, etc. This class is intended to support initial exploration of texts. It is initialized with a list of words, e.g.:

>>> moby = Text(nltk.corpus.gutenberg.words('melville-moby_dick.txt'))

Many of the methods simply print their results, and are intended for use via the interactive console.

Instance Methods [hide private]
new list
__init__(self, text, name=None)
Create a Text object.
source code
 
concordance(self, word, width=80, lines=25)
Print a concordance for the word with the specified context window.
source code
 
collocations(self, num=20)
Print collocations derived from the text.
source code
 
readability(self, method) source code
 
generate(self, length=100)
Print random text, generated using a trigram language model.
source code
 
similar(self, word, num=20)
Distributional similarity: find other words which appear in the same contexts as the specified word.
source code
 
dispersion_plot(self, words) source code
 
zipf_plot(self, *args) source code
 
vocab(self) source code
string
__str__(self)
Returns: A string representation of this FreqDist.
source code
string
__repr__(self)
Returns: A string representation of this FreqDist.
source code

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reversed__, __rmul__, __setitem__, __setslice__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, text, name=None)
(Constructor)

source code 

Create a Text object.

Parameters:
  • words (sequence of str) - The source text.
Returns: new list
Overrides: list.__init__

concordance(self, word, width=80, lines=25)

source code 

Print a concordance for the word with the specified context window.

Parameters:
  • word (str) - The target word
  • width (int) - The width of each line, in characters (default=80)
  • lines (int) - The number of lines to display (default=25)

collocations(self, num=20)

source code 

Print collocations derived from the text.

Parameters:
  • num (int) - The number of collocations to produce.

generate(self, length=100)

source code 

Print random text, generated using a trigram language model.

Parameters:
  • length (int) - The length of text to generate (default=100)

similar(self, word, num=20)

source code 

Distributional similarity: find other words which appear in the same contexts as the specified word.

Parameters:
  • word (str) - The word used to seed the similarity search
  • num (int) - The number of words to generate (default=20)

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns: string
A string representation of this FreqDist.
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns: string
A string representation of this FreqDist.
Overrides: list.__repr__