def boolean(self): b = self.currentToken[1:] b = b.lower() if (b == 'prox'): self.fetch_token() exclusion = self.currentToken self.fetch_token() distance = self.currentToken self.fetch_token() ordered = self.currentToken self.fetch_token() relation = self.currentToken self.fetch_token() which = self.currentToken self.fetch_token() unit = self.currentToken prox = z3950.ProximityOperator() if (not (relation.isdigit() and exclusion.isdigit() and distance.isdigit() and unit.isdigit())): raise ValueError prox.relationType = int(relation) prox.exclusion = bool(exclusion) prox.distance = int(distance) if (which[0] == 'k'): prox.unit = ('known', int(unit)) elif (which[0] == 'p'): prox.unit = ('private', int(unit)) else: raise ValueError return (b, prox) elif b == 'not': return ('and_not', None) else: return (b, None)
def boolean(self): tok = self.currentToken.upper() self.fetch_token() if (tok in booleans): return (booleans[tok], None) elif (tok in privateBooleans): # Generate cutesie prox trick type = privateBooleans[tok] prox = z3950.ProximityOperator() prox.proximityUnitCode = ('private', type) prox.distance = 0 prox.ordered = 0 prox.relationType = 3 return ('op', ('prox', prox)) elif (tok in proxBooleans): # Generate prox prox = z3950.ProximityOperator() stuff = proxBooleans[tok] prox.distance = stuff[0] prox.ordered = stuff[1] prox.relationType = stuff[2] prox.proximityUnitCode = ('known', 2) # Now look for / while (self.currentToken == "/"): self.fetch_token() if (self.currentToken.isdigit()): prox.distance = int(self.currentToken) elif (self.currentToken.upper() in proxUnits): prox.proximityUnitCode = ( 'known', proxUnits[self.currentToken.upper()]) else: raise ValueError self.fetch_token() return ('op', ('prox', prox)) else: # Argh! raise ValueError
def toRPN(self, top): op = self.value if (self.value == 'not'): op = 'and-not' elif (self.value == 'prox'): # Create ProximityOperator prox = z3950.ProximityOperator() # distance, ordered, proximityUnitCode, relationType u = self['unit'] try: units = [ "", "character", "word", "sentence", "paragraph", "section", "chapter", "document", "element", "subelement", "elementType", "byte" ] if (u.value in units): prox.unit = ('known', units.index(u.value)) else: # Uhhhh..... prox.unit = ('private', int(u.value)) except: prox.unit = ('known', 2) d = self['distance'] try: prox.distance = int(d.value) except: if (prox.unit == ('known', 2)): prox.distance = 1 else: prox.distance = 0 try: rels = ["", "<", "<=", "=", ">=", ">", "<>"] prox.relationType = rels.index(d.comparison) except: prox.relationType = 2 prox.ordered = bool(self['ordered']) return ('op', ('prox', prox)) return (op, None)