1 # common-dmv.py, stuff common to cnf_ and loc_h_-files
3 # non-tweakable/constant "lookup" globals
5 RA
, RN
, LA
, LN
= 0, 1, 2, 3 # for cnf_ DMV_Rule
7 LEFT
, RIGHT
, ADJ
, NON
= 0, 1, True, False # for loc_h
15 SEALS
= [GOR
, RGOL
, SEAL
, GOL
, LGOR
]
18 ROOT
= (SEAL
, ROOTNUM
) # rather arbitrary, doesn't actually make a difference.
19 STOP
= (GOR
, -2) # They would be different in cnf_ I guess... todo!
30 def xgo_left(gt
, lteq
): # i < k <= loc_l(h)
31 return xrange(gt
+1, lteq
+1)
33 def xgo_right(gt
, lt
): # loc_l(h) < k < j (but loc_r(h) <= k)
34 return xrange(gt
+1, lt
)
37 return xrange(0,lteq
+1)
43 '''Include the position "behind" the last word, ie. len(sent).'''
45 return xrange(gt
+1, lt
)
47 def xgteq(gteq
, sent
):
48 '''Include the position "behind" the last word, ie. len(sent).'''
50 return xrange(gteq
, lt
)
53 ''' For use with eg k:i<k<loc_h. Makes sure we get all and only the
54 integers between gt and lt:
56 >>> [x for x in xtween(3,7)]
58 >>> [x for x in xtween(3.5,7)]
60 >>> [x for x in xtween(3.5,6.5)]
62 return xrange(gt
+1, lt
)
68 "Actually just a number representing the POS-tag"
71 def node_str(node
, tag
=lambda x
:x
):
80 return " %s><" % tag(h
)
82 return "_%s_ " % tag(h
)
84 return " %s> " % tag(h
)
86 return " <%s " % tag(h
)
88 return "><%s " % tag(h
)
90 raise ValueError("in node_str, got as node: %s" % node
)