2to3 (compiles, not tested)
[tag_parser.git] / src / mjacob / nltk / parse / tag / prefix_valid_earley / PVTagEdge.py
blob464153d094379a4f2a4fa57c74f510bb5d85de57
1 # This Python file uses the following encoding: utf-8
2 '''
3 Created on May 18, 2011
5 Based on nltk's EdgeI
7 @author: mjacob
8 '''
9 from mjacob.nltk.parse.tag.earley.TagEdge import TagEdge
10 from operator import lt, eq
12 """the symbol for an index whose value doesn't matter is ~"""
13 CARENT="~"
15 class PVTagEdge(TagEdge):
16 def __init__(self, production, treeposition, treestart, span, gapspan, dotposition, has_adjoined):
17 TagEdge.__init__(self, production, treeposition, span, gapspan, dotposition, has_adjoined)
18 self.__treestart = treestart
20 def treestart(self):
21 """the start position of the elementary tree that has triggered the creation of this edge"""
22 return self.__treestart
24 def startgap(self):
25 if self.__treestart == CARENT:
26 return None
27 return self.start() - self.__treestart
29 def __str__(self):
30 return '[%s:%s:%s:%s:%s] %r %s[%s] %s %s' % (self.__treestart,
31 self.start(),
32 self.gapstart() is None and "-" or self.gapstart(),
33 self.gapend() is None and "-" or self.gapend(),
34 self.end(),
35 self.text(),
36 self.production(),
37 self.treeposition(),
38 self.dotposition(),
39 self.has_adjoined())
41 def __repr__(self):
42 return '[Edge: %s]' % (self)
44 def __lt__(self, othr):
45 return lt((self.__treestart, self.start(), self.gapstart(), self.gapend(), self.end(), self.production(), self.treeposition(), self.dotposition(), self.has_adjoined()),
46 (othr.__treestart, othr.start(), othr.gapstart(), othr.gapend(), othr.end(), othr.production(), othr.treeposition(), othr.dotposition(), othr.has_adjoined()))
48 def __eq__(self, othr):
49 return eq((self.__treestart, self.start(), self.gapstart(), self.gapend(), self.end(), self.production(), self.treeposition(), self.dotposition(), self.has_adjoined()),
50 (othr.__treestart, othr.start(), othr.gapstart(), othr.gapend(), othr.end(), othr.production(), othr.treeposition(), othr.dotposition(), othr.has_adjoined()))
52 def __hash__(self):
53 return hash((self.__treestart, self.production(), self.treeposition(), self.span(), self.gap(), self.dotposition(), self.has_adjoined()))