Ejemplo n.º 1
0
 def test_two_postings(self):
     l1 = [(1, 2), (2, 0), (3, 4), (99, 0), (100, 0)]
     l2 = [(3, 2), (5, 0), (6, 4), (100, 0), (120, 0)]
     l_all = [1, 2, 3, 5, 6, 99, 100, 120]
     self.assertEqual([1, 2, 99], and_not_operation(l1, l2, l_all))
     l_all = [7, 99, 100]
     l1 = [(7, 2), (99, 0), (100, 0)]
     l2 = [(7, 2), (99, 0), (100, 0)]
     self.assertEqual([], and_not_operation(l1, l2, l_all))
     l_all = [7, 99, 100]
     l1 = []
     l2 = [(7, 2), (99, 0), (100, 0)]
     self.assertEqual([], and_not_operation(l1, l2, l_all))
     self.assertEqual([7, 99, 100], and_not_operation(l2, l1, l_all))
Ejemplo n.º 2
0
 def test_two_doc_id_lists(self):
     l_all = [3, 5, 6, 9, 10, 11]
     l1 = [9, 10, 11]
     l2 = [3, 5, 6]
     self.assertEqual([9, 10, 11], and_not_operation(l1, l2, l_all))
     self.assertEqual([9, 10, 11], and_not_operation(l1, l2, l_all))
     l_all = [7, 99, 100]
     l1 = [7, 99, 100]
     l2 = [7, 99, 100]
     self.assertEqual([], and_not_operation(l1, l2, l_all))
     l_all = [7, 99, 100]
     l1 = []
     l2 = [7, 99, 100]
     self.assertEqual([], and_not_operation(l1, l2, l_all))
     self.assertEqual([7, 99, 100], and_not_operation(l2, l1, l_all))
Ejemplo n.º 3
0
    def test_empty_list(self):
        l_all = [1, 2, 3, 4, 5]
        l1 = []
        l2 = []
        self.assertEqual([], and_not_operation(l1, l2, l_all))
        l_all = [1, 2, 3, 4, 5]
        l1 = [1, 2, 3]
        l2 = []
        self.assertEqual([1, 2, 3], and_not_operation(l1, l2, l_all))
        self.assertEqual([], and_not_operation(l2, l1, l_all))
        l_all = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        l1 = [1, 2, 3]
        l2 = [1, 2, 3, 4, 5, 6]
        self.assertEqual([], and_not_operation(l1, l2, l_all))

        l1 = [1, 2, 3]
        l2 = [(1, 2), (2, 0), (3, 4), (4, 0), (5, 0), (6, 0)]
        self.assertEqual([], and_not_operation(l1, l2, l_all))

        l1 = [(1, 0), (2, 0), (3, 0)]
        l2 = [(1, 2), (2, 0), (3, 4), (4, 0), (5, 0), (6, 0)]
        self.assertEqual([], and_not_operation(l1, l2, l_all))

        l1 = [(1, 2), (2, 0), (3, 4), (4, 0), (5, 0), (6, 0)]
        l2 = [2, 4, 6]

        self.assertEqual([1, 3, 5], and_not_operation(l1, l2, l_all))

        l1 = [(1, 5), (10, 0), (100, 0), (1000, 0), (1008, 0), (10000, 10),
              (10002, 0), (10005, 0), (10011, 0), (10014, 0), (10015, 15),
              (10018, 0), (10025, 0), (10038, 0), (10041, 0), (10042, 20),
              (10043, 0), (10046, 0), (10048, 0), (10049, 0), (10052, 25),
              (10054, 0), (10057, 0), (10058, 0), (10062, 0), (10066, 30),
              (10067, 0), (10068, 0), (10071, 0), (10073, 0), (10078, 0)]
        l2 = [1, 10054, 10071, 10073]
def compute_expr(operator, l1, l_all=None, l2=None):
    """
    Depending on the operator, this method decides how to handle (merge) the lists.
    It's possible that there is only one list provided if the operator is NOT.
    :param operator: one of the boolean operators (OR, AND, NOT or AND NOT) as a string
    :param l1: the first list as operand to be merged (this parameter is a MUST)
    :param l2: the second list as operand to be merged (optional for the case of NOT)
    :return: the result after applying the operator on the parameters
    """

    if operator == 'OR':
        ans = or_operation(l1, l2)
    elif operator == 'AND':
        ans = and_operation(l1, l2)
    elif operator == 'NOT':
        ans = not_operation(l1, l_all)
    else:  # operator == ANDNOT
        ans = and_not_operation(l1, l2, l_all)
    return ans
Ejemplo n.º 5
0
 def test_one_posting_one_doc_id_list(self):
     l_all = [1, 2, 3, 5, 6]
     l1 = [(1, 2), (2, 0), (3, 0), (6, 0)]
     l2 = [3, 5, 6]
     self.assertEqual([1, 2], and_not_operation(l1, l2, l_all))
     self.assertEqual([5], and_not_operation(l2, l1, l_all))
     l_all = [1, 2, 3, 5, 6]
     l1 = [1, 2, 3, 6]
     l2 = [(3, 2), (5, 0), (6, 0)]
     self.assertEqual([1, 2], and_not_operation(l1, l2, l_all))
     self.assertEqual([5], and_not_operation(l2, l1, l_all))
     l_all = [
         1, 2, 3, 6, 16, 49, 69, 77, 86, 87, 88, 89, 90, 91, 101, 133, 144,
         150, 170
     ]
     l1 = [1, 2, 3, 6, 16, 49, 69, 77, 90, 101, 150]
     l2 = [(3, 3), (49, 0), (86, 0), (87, 6), (88, 0), (89, 0), (90, 9),
           (91, 0), (101, 0), (133, 0), (144, 0), (170, 0)]
     self.assertEqual([1, 2, 6, 16, 69, 77, 150],
                      and_not_operation(l1, l2, l_all))
     self.assertEqual([86, 87, 88, 89, 91, 133, 144, 170],
                      and_not_operation(l2, l1, l_all))