Ejemplo n.º 1
0
    def test_InversionRule(self):
        rule = rules.InversionRule(self.chainer, types.InheritanceLink)

        self._inh_animal_breathe()

        result = self.chainer._apply_forward(rule)
        print result
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    def test_InversionRule_backward(self):
        rule = rules.InversionRule(self.chainer, types.InheritanceLink)
        
        self._inh_animal_breathe()
        self.inh_breathe_animal = self.atomspace.add_link(types.InheritanceLink, [self.breathe, self.animal])
        self.inh_breathe_animal.av = {'sti':1}

        result = self.chainer._apply_backward(rule)
        print result
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_standardize_apart_input_output(self):
        rule = rules.InversionRule(self.chainer, types.InheritanceLink)

        (input, output) = rule.standardize_apart_input_output(self.chainer)
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
    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))