2to3 (compiles, not tested)
[tag_parser.git] / src / mjacob / nltk / parse / tag / TreeBuilderI.py
blob99c91528ef9896ccbc8ad0f65b365c0d7dd26c78
1 # This Python file uses the following encoding: utf-8
2 '''
3 Created on Jun 16, 2011
5 @author: mjacob
6 '''
7 from abc import abstractmethod, ABCMeta
9 class TreeBuilderI(object, metaclass=ABCMeta):
10 def __init__(self, chart, type, *edges):
11 self.__chart = chart
12 self.__type = type
13 self.__edges = edges
15 def build(self, working_on):
16 return self._build(working_on, self.__chart, *self.__edges)
18 @abstractmethod
19 def _build(self, chart, *edges): pass
21 def __eq__(self, othr):
22 return self.__type == othr.__type and self.__edges == othr.__edges
24 def __hash__(self):
25 return hash((self.__type, self.__edges))
27 def __str__(self):
28 return "%s Tree Builder: %s" % (self.__type, self.__edges)
30 def __repr__(self):
31 return "%r Tree Builder: %r" % (self.__type, self.__edges)
33 class InitialTreeBuilder(TreeBuilderI):
34 def _build(self, working_on, chart, new_edge):
35 return frozenset((new_edge.production().as_tree(),))
37 class PassthroughTreeBuilder(TreeBuilderI):
38 def _build(self, working_on, chart, edge):
39 if edge in working_on:
40 return frozenset()
42 return chart.get_trees(edge, working_on)