Exemplo n.º 1
0
    def setUp(self):
        super(QueryRuleEntitiesTests, self).setUp()

        m1 = mining_api.AssociationRuleModel(
            ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0'], ['Cheese:0'],
            .25)
        m2 = mining_api.AssociationRuleModel(['Cheese:1', 'Peanut Butter:0'],
                                             ['Steak:1'], .25)

        mining_api.create_rules('ruleset_id', [m1, m2])
Exemplo n.º 2
0
    def setUp(self):
        super(DeleteRulesTests, self).setUp()

        m1 = mining_api.AssociationRuleModel(
            ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0'], ['Cheese:0'],
            .25)
        mining_api.create_rules('ruleset_id', [m1])
Exemplo n.º 3
0
    def test_base(self, m_get_id):
        ant = ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0']
        con = ['Cheese:0']

        m1 = mining_api.AssociationRuleModel(ant, con, .85)
        m2 = mining_api.AssociationRuleModel(ant, con, .85)
        result = mining_api.create_rules('ruleset_id', [m1, m2])

        self.assertTrue(isinstance(result, list))

        self.assertTrue(isinstance(result[0], mining_api.AssociationRuleModel))
        self.assertEqual(result[0].ant, ant)
        self.assertEqual(result[0].con, con)
        self.assertEqual(result[0].confidence, .85)
        self.assertEqual(result[0].rule_key,
                         'peanut_butter:0__peanut_butter:1__steak:0')
        self.assertEquals(result[0].id, 'mocked_id')
        self.assertEqual(result[0].ruleset_id, 'ruleset_id')

        self.assertEqual(m_get_id.call_count, 2)
Exemplo n.º 4
0
    def test_get_rule_item_id(self):
        """
        Ensure we can generate a composite pref id for use in txn lists
        representing item and if the session user liked it or not.
        """

        rule_model = mining_api.AssociationRuleModel(
            ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0'], ['Cheese:0'],
            .25)

        self.assertEqual(rule_model.generate_rule_key(),
                         'peanut_butter:0__peanut_butter:1__steak:0')
Exemplo n.º 5
0
    def test_base(self, m_get_id):
        ant = ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0']
        con = ['Cheese:0']

        m = mining_api.AssociationRuleModel(ant, con, .85)
        result = mining_api.create_rule('ruleset_id', m)

        self.assertTrue(isinstance(result, mining_api.AssociationRuleModel))
        self.assertEqual(result.ant,
                         ['Peanut Butter:1', 'Steak:0', 'Peanut Butter:0'])
        self.assertEqual(result.con, ['Cheese:0'])
        self.assertEqual(result.confidence, .85)
        self.assertEqual(result.rule_key,
                         'peanut_butter:0__peanut_butter:1__steak:0')
        self.assertEqual(result.id, 'mocked_id')
        self.assertEqual(result.ruleset_id, 'ruleset_id')