Package nltk :: Module featstruct :: Class FeatDict
[hide private]
[frames] | no frames]

Class FeatDict

source code

                   object --+        
                            |        
sem.logic.SubstituteBindingsI --+    
                                |    
                       FeatStruct --+
                                    |
                       object --+   |
                                |   |
                             dict --+
                                    |
                                   FeatDict
Known Subclasses:

A feature structure that acts like a Python dictionary. I.e., a mapping from feature identifiers to feature values, where feature identifiers can be strings or Features; and feature values can be either basic values (such as a string or an integer), or nested feature structures. Feature identifiers for FeatDicts are sometimes called feature names.

Two feature dicts are considered equal if they assign the same values to all features, and have the same reentrances.


See Also: FeatStruct for information about feature paths, reentrance, cyclic feature structures, mutability, freezing, and hashing.

Instance Methods [hide private]
new empty dictionary

__init__(self, features=None, **morefeatures)
Create a new feature dictionary, with the specified features.
source code

Inherited from dict: __cmp__, __ge__, __getattribute__, __gt__, __iter__, __le__, __len__, __lt__, fromkeys, items, iteritems, iterkeys, itervalues, keys, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

    Dict methods
 
__getitem__(self, name_or_path)
If the feature with the given name or path exists, return its value; otherwise, raise KeyError.
source code
D[k] if k in D, else d
get(self, name_or_path, default=None)
If the feature with the given name or path exists, return its value; otherwise, return default.
source code
True if D has a key k, else False
__contains__(self, name_or_path)
Return true if a feature with the given name or path exists.
source code
True if D has a key k, else False
has_key(self, name_or_path)
Return true if a feature with the given name or path exists.
source code
 
__delitem__(self, name_or_path)
If the feature with the given name or path exists, delete its value; otherwise, raise KeyError.
source code
 
__setitem__(self, name_or_path, value)
Set the value for the feature with the given name or path to value.
source code
None
clear(D)
Remove all items from D.
source code
v, remove specified key and return the corresponding value
pop(D, k, d=...)
If key is not found, d is returned if given, otherwise KeyError is raised If self is frozen, raise ValueError.
source code
(k, v), remove and return some (key, value) pair as a
popitem(D)
2-tuple; but raise KeyError if D is empty If self is frozen, raise ValueError.
source code
D.get(k,d), also set D[k]=d if k not in D
setdefault(D, k, d=...)
If self is frozen, raise ValueError.
source code
None
update(self, features=None, **morefeatures)
Update D from E and F: for k in E: D[k] = E[k] (if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]
source code
    Copying
 
__deepcopy__(self, memo) source code

Inherited from FeatStruct: copy

    Uniform Accessor Methods
 
_keys(self)
Return an iterable of the feature identifiers used by this FeatStruct.
source code
 
_values(self)
Return an iterable of the feature values directly defined by this FeatStruct.
source code
 
_items(self)
Return an iterable of (fid,fval) pairs, where fid is a feature identifier and fval is the corresponding feature value, for all features defined by this FeatStruct.
source code
    String Representations
 
__str__(self)
Display a multi-line representation of this feature dictionary as an FVM (feature value matrix).
source code
 
_repr(self, reentrances, reentrance_ids)
Returns: A string representation of this feature structure.
source code
 
_str(self, reentrances, reentrance_ids)
Returns: A list of lines composing a string representation of this feature dictionary.
source code

Inherited from FeatStruct: __repr__

    Equality & Hashing

Inherited from FeatStruct: __eq__, __hash__, __ne__, equal_values

Inherited from FeatStruct (private): _equal, _hash

    Freezing

Inherited from FeatStruct: freeze, frozen

Inherited from FeatStruct (private): _freeze

    Structural Information

Inherited from FeatStruct: cyclic, reentrances, walk

Inherited from FeatStruct (private): _find_reentrances, _walk

    Variables & Bindings

Inherited from FeatStruct: remove_variables, rename_variables, retract_bindings, substitute_bindings, variables

    Unification

Inherited from FeatStruct: subsumes, unify

Static Methods [hide private]
    Constructor

Inherited from FeatStruct: __new__

Class Variables [hide private]
    Dict methods
  _INDEX_ERROR = 'Expected feature name or path. Got %r.'
    Freezing

Inherited from FeatStruct (private): _FROZEN_ERROR

