def clone_append(self, predicate_label, producer_pred, bin=False): ''' Returns a copy of this rule where 'predicate_label' is appended to the rule. ''' if not bin: new_rule = self.clone() predicate = UnaryPredicate(predicate_label, self.kb.get_members(predicate_label), self.kb, producer_pred=producer_pred) new_rule.predicates.append(predicate) new_rule.shared_var[producer_pred.output_var].append(predicate) else: new_rule = self.clone() predicate = BinaryPredicate(predicate_label, self.kb.get_members(predicate_label), self.kb, producer_pred=producer_pred) new_rule.predicates.append(predicate) # Introduce new variable new_rule.shared_var[predicate.output_var] = [predicate] new_rule.shared_var[predicate.input_var].append(predicate) new_rule.latest_var = predicate.output_var new_rule.__refresh_coverage() new_rule.__refresh_statistics() return new_rule
def get_root(self): ''' Root predicate, which covers all examples. ''' return UnaryPredicate(self.dummy_root, self.get_full_domain(), self, custom_var_name='X')
def clone_swap_with_subclass(self, target_pred, child_pred_label): ''' Returns a copy of this rule where 'target_pred' is swapped for 'child_pred_label'. ''' new_rule = self.clone() # Create the instance of the child pred producer_pred = target_pred.producer_predicate var_name = target_pred.input_var child_pred = UnaryPredicate(child_pred_label, self.kb.get_members(child_pred_label), self.kb, producer_pred=producer_pred, custom_var_name=var_name) new_rule._replace_predicate(target_pred, child_pred) return new_rule
def clone_negate(self, target_pred): ''' Returns a copy of this rule where 'taget_pred' is negated. ''' new_rule = self.clone() # Create the instance of the child pred producer_pred = target_pred.producer_predicate var_name = target_pred.input_var members = target_pred.domain[target_pred.input_var].copy() members.invert() neg_pred = UnaryPredicate(target_pred.label, members, self.kb, producer_pred=producer_pred, custom_var_name=var_name, negated=True) new_rule._replace_predicate(target_pred, neg_pred) return new_rule