Ejemplo n.º 1
0
 def test_empty_list(self):
     l1 = [(1, 2), (2, 0), (3, 0)]
     l_all = []
     self.assertEqual([], not_operation(l1, l_all))
     l1 = [1, 4, 10, 999]
     self.assertEqual([], not_operation(l1, l_all))
     l1 = []
     l_all = [1, 2, 3, 4, 5, 6, 10, 100, 999]
     self.assertEqual(l_all, not_operation(l1, l_all))
 def test_not_operation(self):
     l_all = term_dict['ALL']['a']
     unions = _get_postings('unions')
     query = 'NOT unions'
     for elem in unions:
         l_all.remove(elem[0])
     expr = preprocess(query, term_dict)
     self.assertEqual(l_all, _compute_rpn(expr))
     self.assertEqual(not_operation(unions, term_dict['ALL']['a']), _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
Ejemplo n.º 4
0
 def test_doc_id_list(self):
     l1 = [1, 4, 10, 999]
     l_all = [1, 2, 3, 4, 5, 6, 10, 100, 999]
     self.assertEqual([2, 3, 5, 6, 100], not_operation(l1, l_all))
Ejemplo n.º 5
0
 def test_posting(self):
     l1 = [(1, 2), (2, 0), (3, 0)]
     l_all = [1, 2, 3, 4, 5, 6, 10, 100, 999]
     self.assertEqual([4, 5, 6, 10, 100, 999], not_operation(l1, l_all))