class documentation

class Trie(dict): (source)

Constructor: Trie(strings)

View In Hierarchy

A Trie implementation for strings

Method __init__ Builds a Trie object, which is built around a dict
Method __missing__ Undocumented
Method insert Inserts string into the Trie
Constant LEAF Undocumented
def __init__(self, strings=None): (source)

Builds a Trie object, which is built around a dict

If strings is provided, it will add the strings, which consist of a list of strings, to the Trie. Otherwise, it'll construct an empty Trie.

Parameters
strings:list(str)List of strings to insert into the trie (Default is None)
def __missing__(self, key): (source)

Undocumented

def insert(self, string): (source)

Inserts string into the Trie

>>> from nltk.collections import Trie
>>> trie = Trie(["abc", "def"])
>>> expected = {'a': {'b': {'c': {True: None}}},                         'd': {'e': {'f': {True: None}}}}
>>> trie == expected
True
Parameters
string:strString to insert into the trie
Unknown Field: example
LEAF: bool = (source)

Undocumented

Value
True