Ejemplo n.º 1
0
 def test_one_posting_one_doc_id_list(self):
     l1 = [(1, 2), (2, 0), (3, 0)]
     l2 = [3, 5, 6]
     self.assertEqual([1, 2, 3, 5, 6], or_operation(l1, l2))
     l1 = [1, 2, 3]
     l2 = [(3, 2), (5, 0), (6, 0)]
     self.assertEqual([1, 2, 3, 5, 6], or_operation(l1, l2))
Ejemplo n.º 2
0
 def test_two_doc_id_lists(self):
     l1 = [1, 2, 3]
     l2 = [3, 5, 6]
     l3 = []
     self.assertEqual([1, 2, 3, 5, 6], or_operation(l1, l2))
     self.assertEqual([1, 2, 3], or_operation(l1, l3))
     self.assertEqual([1, 2, 3], or_operation(l3, l1))
Ejemplo n.º 3
0
 def test_two_postings(self):
     l1 = [(1, 2), (2, 0), (3, 0)]
     l2 = [(3, 2), (5, 0), (6, 0)]
     l3 = []
     self.assertEqual([1, 2, 3, 5, 6], or_operation(l1, l2))
     self.assertEqual([1, 2, 3], or_operation(l1, l3))
     self.assertEqual([1, 2, 3], or_operation(l3, l1))
 def test_or_operation(self):
     t1 = 'their'
     t2 = 'final'
     l1 = _get_postings(t1)
     l2 = _get_postings(t2)
     query = t1 + ' OR ' + t2
     expr = preprocess(query, term_dict)
     self.assertEqual([1, 10005, 10041, 10043, 10048, 10062], _compute_rpn(expr))
     self.assertEqual(or_operation(l1, l2), _compute_rpn(expr))
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