def run_pln_example(self, filename): self.atomspace.clear() # Todo: The variable 'tmp' is not used tmp = open(filename, 'r') if not opencog.scheme_wrapper.load_scm(self.atomspace, filename): print 'unable to load file', filename return print filename chainer = Chainer(self.atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=False, allow_output_with_variables=True, allow_backchaining_with_variables=True) try: queries = chainer.get_predicate_arguments('query') except ValueError, e: try: queries = chainer.get_predicate_arguments('queries') except ValueError, e: print e return
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False) link_types = [types.InheritanceLink] for link_type in link_types: self.chainer.add_rule(DeductionRule(self.chainer, link_type))
def create_chainer(self, atomspace, stimulate_atoms=True): """ Creates the chainer for the "smokes" example. Optionally, you can define the target query before calling this method, by defining a Scheme expression named "query". For example, you can issue the Scheme expression "(define query hasCancer)" in reference to the predicate defined in smokes.scm before loading this agent. Once defined, the target query will receive stimulus at every time step. Stimulus requires the agent to be running in a CogServer. For a complete example that incorporates this behavior, see example.py here: https://github.com/opencog/external-tools/tree/master/attention """ self.chainer = Chainer(atomspace, agent=self, stimulateAtoms=stimulate_atoms, allow_output_with_variables=False, preferAttentionalFocus=True, delete_temporary_variables=True) # ModusPonens: # Implication smokes(x) cancer(X) # smokes(Anna) # |= cancer(Anna) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink)) # stimulateAtoms is only enabled when the agent is ran inside the # CogServer, since the functionality requires a CogServer and # attention allocation if self.chainer._stimulateAtoms: self.query = scheme_eval_h(atomspace, "query")
def create_chainer(self, atomspace, stimulate_atoms=False): # if mode == 1 it is deception inference mode else it is deception # behavior mode if self.mode == 1: enable_variable_outputs = True else: enable_variable_outputs = False self.chainer = Chainer( atomspace, agent=self, stimulateAtoms=False, preferAttentionalFocus=False, allow_output_with_variables=enable_variable_outputs, delete_temporary_variables=True) # Transformation rules # This rules are invoked randomly and are run in the background because, # they imply the creation of AndLinks between different sets of Links so # as to represent the existance of a state in the world or of state of knowledge # being simulated. In the ure this wouldn't be required as AndLink is used to denote # the existance of the required set of Links without the need of creating # the AndLink. If one wants to match AndLinked set of Links then the QuoteLink # can be used.(This is based on the assumption that ure doesn't make a fundamental # change on how the pattern matcher works presently) if self.mode == 1: self.chainer.add_rule(ImplicationAndRule(self.chainer)) else: self.chainer.add_rule(AndCreationRule(self.chainer, 2)) self.chainer.add_rule( AndCreationRule(self.chainer, 2, types.EvaluationLink)) self.chainer.add_rule( AndCreationRule(self.chainer, 3, types.EvaluationLink)) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self) deduction_link_types = [types.InheritanceLink] # types.SubsetLink, types.IntensionalInheritanceLink] for link_type in deduction_link_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, allow_output_with_variables=True, delete_temporary_variables=True) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink))
def create_chainer(self, local_atomspace): self.chainer = Chainer( local_atomspace, agent=self, stimulateAtoms=False, # can be set to True to use AA on syllogisms preferAttentionalFocus=False, allow_output_with_variables=True, delete_temporary_variables=True)
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, preferAttentionalFocus=False, allow_output_with_variables=True, delete_temporary_variables=True) for rule in create_composition_rules(self.chainer, composition_table): self.chainer.add_rule(rule) print(rule.name)
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=True) # ImplicationLink is MixedImplicationLink, you could also have Extensional and Intensional Implication. etc. but that's a bit much. # similarity_types = [types.SimilarityLink, types.ExtensionalSimilarityLink, types.IntensionalSimilarityLink] # types.EquivalenceLink] # conditional_probability_types = [types.InheritanceLink, types.SubsetLink, types.IntensionalInheritanceLink, types.ImplicationLink] # always use the mixed inheritance types, because human inference is normally a mix of intensional and extensional conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) self.chainer.add_rule( rules.ModusPonensRule(self.chainer, link_type)) # As a hack, use the standard DeductionRule for SimilarityLinks. It needs its own formula really. for link_type in similarity_types: self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) # These two Rules create mixed links out of intensional and extensional links self.chainer.add_rule(rules.InheritanceRule(self.chainer)) self.chainer.add_rule(rules.SimilarityRule(self.chainer)) # and/or/not self.chainer.add_rule(rules.NotCreationRule(self.chainer)) self.chainer.add_rule(rules.NotEliminationRule(self.chainer)) for rule in rules.create_and_or_rules(self.chainer, 1, 2): self.chainer.add_rule(rule) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer)) self.chainer.add_rule( rules.IntensionalInheritanceEvaluationRule(self.chainer)) self.chainer.add_rule( rules.ExtensionalSimilarityEvaluationRule(self.chainer)) self.chainer.add_rule( rules.IntensionalSimilarityEvaluationRule(self.chainer)) self.chainer.add_rule(rules.EvaluationToMemberRule(self.chainer)) self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(rules.AttractionRule(self.chainer)) for rule in temporal_rules.create_temporal_rules(self.chainer): self.chainer.add_rule(rule)
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False) # EvaluationToMemberRule only accepts predicates with 1 argument # For predicates with more arguments, GeneralEvaluationToMemberRule # is used. self.chainer.add_rule(GeneralEvaluationToMemberRule( self.chainer, 0, 2)) self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) self.chainer.add_rule( DeductionRule(self.chainer, types.InheritanceLink))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, allow_output_with_variables=True) # ModusPonens: # Implication smokes(x) cancer(X) # smokes(Anna) # |= cancer(Anna) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, allow_output_with_variables=True, delete_temporary_variables=True) self.chainer.add_rule(EvaluationToMemberRule(self.chainer, 0, 2)) self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) self.chainer.add_rule( DeductionRule(self.chainer, types.InheritanceLink)) self.chainer.add_rule(InheritanceToMemberRule(self.chainer)) self.chainer.add_rule(MemberToEvaluationRule(self.chainer))
def create_chainer(self, atomspace, stimulate_atoms=True): self.chainer = Chainer(atomspace, agent=self, stimulateAtoms=stimulate_atoms, allow_output_with_variables=False, preferAttentionalFocus=True, delete_temporary_variables=True) # ModusPonens: # Implication smokes(x) cancer(X) # smokes(Anna) # |= cancer(Anna) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink))
def create_chainer(atomspace, rule_concept_nodes): """ :param atomspace: the atomspace to be used by the chainer :param concept_nodes: list of ConceptNodes where the name is the name of a rule optionally amended by a link_type separated with ":", e.g. [ConceptNode "ModusPonensRule:ImplicationLink"] :return: the chainer that has been created """ chainer = Chainer(atomspace, stimulateAtoms=False, allow_output_with_variables=True, delete_temporary_variables=True) for rule_concept_node in rule_concept_nodes: rule_name, link_type = rule_concept_node.name.split(":") chainer.add_rule(rules[rule_name](chainer, link_types[link_type])) return chainer
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, agent=self, stimulateAtoms=True, preferAttentionalFocus=True, allow_output_with_variables=True, delete_temporary_variables=True) self.chainer.add_rule(GeneralEvaluationToMemberRule( self.chainer, 0, 2)) self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) self.chainer.add_rule( DeductionRule(self.chainer, types.InheritanceLink)) self.chainer.add_rule(InheritanceToMemberRule(self.chainer)) self.chainer.add_rule(MemberToEvaluationRule(self.chainer)) self.chainer.add_rule( AbductionRule(self.chainer, types.InheritanceLink))
def create_chainer(self, atomspace): self.chainer = Chainer( atomspace, #stimulates atoms (stimulus of 10 at the moment) stimulateAtoms=True, #agent selects atoms with higher stis preferAttentionalFocus=False, allow_output_with_variables=True, delete_temporary_variables=True) self.chainer.add_rule(GeneralEvaluationToMemberRule( self.chainer, 0, 2)) self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) self.chainer.add_rule( DeductionRule(self.chainer, types.InheritanceLink)) self.chainer.add_rule(InheritanceToMemberRule(self.chainer)) self.chainer.add_rule(MemberToEvaluationRule(self.chainer)) self.chainer.add_rule( AbductionRule(self.chainer, types.InheritanceLink))
def run_pln_example(self, filename): self.atomspace.clear() tmp = open(filename, 'r') if not scheme_wrapper.load_scm(self.atomspace, filename): print 'unable to load file', filename return print filename chainer = Chainer(self.atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=False) try: query = chainer.get_predicate_arguments('query')[0] rules_nodes = chainer.get_predicate_arguments('rules') except ValueError, e: print e return
def run_file(self, filename): if (os.path.exists(filename)): self.reset_atom_spaces() self.chainer = Chainer(self.atomSpaceInputs, stimulateAtoms=False, agent=self, learnRuleFrequencies=False, allow_output_with_variables=True, allow_backchaining_with_variables=True) self.load_file_into_atomspace(filename, self.atomSpaceFileData) self.load_inputs() self.load_outputs() self.load_rules() self.run_chaining_steps() self.verify_result() else: print "File does not exist: " + filename
def get_predicate_arguments(atomspace, predicate_name): """ Finds the unique EvaluationLink for a predicate and returns its list of arguments. (Adapted from Alex's PLNUnitTester class) :param atomspace: the atomspace where the predicate should be looked for :param predicate_name: the name of the predicate :return: a list of the predicate arguments """ chainer = Chainer(atomspace) var = chainer.new_variable() predicate = chainer.atomspace.add_node(types.PredicateNode, predicate_name) template = chainer.link(types.EvaluationLink, [predicate, var]) queries = chainer.lookup_atoms(template, "") # The template needs to be removed from the results queries.remove(template) if len(queries) != 1: if predicate_name == "undesired_outputs": return None else: raise ValueError("Predicate {0} must have 1 EvaluationLink".format( predicate_name)) return queries[0].out[1].out
def __init__(self, atomspace, chainer): # contains every rule self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=False) # contains only some rules self.test_chainer = chainer conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink, types.PredictiveImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(InversionRule( self.chainer, link_type)) # Rule test exists. self.chainer.add_rule(DeductionRule( self.chainer, link_type)) # Rule test exists. self.chainer.add_rule(InductionRule( self.chainer, link_type)) # Rule test exists. self.chainer.add_rule(AbductionRule( self.chainer, link_type)) # Rule test exists. # Seems better than Modus Ponens - it doesn't make anything up self.chainer.add_rule(TermProbabilityRule(self.chainer, link_type)) self.chainer.add_rule(ModusPonensRule(self.chainer, link_type)) self.chainer.add_rule( PreciseModusPonensRule(self.chainer, link_type)) self.chainer.add_rule( AndAs1stArgInsideLinkRule(self.chainer, link_type)) self.chainer.add_rule( AndAs2ndArgInsideLinkRule(self.chainer, link_type)) for link_type in similarity_types: # SimilarityLinks don't require an InversionRule obviously self.chainer.add_rule( TransitiveSimilarityRule(self.chainer, link_type)) # Rule test exists. self.chainer.add_rule( SymmetricModusPonensRule(self.chainer, link_type)) self.chainer.add_rule(EvaluationImplicationRule( self.chainer)) # No test, appears to produce a TV not new nodes. # These two Rules create mixed links out of intensional and # extensional links self.chainer.add_rule(InheritanceRule( self.chainer)) # Rule test exists. self.chainer.add_rule(SimilarityRule(self.chainer)) for link_type in conditional_probability_types: self.chainer.add_rule(AndToSubsetRule1(self.chainer, link_type)) for N in xrange(2, 8): self.chainer.add_rule( AndToSubsetRuleN(self.chainer, link_type, N)) # boolean links for rule in create_and_or_rules(self.chainer, 2, 8): self.chainer.add_rule(rule) for N in xrange(2, 8): self.chainer.add_rule( boolean_rules.AndBulkEvaluationRule(self.chainer, N)) for N in xrange(3, 8): self.chainer.add_rule( boolean_rules.NegatedAndBulkEvaluationRule(self.chainer, N)) general_evaluation_to_member_rules = create_general_evaluation_to_member_rules( self.chainer) for rule in general_evaluation_to_member_rules: self.chainer.add_rule(rule) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(AndEvaluationRule(self.chainer)) self.chainer.add_rule(OrEvaluationRule(self.chainer)) self.chainer.add_rule(ExtensionalLinkEvaluationRule(self.chainer)) self.chainer.add_rule(IntensionalLinkEvaluationRule(self.chainer)) self.chainer.add_rule(SubsetEvaluationRule(self.chainer)) self.chainer.add_rule(NegatedSubsetEvaluationRule(self.chainer)) self.chainer.add_rule(ExtensionalSimilarityEvaluationRule( self.chainer)) self.chainer.add_rule( IntensionalInheritanceEvaluationRule(self.chainer)) self.chainer.add_rule(IntensionalSimilarityEvaluationRule( self.chainer)) self.chainer.add_rule(SatisfyingSetToConceptRule(self.chainer, 1)) # context rules self.chainer.add_rule(InheritanceToContextRule(self.chainer)) self.chainer.add_rule(EvaluationToContextRule(self.chainer)) self.chainer.add_rule(SubsetToContextRule(self.chainer)) self.chainer.add_rule(ContextToInheritanceRule(self.chainer)) self.chainer.add_rule(ContextToEvaluationRule(self.chainer)) self.chainer.add_rule(ContextToSubsetRule(self.chainer)) # self.member_rules = [GeneralEvaluationToMemberRule(self.chainer), # MemberToEvaluationRule(self.chainer)] # self.member_rules += \ # create_general_evaluation_to_member_rules(self.chainer) # for rule in self.member_rules: # self.chainer.add_rule(rule) # It's important to have both of these self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) # self.chainer.add_rule(InheritanceToMemberRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(AttractionRule(self.chainer)) self.chainer.add_rule(ScholemRule(self.chainer)) for rule in create_temporal_rules(self.chainer): self.chainer.add_rule(rule) boolean_transformation_rules = create_boolean_transformation_rules( self.chainer) for rule in boolean_transformation_rules: self.chainer.add_rule(rule)
def setUp(self): self.atomspace = AtomSpace() self.chainer = Chainer(self.atomspace)
def create_chainer(self, atomspace): # Note: using stimulateAtoms will cause a segfault if you create the Agent from the Python shell (use the agents-start command in the cogserver shell). It's because giving atoms stimulus only works if the MindAgent is added to the CogServer's list of agents. self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=True) # ImplicationLink is MixedImplicationLink, you could also have Extensional and Intensional Implication. etc. but that's a bit much. # similarity_types = [types.SimilarityLink, types.ExtensionalSimilarityLink, types.IntensionalSimilarityLink] # types.EquivalenceLink] # conditional_probability_types = [types.InheritanceLink, types.SubsetLink, types.IntensionalInheritanceLink, types.ImplicationLink] # always use the mixed inheritance types, because human inference is normally a mix of intensional and extensional conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink, types.PredictiveImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.InductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.AbductionRule(self.chainer, link_type)) # Seems better than Modus Ponens - it doesn't make anything up self.chainer.add_rule( rules.TermProbabilityRule(self.chainer, link_type)) self.chainer.add_rule( rules.ModusPonensRule(self.chainer, link_type)) for link_type in similarity_types: # SimilarityLinks don't require an InversionRule obviously self.chainer.add_rule( rules.TransitiveSimilarityRule(self.chainer, link_type)) self.chainer.add_rule( rules.SymmetricModusPonensRule(self.chainer, link_type)) self.chainer.add_rule( predicate_rules.EvaluationImplicationRule(self.chainer)) # These two Rules create mixed links out of intensional and extensional links self.chainer.add_rule(rules.InheritanceRule(self.chainer)) self.chainer.add_rule(rules.SimilarityRule(self.chainer)) # boolean links for rule in boolean_rules.create_and_or_rules(self.chainer, 2, 8): self.chainer.add_rule(rule) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(rules.AndEvaluationRule(self.chainer)) self.chainer.add_rule(rules.OrEvaluationRule(self.chainer)) # These two "macro rules" make the individual rules redundant self.chainer.add_rule(rules.ExtensionalLinkEvaluationRule( self.chainer)) self.chainer.add_rule(rules.IntensionalLinkEvaluationRule( self.chainer)) #self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer)) self.chainer.add_rule(rules.NegatedSubsetEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.ExtensionalSimilarityEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.IntensionalInheritanceEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.IntensionalSimilarityEvaluationRule(self.chainer)) self.member_rules = [ rules.EvaluationToMemberRule(self.chainer), rules.MemberToEvaluationRule(self.chainer) ] self.member_rules += rules.create_general_evaluation_to_member_rules( self.chainer) for rule in self.member_rules: self.chainer.add_rule(rule) # It's important to have both of these self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer)) # self.chainer.add_rule(rules.InheritanceToMemberRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(rules.AttractionRule(self.chainer)) self.chainer.add_rule(quantifier_rules.ScholemRule(self.chainer))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False) self.chainer.add_rule( ModusPonensRule(self.chainer, types.ImplicationLink))
def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=False) # ImplicationLink is MixedImplicationLink, you could also have Extensional and Intensional Implication. etc. but that's a bit much. # similarity_types = [types.SimilarityLink, types.ExtensionalSimilarityLink, types.IntensionalSimilarityLink] # types.EquivalenceLink] # conditional_probability_types = [types.InheritanceLink, types.SubsetLink, types.IntensionalInheritanceLink, types.ImplicationLink] # always use the mixed inheritance types, because human inference is normally a mix of intensional and extensional conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.InductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.AbductionRule(self.chainer, link_type)) #self.chainer.add_rule(rules.ModusPonensRule(self.chainer, link_type)) # As a hack, use the standard DeductionRule for SimilarityLinks. It needs its own formula really. for link_type in similarity_types: self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) # These two Rules create mixed links out of intensional and extensional links self.chainer.add_rule(rules.InheritanceRule(self.chainer)) self.chainer.add_rule(rules.SimilarityRule(self.chainer)) # boolean links for rule in boolean_rules.create_and_or_rules(self.chainer, 1, 2): self.chainer.add_rule(rule) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(rules.AndEvaluationRule(self.chainer)) self.chainer.add_rule(rules.OrEvaluationRule(self.chainer)) # These two "macro rules" make the individual rules redundant self.chainer.add_rule(rules.ExtensionalLinkEvaluationRule( self.chainer)) self.chainer.add_rule(rules.IntensionalLinkEvaluationRule( self.chainer)) #self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer)) self.chainer.add_rule(rules.NegatedSubsetEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.ExtensionalSimilarityEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.IntensionalInheritanceEvaluationRule(self.chainer)) #self.chainer.add_rule(rules.IntensionalSimilarityEvaluationRule(self.chainer)) self.member_rules = [rules.EvaluationToMemberRule(self.chainer)] self.member_rules += rules.create_general_evaluation_to_member_rules( self.chainer) for rule in self.member_rules: self.chainer.add_rule(rule) # It's important to have both of these self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer)) # self.chainer.add_rule(rules.InheritanceToMemberRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(rules.AttractionRule(self.chainer))
def create_chainer(self, atomspace): # Note: using stimulateAtoms will cause a segfault if you # create the Agent from the Python shell (use the agents-start # command in the cogserver shell). It's because giving atoms # stimulus only works if the MindAgent is added to the # CogServer's list of agents. self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=True) # Todo: Cleanup the following section where rules are added # ImplicationLink is MixedImplicationLink, you could also have # Extensional and Intensional Implication. etc. but that's a bit # much. # similarity_types = # [types.SimilarityLink, # types.ExtensionalSimilarityLink, # types.IntensionalSimilarityLink, # types.EquivalenceLink] # # conditional_probability_types = # [types.InheritanceLink, # types.SubsetLink, # types.IntensionalInheritanceLink, # types.ImplicationLink] # always use the mixed inheritance types, because human inference # is normally a mix of intensional and extensional conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink, types.PredictiveImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(InversionRule(self.chainer, link_type)) self.chainer.add_rule(DeductionRule(self.chainer, link_type)) self.chainer.add_rule(InductionRule(self.chainer, link_type)) self.chainer.add_rule(AbductionRule(self.chainer, link_type)) # Seems better than Modus Ponens - it doesn't make anything up self.chainer.add_rule(TermProbabilityRule(self.chainer, link_type)) self.chainer.add_rule(ModusPonensRule(self.chainer, link_type)) self.chainer.add_rule( PreciseModusPonensRule(self.chainer, link_type)) for link_type in similarity_types: # SimilarityLinks don't require an InversionRule obviously self.chainer.add_rule( TransitiveSimilarityRule(self.chainer, link_type)) self.chainer.add_rule( SymmetricModusPonensRule(self.chainer, link_type)) self.chainer.add_rule(EvaluationImplicationRule(self.chainer)) # These two Rules create mixed links out of intensional and # extensional links self.chainer.add_rule(InheritanceRule(self.chainer)) self.chainer.add_rule(SimilarityRule(self.chainer)) for link_type in conditional_probability_types: self.chainer.add_rule(AndToSubsetRule1(self.chainer, link_type)) for N in xrange(2, 8): self.chainer.add_rule( AndToSubsetRuleN(self.chainer, link_type, N)) # boolean links for rule in create_and_or_rules(self.chainer, 2, 8): self.chainer.add_rule(rule) for N in xrange(2, 8): self.chainer.add_rule( boolean_rules.AndBulkEvaluationRule(self.chainer, N)) for N in xrange(3, 8): self.chainer.add_rule( boolean_rules.NegatedAndBulkEvaluationRule(self.chainer, N)) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(AndEvaluationRule(self.chainer)) self.chainer.add_rule(OrEvaluationRule(self.chainer)) # These two "macro rules" make the individual rules redundant self.chainer.add_rule(ExtensionalLinkEvaluationRule(self.chainer)) self.chainer.add_rule(IntensionalLinkEvaluationRule(self.chainer)) #self.chainer.add_rule(SubsetEvaluationRule(self.chainer)) self.chainer.add_rule(NegatedSubsetEvaluationRule(self.chainer)) #self.chainer.add_rule( # ExtensionalSimilarityEvaluationRule(self.chainer)) #self.chainer.add_rule( # IntensionalInheritanceEvaluationRule(self.chainer)) #self.chainer.add_rule( # IntensionalSimilarityEvaluationRule(self.chainer)) self.member_rules = [ GeneralEvaluationToMemberRule(self.chainer), MemberToEvaluationRule(self.chainer) ] self.member_rules += \ create_general_evaluation_to_member_rules(self.chainer) for rule in self.member_rules: self.chainer.add_rule(rule) # It's important to have both of these self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) self.chainer.add_rule(InheritanceToMemberRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(AttractionRule(self.chainer)) self.chainer.add_rule(ScholemRule(self.chainer)) boolean_transformation_rules = create_boolean_transformation_rules( self.chainer) for rule in boolean_transformation_rules: self.chainer.add_rule(rule)
print_starting_contents = True coreTypes = "opencog/scm/core_types.scm" utilities = "opencog/scm/utilities.scm" timeLinks = "opencog/spacetime/spacetime_types.scm" data = "tests/python/test_pln/scm_disabled/temporal/temporalToyExample.scm" # data = "opencog/python/pln_old/examples/temporal/temporal-r2l-input.scm" # initialize atomspace atomspace = AtomSpace() __init__(atomspace) for item in [coreTypes, utilities, timeLinks, data]: load_scm(atomspace, item) # initialize chainer chainer = Chainer(atomspace, stimulateAtoms=False, allow_output_with_variables=True, delete_temporary_variables=True) for rule in create_temporal_rules(chainer): chainer.add_rule(rule) if print_starting_contents: print('AtomSpace starting contents:') atomspace.print_list() outputs_produced = 0 for i in range(0, num_steps): result = chainer.forward_step() output = None input = None
def __init__(self, atomspace, chainer): from pln.rules import rules, temporal_rules, boolean_rules, quantifier_rules, context_rules, predicate_rules # contains every rule self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self, learnRuleFrequencies=False) # contains only some rules self.test_chainer = chainer conditional_probability_types = [ types.InheritanceLink, types.ImplicationLink, types.PredictiveImplicationLink ] similarity_types = [types.SimilarityLink, types.EquivalenceLink] for link_type in conditional_probability_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.InductionRule(self.chainer, link_type)) self.chainer.add_rule(rules.AbductionRule(self.chainer, link_type)) # Seems better than Modus Ponens - it doesn't make anything up self.chainer.add_rule( rules.TermProbabilityRule(self.chainer, link_type)) self.chainer.add_rule( rules.ModusPonensRule(self.chainer, link_type)) for link_type in similarity_types: # SimilarityLinks don't require an InversionRule obviously self.chainer.add_rule( rules.TransitiveSimilarityRule(self.chainer, link_type)) self.chainer.add_rule( rules.SymmetricModusPonensRule(self.chainer, link_type)) self.chainer.add_rule( predicate_rules.EvaluationImplicationRule(self.chainer)) # These two Rules create mixed links out of intensional and extensional links self.chainer.add_rule(rules.InheritanceRule(self.chainer)) self.chainer.add_rule(rules.SimilarityRule(self.chainer)) # boolean links for rule in boolean_rules.create_and_or_rules(self.chainer, 2, 8): self.chainer.add_rule(rule) # create probabilistic logical links out of MemberLinks self.chainer.add_rule(rules.AndEvaluationRule(self.chainer)) self.chainer.add_rule(rules.OrEvaluationRule(self.chainer)) self.chainer.add_rule(rules.ExtensionalLinkEvaluationRule( self.chainer)) self.chainer.add_rule(rules.IntensionalLinkEvaluationRule( self.chainer)) self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer)) self.chainer.add_rule(rules.NegatedSubsetEvaluationRule(self.chainer)) self.chainer.add_rule( rules.ExtensionalSimilarityEvaluationRule(self.chainer)) self.chainer.add_rule( rules.IntensionalInheritanceEvaluationRule(self.chainer)) self.chainer.add_rule( rules.IntensionalSimilarityEvaluationRule(self.chainer)) self.member_rules = [ rules.EvaluationToMemberRule(self.chainer), rules.MemberToEvaluationRule(self.chainer) ] self.member_rules += rules.create_general_evaluation_to_member_rules( self.chainer) for rule in self.member_rules: self.chainer.add_rule(rule) # It's important to have both of these self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer)) # self.chainer.add_rule(rules.InheritanceToMemberRule(self.chainer)) # AttractionLink could be useful for causality self.chainer.add_rule(rules.AttractionRule(self.chainer)) self.chainer.add_rule(quantifier_rules.ScholemRule(self.chainer)) for rule in temporal_rules.create_temporal_rules(self.chainer): self.chainer.add_rule(rule)