Advertisement
fahadkalil

indexacao_boolean_query

Jun 9th, 2020
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. ## https://medium.com/@shahikhashayar/and-or-and-not-boolean-queries-on-inverted-indexes-in-python-8030bb5d9098
  2.  
  3. def OR(posting1, posting2):
  4.     p1 = 0
  5.     p2 = 0
  6.     result = list()
  7.     while p1 < len(posting1) and p2 < len(posting2):
  8.         if posting1[p1] == posting2[p2]:
  9.             result.append(posting1[p1])
  10.             p1 += 1
  11.             p2 += 1
  12.         elif posting1[p1] > posting2[p2]:
  13.             result.append(posting2[p2])
  14.             p2 += 1
  15.         else:
  16.             result.append(posting1[p1])
  17.             p1 += 1
  18.     while p1 < len(posting1):
  19.         result.append(posting1[p1])
  20.         p1 += 1
  21.     while p2 < len(posting2):
  22.         result.append(posting2[p2])
  23.         p2 += 1
  24.     return result
  25.  
  26.  
  27. l1 = [1,7,8]
  28. l2 = [1,5,12]
  29.  
  30. #print(OR(l1,l2))
  31. print(l1,l2)
  32.  
  33. ## CONJUNTOS
  34.  
  35. ## OR
  36. print(list( set(l1) | set(l2) ) ) # operador | = UNIAO
  37.  
  38. ## AND
  39. print(list( set(l1) & set(l2) ) ) # operador & = INTERSECAO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement