Package nltk_lite :: Package contrib :: Package toolbox :: Module lexicon :: Class Lexicon
[hide private]
[frames] | no frames]

Class Lexicon

source code

                    object --+    
                             |    
corpora.toolbox.StandardFormat --+
                                 |
                                Lexicon

This class represents a Toolbox lexicon, which consists of an optional header and one or more Entry objects, saved in a dictionary whose keys are passed as a parameter to the parse() method.

Instance Methods [hide private]
 
__init__(self, file)
This method construct a Lexicon object with a header and a dictionary of entries.
source code
 
__str__(self)
This method defines the string representation of a Lexicon object
source code
 
set_header(self, header)
This method sets the raw text of the header.
source code
string
get_header(self)
This method obtains the raw text of the header.
source code
list of Entry objects
get_entries(self)
This method obtains all of the entries found in a parsed Toolbox lexicon.
source code
 
add_entry(self, entry, unique=True)
This method adds an Entry object to a Lexicon object.
source code
dictionary object
parse(self, head_field_marker='lx', subentry_field_marker=None, key_fields=None, unique_entry=True, unique_subentry=True)
This method parses a Toolbox file in a Lexicon object.
source code

Inherited from corpora.toolbox.StandardFormat: close, fields, open, open_string, raw_fields

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, file)
(Constructor)

source code 

This method construct a Lexicon object with a header and a dictionary of entries.

Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

This method defines the string representation of a Lexicon object

Overrides: object.__str__

set_header(self, header)

source code 

This method sets the raw text of the header.

Parameters:
  • header (string) - header (as raw text)

get_header(self)

source code 

This method obtains the raw text of the header.

Returns: string
raw header

get_entries(self)

source code 

This method obtains all of the entries found in a parsed Toolbox lexicon.

Returns: list of Entry objects
all of the entries in the Lexicon

add_entry(self, entry, unique=True)

source code 

This method adds an Entry object to a Lexicon object. It adds the entry to the Lexicon keyed by the values of the fields specified by the key_fields argument.

Parameters:
  • entry (Entry object) - a parsed entry from a Toolbox lexicon
  • unique (boolean) - raise exception if entry key already exists

parse(self, head_field_marker='lx', subentry_field_marker=None, key_fields=None, unique_entry=True, unique_subentry=True)

source code 

This method parses a Toolbox file in a Lexicon object. It will also parse subentries provided that the field marker identifying subentries is passed to it.

Parameters:
  • head_field_marker (string) - field marker that identifies the start of an entry
  • key_fields (list of strings) - the field(s) to which entries are keyed
  • subentry_field_marker (string) - field marker that identifies subentries
  • unique_entry (boolean) - raise warning if entries are non-unique according to key_fields parameter
  • unique_subentry (boolean) - raise warning if entries are non-unique according to key_fields parameter
Returns: dictionary object
a parsed Lexicon object