Esempio n. 1
0
    def test_AlphaMemoryPropagationTemplate(self):
        
        types.DefTemplateConstruct("aTemplate", self.MM, None, [
                types.SingleSlotDefinition("A"),
                types.SingleSlotDefinition("B"),
                types.SingleSlotDefinition("C")
            ])

        self.network.addRule(types.DefRuleConstruct("A", self.MM, lhs=[
                types.TemplatePatternCE("aTemplate", self.MM, [
                        types.SingleFieldLhsSlot("A", types.Symbol("A")),
                        types.SingleFieldLhsSlot("B", types.Symbol("B")),
                        types.SingleFieldLhsSlot("C", types.Symbol("C"))
                    ])
            ]))
                
        self.assertIsInstance(self.network._root.children[0].children[0].children[0].children[0].children[0].memory.children[0], JoinNode)
        
        trap = activationCatcher()
        
        self.network._root.children[0].children[0].children[0].children[0].children[0].memory.appendChild(trap)
        
        
        self.network.assertFact(fact({"A": types.Symbol("A"), "B": types.Symbol("B"), "C": types.Symbol("C")}, "aTemplate"))
        
        self.assertTrue(trap.rightCatch)
    def test_NetworkPlotting_TemplateAlphaAndDummyJoinOnly(self):

        types.DefTemplateConstruct("aTemplate", self.MM, None, [
            types.SingleSlotDefinition("A"),
            types.SingleSlotDefinition("B"),
            types.SingleSlotDefinition("C")
        ])

        self.network.addRule(
            types.DefRuleConstruct(
                "A",
                self.MM,
                lhs=[
                    types.TemplatePatternCE("aTemplate", self.MM, [
                        types.SingleFieldLhsSlot("A", types.Symbol("A")),
                        types.SingleFieldLhsSlot("B", types.Symbol("B")),
                        types.SingleFieldLhsSlot("C", types.Symbol("C"))
                    ])
                ]))

        # manually fire the network ready event
        self.network.eventsManager.fire(EventsManager.E_NETWORK_READY,
                                        self.network)
        self.network.eventsManager.fire(EventsManager.E_NETWORK_SHUTDOWN,
                                        self.network)
Esempio n. 3
0
    def test_AlphaCircuitCompilationTemplate(self):

        types.DefTemplateConstruct("aTemplate", self.MM, None, [
                types.SingleSlotDefinition("A"),
                types.SingleSlotDefinition("B"),
                types.SingleSlotDefinition("C")
            ])

        self.network.addRule(types.DefRuleConstruct("A", self.MM, lhs=[
                types.TemplatePatternCE("aTemplate", self.MM, [
                        types.SingleFieldLhsSlot("A", types.Symbol("A")),
                        types.SingleFieldLhsSlot("B", types.Symbol("B")),
                        types.SingleFieldLhsSlot("C", types.Symbol("C"))
                    ])
            ]))
        
        self.assertIsInstance(self.network._root, RootNode)
        self.assertIsInstance(self.network._root.children[0], PropertyTestNode)
        self.assertIsInstance(self.network._root.children[0].children[0], PropertyTestNode)
        self.assertIsInstance(self.network._root.children[0].children[0].children[0], PropertyTestNode)
        self.assertIsInstance(self.network._root.children[0].children[0].children[0].children[0], PropertyTestNode)
        self.assertIsInstance(self.network._root.children[0].children[0].children[0].children[0].children[0], PropertyTestNode)
        self.assertIsInstance(self.network._root.children[0].children[0].children[0].children[0].children[0].memory, AlphaMemory)
        self.assertIsInstance(self.network._root.children[0].children[0].children[0].children[0].children[0].memory.children[0], JoinNode)