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

Class Category

source code

                       object --+    
                                |    
featurestructure.FeatureStructure --+
                                    |
                       object --+   |
                                |   |
                  cfg.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:

Nested Classes [hide private]
Instance Methods [hide private]
 
__init__(self, **features)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
required_features(self)
Returns: A list of the names of all required features.
source code
 
__cmp__(self, other) source code
Nonterminal
__div__(self, other)
Returns: A new Category based on this one, with its / feature set to other.
source code
bool
__eq__(self, other)
Returns: True if self and other assign the same value to to every feature.
source code
boolean
__ne__(self, other)
Returns: True if this non-terminal is not equal to other.
source code
 
__hash__(self)
hash(x)
source code
 
freeze(self)
Freezing a Category memoizes its hash value, to make comparisons on it faster.
source code
bool
frozen(self)
Returns whether this Category is frozen (immutable).
source code
 
__setitem__(self, name, value) source code
Category
symbol(self)
Returns: The node value corresponding to this Category.
source code
str or None
head(self)
Returns: The head of this category (the value shown outside the brackets in its string representation).
source code
 
deepcopy(self, memo=None)
Returns: A deep copy of self.
source code
list of FeatureStructure
reentrances(self)
Returns: A list of all feature structures that can be reached from self by multiple feature paths.
source code
list of string
feature_names(self)
Returns: a list of all features that have values.
source code
 
get_feature(self, *args) source code
 
has_feature(self, name) source code
 
remove_unbound_vars(self) source code
 
_remove_unbound_vars(self) source code
 
_destructively_unify(self, other, bindings, trace=True, depth=0)
Attempt to unify self and other by modifying them in-place.
source code
 
__repr__(self)
Returns: A string representation of this feature structure.
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 structure.
source code

Inherited from featurestructure.FeatureStructure: __getitem__, __str__, apply_bindings, equal_values, rename_variables, subsumes, unify

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

Class Methods [hide private]
 
_parseval(cls, s, position, reentrances)
Helper function that parses a feature value.
source code
 
_parse(cls, s, position=0, reentrances=None)
Helper function that parses a Category.
source code
 
parse_rules(cls, s)
Parse a CFG line involving Categories.
source code

Inherited from featurestructure.FeatureStructure: parse

Class Variables [hide private]
  headname = '_head'
  requiredFeatures = []
  _PARSE_RE = {'arrow': re.compile(r'\s*->\s*'), 'assign': re.co...
  k = 'reentrance'
  v = re.compile(r'\s*->\s*')
Instance Variables [hide private]

Inherited from cfg.Nonterminal (private): _symbol

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **features)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: featurestructure.FeatureStructure.__init__

required_features(self)

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

__cmp__(self, other)
(Comparison operator)

source code 
Overrides: cfg.Nonterminal.__cmp__

__div__(self, other)

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

__eq__(self, other)
(Equality operator)

source code 
Returns: bool
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).
Overrides: featurestructure.FeatureStructure.__eq__

__ne__(self, other)

source code 
Returns: boolean
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.
Overrides: cfg.Nonterminal.__ne__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: featurestructure.FeatureStructure.__hash__

freeze(self)

source code 

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

symbol(self)

source code 
Returns: Category
The node value corresponding to this Category.
Overrides: cfg.Nonterminal.symbol

head(self)

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

deepcopy(self, memo=None)

source code 
Returns:
A deep copy of self.
Overrides: featurestructure.FeatureStructure.deepcopy

reentrances(self)

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

feature_names(self)

source code 
Returns: list of string
a list of all features that have values.
Overrides: featurestructure.FeatureStructure.feature_names

_destructively_unify(self, other, bindings, trace=True, depth=0)

source code 

Attempt to unify self and other by modifying them in-place. If the unification succeeds, then self will contain the unified value, and the value of other is undefined. If the unification fails, then a _UnificationFailureError is raised, and the values of self and other are undefined.

Overrides: featurestructure.FeatureStructure._destructively_unify
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

Display a single-line representation of this feature structure, suitable for embedding in other representations.

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

_repr(self, reentrances, reentrance_ids)

source code 
Returns:
A string representation of this feature structure.
Overrides: featurestructure.FeatureStructure._repr
(inherited documentation)

_str(self, reentrances, reentrance_ids)

source code 
Returns:
A list of lines composing a string representation of this feature structure.
Overrides: featurestructure.FeatureStructure._str
(inherited documentation)

_parseval(cls, s, position, reentrances)
Class Method

source code 

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: featurestructure.FeatureStructure._parseval

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

source code 

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: featurestructure.FeatureStructure._parse

parse_rules(cls, s)
Class Method

source code 

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.

Class Variable Details [hide private]

_PARSE_RE

Value:
{'arrow': re.compile(r'\s*->\s*'),
 'assign': re.compile(r'\s*=\s*'),
 'bool': re.compile(r'\s*([-\+])'),
 'bracket': re.compile(r'\s*\]\s*'),
 'categorystart': re.compile(r'\s*([^\s\(\)"\'-=,\[\]]*)\s*\['),
 'comma': re.compile(r'\s*,\s*'),
 'disjunct': re.compile(r'\s*\|\s*'),
 'ident': re.compile(r'\s*\((\d+)\)\s*'),
...