def replace(self, minquality=0): a = self.a b = self.b a_active = a.is_active() b_active = b.is_active() if not a_active: return mcore.NullMatcher() elif minquality and b_active: if a.max_quality() + b.max_quality() < minquality: # If the combined max quality of the sub-matchers isn't high # enough to possibly contribute, return an inactive matcher return mcore.NullMatcher() elif a.max_quality() < minquality: # If the max quality of the main sub-matcher isn't high enough # to ever contribute without the optional sub- matcher, change # into an IntersectionMatcher return IntersectionMatcher(self.a, self.b) elif not b_active: return a.replace(minquality) new_a = a.replace(minquality - b.max_quality()) new_b = b.replace(minquality - a.max_quality()) if new_a is not a or new_b is not b: # If one of the sub-matchers changed, return a new AndMaybe return self.__class__(new_a, new_b) else: return self
def replace(self, minquality=0): a = self.a b = self.b a_active = a.is_active() b_active = b.is_active() # If neither sub-matcher on its own has a high enough max quality to # contribute, convert to an intersection matcher if minquality and a_active and b_active: a_max = a.max_quality() b_max = b.max_quality() if a_max < minquality and b_max < minquality: return IntersectionMatcher(a, b).replace(minquality) elif a_max < minquality: return AndMaybeMatcher(b, a) elif b_max < minquality: return AndMaybeMatcher(a, b) # If one or both of the sub-matchers are inactive, convert if not (a_active or b_active): return mcore.NullMatcher() elif not a_active: return b.replace(minquality) elif not b_active: return a.replace(minquality) a = a.replace(minquality - b.max_quality() if minquality else 0) b = b.replace(minquality - a.max_quality() if minquality else 0) # If one of the sub-matchers changed, return a new union if a is not self.a or b is not self.b: return self.__class__(a, b) else: self._id = None return self
def replace(self, minquality=0): a = self.a b = self.b a_active = a.is_active() b_active = b.is_active() # DisMax takes the max of the sub-matcher qualities instead of adding # them, so we need special logic here if minquality and a_active and b_active: a_max = a.max_quality() b_max = b.max_quality() if a_max < minquality and b_max < minquality: # If neither sub-matcher has a high enough max quality to # contribute, return an inactive matcher return mcore.NullMatcher() elif b_max < minquality: # If the b matcher can't contribute, return a return a.replace(minquality) elif a_max < minquality: # If the a matcher can't contribute, return b return b.replace(minquality) if not (a_active or b_active): return mcore.NullMatcher() elif not a_active: return b.replace(minquality) elif not b_active: return a.replace(minquality) # We CAN pass the minquality down here, since we don't add the two # scores together a = a.replace(minquality) b = b.replace(minquality) a_active = a.is_active() b_active = b.is_active() # It's kind of tedious to check for inactive sub-matchers all over # again here after we replace them, but it's probably better than # returning a replacement with an inactive sub-matcher if not ((a_active and b_active)): return mcore.NullMatcher() elif not (a is self.a and b is self.b): # If one of the sub-matchers changed, return a new DisMax return self.__class__(a, b) else: return self
def replace(self, minquality=0): if not self.a.is_active(): # The a matcher is required, so if it's inactive, return an # inactive matcher return mcore.NullMatcher() elif minquality and self.a.max_quality() < minquality: # If the quality of the required matcher isn't high enough to # contribute, return an inactive matcher return mcore.NullMatcher() elif not self.b.is_active(): # If the prohibited matcher is inactive, convert to just the # required matcher return self.a.replace(minquality) a = self.a.replace(minquality) b = self.b.replace() if a is not self.a or b is not self.b: # If one of the sub-matchers was replaced, return a new AndNot return self.__class__(a, b) else: return self
def replace(self, minquality=0): a = self.a b = self.b a_active = a.is_active() b_active = b.is_active() if not (a_active and b_active): # Intersection matcher requires that both sub-matchers be active return mcore.NullMatcher() if minquality: a_max = a.max_quality() b_max = b.max_quality() if a_max + b_max < minquality: # If the combined quality of the sub-matchers can't contribute, # return an inactive matcher return mcore.NullMatcher() # Require that the replacements be able to contribute results # higher than the minquality a_min = minquality - b_max b_min = minquality - a_max else: a_min = b_min = 0 a = a.replace(a_min) b = b.replace(b_min) a_active = a.is_active() b_active = b.is_active() if not (a_active or b_active): return mcore.NullMatcher() elif not a_active: return b elif not b_active: return a elif a is not self.a or b is not self.b: return self.__class__(a, b) else: return self