1 # common-dmv.py, stuff common to cnf_ and loc_h_-files
3 # non-tweakable/constant "lookup" globals
5 LEFT
, RIGHT
, ADJ
, NON
= 0, 1, True, False
8 GOR
= 0 # (RIGHT,0) as an alternate possibility
13 SEALS
= [GOR
, RGOL
, SEAL
, GOL
, LGOR
]
16 NGOR
= 5 # we don't care about left-first attachment,
17 NRGOL
= 6 # but have to add the non-adjacent info
20 MPPROOT
= ('ROOT', ROOTNUM
)
21 ROOT
= (SEAL
, ROOTNUM
) # rather arbitrary, doesn't actually make a difference.
34 def xgo_left(gt
, lteq
): # i < k <= loc_l(h)
35 return xrange(gt
+1, lteq
+1)
37 def xgo_right(gt
, lt
): # loc_l(h) < k < j (but loc_r(h) <= k)
38 return xrange(gt
+1, lt
)
41 return xrange(0,lteq
+1)
47 '''Include the position "behind" the last word, ie. len(sent).'''
49 return xrange(gt
+1, lt
)
54 def xgteq(gteq
, sent
):
55 '''Include the position "behind" the last word, ie. len(sent).'''
57 return xrange(gteq
, lt
)
60 ''' For use with eg k:i<k<loc_h. Makes sure we get all and only the
61 integers between gt and lt:
63 >>> [x for x in xtween(3,7)]
65 >>> [x for x in xtween(3.5,7)]
67 >>> [x for x in xtween(3.5,6.5)]
69 return xrange(gt
+1, lt
)
75 "Actually just a number representing the POS-tag"
78 def node_str(node
, tag
=lambda x
:x
):
87 return " %s><" % tag(h
)
89 return " _%s_ " % tag(h
)
91 return " %s> " % tag(h
)
93 return " <%s " % tag(h
)
95 return "><%s " % tag(h
)
97 return " >%s> " % tag(h
)
99 return " <%s><" % tag(h
)
101 raise ValueError("in node_str, got as node: %s" % node
)
104 def test(wanted
, got
, wanted_name
="it", got_name
=""):
105 if not wanted
== got
:
106 raise Warning, "Wanted %s to be %s, but %s was %s" % (wanted_name
, wanted
, got_name
, got
)