Instance Variables [hide private]

Inherited from FeatStruct (private): _frozen

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, features=None, **morefeatures)
(Constructor)

source code 

Create a new feature dictionary, with the specified features.

Parameters:
  • features - The initial value for this feature dictionary. If features is a FeatStruct, then its features are copied (shallow copy). If features is a dict, then a feature is created for each item, mapping its key to its value. If features is a string, then it is parsed using FeatStructParser. If features is a list of tuples name,val, then a feature is created for each tuple.
  • morefeatures - Additional features for the new feature dictionary. If a feature is listed under both features and morefeatures, then the value from morefeatures will be used.
Returns:
new empty dictionary

Overrides: dict.__init__

__getitem__(self, name_or_path)
(Indexing operator)

source code 

If the feature with the given name or path exists, return its value; otherwise, raise KeyError.

Overrides: dict.__getitem__

get(self, name_or_path, default=None)

source code 

If the feature with the given name or path exists, return its value; otherwise, return default.

Returns: D[k] if k in D, else d
Overrides: dict.get

__contains__(self, name_or_path)
(In operator)

source code 

Return true if a feature with the given name or path exists.

Returns: True if D has a key k, else False
Overrides: dict.__contains__

has_key(self, name_or_path)

source code 

Return true if a feature with the given name or path exists.

Returns: True if D has a key k, else False
Overrides: dict.has_key

__delitem__(self, name_or_path)
(Index deletion operator)

source code 

If the feature with the given name or path exists, delete its value; otherwise, raise KeyError.

Overrides: dict.__delitem__

__setitem__(self, name_or_path, value)
(Index assignment operator)

source code 

Set the value for the feature with the given name or path to value. If name_or_path is an invalid path, raise KeyError.

Overrides: dict.__setitem__

clear(D)

source code 

Remove all items from D. If self is frozen, raise ValueError.

Returns: None
Overrides: dict.clear

pop(D, k, d=...)

source code 

If key is not found, d is returned if given, otherwise KeyError is raised If self is frozen, raise ValueError.

Returns: v, remove specified key and return the corresponding value
Overrides: dict.pop

popitem(D)

source code 

2-tuple; but raise KeyError if D is empty If self is frozen, raise ValueError.

Returns: (k, v), remove and return some (key, value) pair as a
Overrides: dict.popitem

setdefault(D, k, d=...)

source code 

If self is frozen, raise ValueError.

Returns: D.get(k,d), also set D[k]=d if k not in D
Overrides: dict.setdefault

update(self, features=None, **morefeatures)

source code 

Update D from E and F: for k in E: D[k] = E[k] (if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]

Returns: None
Overrides: dict.update
(inherited documentation)

__deepcopy__(self, memo)

source code 
Overrides: FeatStruct.__deepcopy__

_keys(self)

source code 

Return an iterable of the feature identifiers used by this FeatStruct.

Overrides: FeatStruct._keys
(inherited documentation)

_values(self)

source code 

Return an iterable of the feature values directly defined by this FeatStruct.

Overrides: FeatStruct._values
(inherited documentation)

_items(self)

source code 

Return an iterable of (fid,fval) pairs, where fid is a feature identifier and fval is the corresponding feature value, for all features defined by this FeatStruct.

Overrides: FeatStruct._items
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

Display a multi-line representation of this feature dictionary as an FVM (feature value matrix).

Overrides: object.__str__

_repr(self, reentrances, reentrance_ids)

source code 
Parameters:
  • reentrances - A dictionary that maps from the id of each feature value in self, indicating whether that value is reentrant or not.
  • reentrance_ids - A dictionary mapping from the ids of feature values to unique identifiers. This is modified by repr: the first time a reentrant feature value is displayed, an identifier is added to reentrance_ids for it.
Returns:
A string representation of this feature structure.
Overrides: FeatStruct._repr
(inherited documentation)

_str(self, reentrances, reentrance_ids)

source code 
Parameters:
  • reentrances - A dictionary that maps from the id of each feature value in self, indicating whether that value is reentrant or not.
  • reentrance_ids - A dictionary mapping from the ids of feature values to unique identifiers. This is modified by repr: the first time a reentrant feature value is displayed, an identifier is added to reentrance_ids for it.
Returns:
A list of lines composing a string representation of this feature dictionary.