def to_rule(self, fields, label='name', missing=None): """Builds rule string from a predicate """ # externally forcing missing to True or False depending on the path if missing is None: missing = self.missing if label is not None: name = fields[self.field][label] else: name = "" full_term = self.is_full_term(fields) relation_missing = " or missing" if missing else "" if self.term is not None: relation_suffix = '' if ((self.operator == '<' and self.value <= 1) or (self.operator == '<=' and self.value == 0)): relation_literal = ('is not equal to' if full_term else 'does not contain') else: relation_literal = 'is equal to' if full_term else 'contains' if not full_term: if self.operator != '>' or self.value != 0: relation_suffix = ( RELATIONS[self.operator] % (self.value, plural('time', self.value))) return "%s %s %s %s%s" % (name, relation_literal, self.term, relation_suffix, relation_missing) if self.value is None: return "%s %s" % (name, "is missing" if self.operator == '=' else "is not missing") return "%s %s %s%s" % (name, self.operator, self.value, relation_missing)
def to_rule(self, fields, label='name'): """ Builds rule string from a predicate """ name = fields[self.field][label] full_term = self.is_full_term(fields) relation_missing = u" or missing" if self.missing else u"" if self.term is not None: relation_suffix = '' if ((self.operator == '<' and self.value <= 1) or (self.operator == '<=' and self.value == 0)): relation_literal = (u'is not equal to' if full_term else u'does not contain') else: relation_literal = u'is equal to' if full_term else u'contains' if not full_term: if self.operator != '>' or self.value != 0: relation_suffix = ( RELATIONS[self.operator] % (self.value, plural('time', self.value))) return u"%s %s %s %s%s" % (name, relation_literal, self.term, relation_suffix, relation_missing) if self.value is None: return u"%s %s" % (name, u"is None" if self.operator == '=' else u"is not None") return u"%s %s %s%s" % (name, self.operator, self.value, relation_missing)
def predicate_to_rule(operation, field_info, value, term, missing, label='name'): """Predicate condition string """ # externally forcing missing to True or False depending on the path if missing is None: missing = False if label is not None: name = field_info[label] else: name = "" operation = INVERSE_OP[operation] full_term = is_full_term(term, field_info) relation_missing = " or missing" if missing else "" if term is not None: relation_suffix = '' if ((operation == '<' and value <= 1) or (operation == '<=' and value == 0)): relation_literal = ('is not equal to' if full_term else 'does not contain') else: relation_literal = 'is equal to' if full_term else 'contains' if not full_term: if operation != '>' or value != 0: relation_suffix = (RELATIONS[operation] % (value, plural('time', value))) return "%s %s %s %s%s" % (name, relation_literal, term, relation_suffix, relation_missing) if value is None: return "%s %s" % (name, "is missing" if operation == '=' else "is not missing") return "%s %s %s%s" % (name, operation, value, relation_missing)