nltk.misc package


nltk.misc.babelfish module

This module previously provided an interface to Babelfish online translation service; this service is no longer available; this module is kept in NLTK source code in order to provide better error messages for people following the NLTK Book 2.0.


nltk.misc.chomsky module

CHOMSKY is an aid to writing linguistic papers in the style of the great master. It is based on selected phrases taken from actual books and articles written by Noam Chomsky. Upon request, it assembles the phrases in the elegant stylistic patterns that Chomsky is noted for. To generate n sentences of linguistic wisdom, type

(CHOMSKY n) – for example (CHOMSKY 5) generates half a screen of linguistic truth.

nltk.misc.chomsky.generate_chomsky(times=5, line_length=72)[source]

nltk.misc.minimalset module

class nltk.misc.minimalset.MinimalSet(parameters=None)[source]

Bases: object

Find contexts where more than one possible target value can appear. E.g. if targets are word-initial letters, and contexts are the remainders of words, then we would like to find cases like “fat” vs “cat”, and “training” vs “draining”. If targets are parts-of-speech and contexts are words, then we would like to find cases like wind (noun) ‘air in rapid motion’, vs wind (verb) ‘coil, wrap’.

add(context, target, display)[source]

Add a new item to the minimal set, having the specified context, target, and display form.

  • context (str) – The context in which the item of interest appears

  • target (str) – The item of interest

  • display (str) – The information to be reported for each item


Determine which contexts occurred with enough distinct targets.


minimum (int) – the minimum number of distinct target forms

:rtype list

display(context, target, default='')[source]

nltk.misc.sort module

This module provides a variety of list sorting algorithms, to illustrate the many different algorithms (recipes) for solving a problem, and how to analyze algorithms experimentally.


Bubble Sort: compare adjacent elements of the list left-to-right, and swap them if they are out of order. After one pass through the list swapping adjacent items, the largest item will be in the rightmost position. The remainder is one element smaller; apply the same method to this list, and so on.


Merge Sort: split the list in half, and sort each half, then combine the sorted halves.


Selection Sort: scan the list to find its smallest element, then swap it with the first element. The remainder of the list is one element smaller; apply the same method to this list, and so on.

nltk.misc.wordfinder module

nltk.misc.wordfinder.check(word, dir, x, y, grid, rows, cols)[source]
nltk.misc.wordfinder.step(word, x, xf, y, yf, grid)[source]
nltk.misc.wordfinder.wordfinder(words, rows=20, cols=20, attempts=50, alph='ABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]

Attempt to arrange words into a letter-grid with the specified number of rows and columns. Try each word in several positions and directions, until it can be fitted into the grid, or the maximum number of allowable attempts is exceeded. Returns a tuple consisting of the grid and the words that were successfully placed.

  • words (list) – the list of words to be put into the grid

  • rows (int) – the number of rows in the grid

  • cols (int) – the number of columns in the grid

  • attempts (int) – the number of times to attempt placing a word

  • alph (list) – the alphabet, to be used for filling blank cells

Return type


Module contents