Package nltk_lite :: Package parse :: Module category :: Class Category
[show private | hide private]
[frames | no frames]

Type Category

      object --+    
               |    
FeatureStructure --+
                   |
      object --+   |
               |   |
     Nonterminal --+
                   |
                  Category

Known Subclasses:
GrammarCategory

A Category is a specialized feature structure, intended for use in parsing. It can act as a Nonterminal.

A Category differs from a FeatureStructure in these ways:
Method Summary
  __init__(self, **features)
  __cmp__(self, other)
  __div__(self, other)
Return a new Category based on this one, with its / feature set to other.
bool __eq__(self, other)
Return true if self and other assign the same value to to every feature.
  __hash__(self)
boolean __ne__(self, other)
Return true if this non-terminal is not equal to other.
  __repr__(self)
Return a string representation of this feature structure.
  __setitem__(self, name, value)
  deepcopy(self, memo)
Return a deep copy of self.
  feature_names(self)
Return a list of all features that have values.
  freeze(self)
Freezing a Category memoizes its hash value, to make comparisons on it faster.
bool frozen(self)
Returns whether this Category is frozen (immutable).
  get_feature(self, *args)
  has_feature(self, name)
str or None head(self)
Return the head of this category (the value shown outside the brackets in its string representation).
  parse_rules(cls, s)
Parse a CFG line involving Categories. (Class method)
list of FeatureStructure reentrances(self)
Return a list of all feature structures that can be reached from self by multiple feature paths.
  remove_unbound_vars(self)
  required_features(self)
Return a list of the names of all required features.
Category symbol(self)
Return the node value corresponding to this Category.
  _destructively_unify(self, other, bindings, trace, depth)
  _parse(cls, s, position, reentrances)
Helper function that parses a Category. (Class method)
  _parseval(cls, s, position, reentrances)
Helper function that parses a feature value. (Class method)
  _remove_unbound_vars(self)
  _repr(self, reentrances, reentrance_ids)
Return a string representation of this feature structure.
  _str(self, reentrances, reentrance_ids)
Return a list of lines composing a string representation of this feature structure.
Inherited from FeatureStructure: __getitem__, __str__, apply_bindings, equal_values, parse, rename_variables, subsumes, unify, _apply_bindings, _apply_forwards, _apply_forwards_to_bindings, _find_reentrances, _rebind_aliased_variables, _rename_variables
Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Instance Variable Summary
Inherited from FeatureStructure: _features, _forward
Inherited from Nonterminal: _symbol

Class Variable Summary
str headname = '_head'
str k = 'reentrance'
list requiredFeatures = []
SRE_Pattern v = \s*->\s*
dict _PARSE_RE = {'categorystart': <_sre.SRE_Pattern object a...

Instance Method Details

__div__(self, other)

Returns:
A new Category based on this one, with its / feature set to other.
Overrides:
nltk_lite.parse.cfg.Nonterminal.__div__

__eq__(self, other)
(Equality operator)

Returns:
True if self and other assign the same value to to every feature. In particular, return true if self[p]==other[p] for every feature path p such that self[p] or other[p] is a base value (i.e., not a nested Category).
           (type=bool)
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure.__eq__

__ne__(self, other)

Returns:
True if this non-terminal is not equal to other. In particular, return true iff other is not a Nonterminal or this non-terminal's symbol is not equal to other's symbol.
           (type=boolean)
Overrides:
nltk_lite.parse.cfg.Nonterminal.__ne__ (inherited documentation)

__repr__(self)
(Representation operator)

Returns:
A string representation of this feature structure.
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure.__repr__

deepcopy(self, memo=None)

Returns:
A deep copy of self.
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure.deepcopy

feature_names(self)

Returns:
a list of all features that have values.
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure.feature_names

freeze(self)

Freezing a Category memoizes its hash value, to make comparisons on it faster. After freezing, the Category and all its values are immutable.
Returns:
self

frozen(self)

Returns whether this Category is frozen (immutable).
Returns:
bool

head(self)

Returns:
The head of this category (the value shown outside the brackets in its string representation). If there is no head, returns None.
           (type=str or None)

reentrances(self)

Returns:
A list of all feature structures that can be reached from self by multiple feature paths.
           (type=list of FeatureStructure)
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure.reentrances (inherited documentation)

required_features(self)

Returns:
A list of the names of all required features.

symbol(self)

Returns:
The node value corresponding to this Category.
           (type=Category)
Overrides:
nltk_lite.parse.cfg.Nonterminal.symbol

_repr(self, reentrances, reentrance_ids)

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:
nltk_lite.parse.featurestructure.FeatureStructure._repr (inherited documentation)

_str(self, reentrances, reentrance_ids)

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 structure.
Overrides:
nltk_lite.parse.featurestructure.FeatureStructure._str (inherited documentation)

Class Method Details

parse_rules(cls, s)

Parse a CFG line involving Categories. A line has this form:

lhs -> rhs | rhs | ...

where lhs is a Category, and each rhs is a sequence of Categories.
Returns:
a list of Productions, one for each rhs.

_parse(cls, s, position=0, reentrances=None)

Helper function that parses a Category.
Parameters:
s - The string to parse.
position - The position in the string to start parsing.
reentrances - A dictionary from reentrance ids to values.
Returns:
A tuple (val, pos) of the feature structure created by parsing and the position where the parsed feature structure ends.
Overrides:
__builtin__.type._parse

_parseval(cls, s, position, reentrances)

Helper function that parses a feature value. Currently supports: None, bools, integers, variables, strings, nested feature structures.
Parameters:
s - The string to parse.
position - The position in the string to start parsing.
reentrances - A dictionary from reentrance ids to values.
Returns:
A tuple (val, pos) of the value created by parsing and the position where the parsed value ends.
Overrides:
__builtin__.type._parseval

Class Variable Details

headname

Type:
str
Value:
'_head'                                                                

k

Type:
str
Value:
'reentrance'                                                           

requiredFeatures

Type:
list
Value:
[]                                                                     

v

Type:
SRE_Pattern
Value:
\s*->\s*                                                               

_PARSE_RE

Type:
dict
Value:
{'arrow': <_sre.SRE_Pattern object at 0x2b302dd49140>,
 'assign': <_sre.SRE_Pattern object at 0x2b302dda5030>,
 'bool': <_sre.SRE_Pattern object at 0x2b302d9f6bb0>,
 'bracket': <_sre.SRE_Pattern object at 0x2b302dda51b0>,
 'categorystart': <_sre.SRE_Pattern object at 0x2aaaaad89f08>,
 'comma': <_sre.SRE_Pattern object at 0x2b302dda55b0>,
 'disjunct': <_sre.SRE_Pattern object at 0x2b302d9f60b0>,
 'ident': <_sre.SRE_Pattern object at 0x2b302dcd3490>,
...                                                                    

Generated by Epydoc 2.1 on Tue Sep 5 09:37:21 2006 http://epydoc.sf.net