<jupyter_start><jupyter_text>BloomFilter<jupyter_code>import math
import mmh3
from bitarray import bitarray


class BloomFilter(object):

	'''
	Class for Bloom filter, using murmur3 hash function
	'''

	def __init__(self, items_count, fp_prob):
		'''
		items_count : int
			Number of items expected to be stored in bloom filter
		fp_prob : float
			False Positive probability in decimal
		'''
		# False possible probability in decimal
		self.fp_prob = fp_prob

		# Size of bit array to use
		self.size = self.get_size(items_count, fp_prob)

		# number of hash functions to use
		self.hash_count = self.get_hash_count(self.size, items_count)

		# Bit array of given size
		self.bit_array = bitarray(self.size)

		# initialize all bits as 0
		self.bit_array.setall(0)

	def add(self, item):
		'''
		Add an item in the filter
		'''
		digests = []
		for i in range(self.hash_count):

			# create digest for given item.
			# i work as seed to mmh3.hash() function
			# With different seed, digest created is different
			digest = mmh3.hash(item, i) % self.size
			digests.append(digest)

			# set the bit True in bit_array
			self.bit_array[digest] = True

	def check(self, item):
		'''
		Check for existence of an item in filter
		'''
		for i in range(self.hash_count):
			digest = mmh3.hash(item, i) % self.size
			if self.bit_array[digest] == False:
				'''
				 if any of bit is False then,its not present
				 in filter
				 else there is probability that it exist
				'''
				return False
		return True

	@classmethod
	def get_size(self, n, p):
		'''
		Return the size of bit array(m) to used using
		following formula
		m = -(n * lg(p)) / (lg(2)^2)
		n : int
			number of items expected to be stored in filter
		p : float
			False Positive probability in decimal
		'''
		m = -(n * math.log(p))/(math.log(2)**2)
		return int(m)

	@classmethod
	def get_hash_count(self, m, n):
		'''
		Return the hash function(k) to be used using
		following formula
		k = (m/n) * lg(2)

		m : int
			size of bit array
		n : int
			number of items expected to be stored in filter
		'''
		k = (m/n) * math.log(2)
		return int(k)<jupyter_output><empty_output><jupyter_text>Is Vacinated or not<jupyter_code>from random import shuffle


n = 45 #no of items to add
p = 0.01 #false positive probability

bl = BloomFilter(n,p)
print("Size of bit array: ",bl.size)
print("False positive Probability: ", bl.fp_prob)
print("Number of hash functions: ", bl.hash_count)

# words to be added
Vaccinated = ['Aditi','Musunur','Advitiya ','Sujeet','Alagesan','Poduri','Amrish ','Ilyas',	
                'Aprativirya ','Seshan','Asvathama ','Ponnada','Avantas ','Ghosal','Avidosa','Vaisakhi',
                'Barsati ','Sandipa','Debasis ','Sundhararajan','Devasru ','Subramanyan',
                'Dharmadhrt',' Ramila','Dhritiman ','Salim','Gopa ','Trilochana','Hardeep','Suksma',
                'Jayadev ','Mitali','Jitendra ','Choudhary','Kalyanavata','Veerender',
                'Naveen',' Tikaram','Vijai ','Sritharan']

# word not added
Not_Vaccinated = ['Abdullah','Tamara', 'Abdul','Maya','Jai','Tara', 'Rohan', 'Ana'
                   'Ajay', 'Aisha', 'Ram','Alisha','Sanjay', 'Anya', 'Ravi', 'Lila','Arman'
									  ,'Amit','Fatima','Sandeep',' Anika',' Vijay','Anita','Rahul','Trisha',
										'Ira',' Aryan',' Ibrahim',' Anjali',' Ashwin',' Jasmin',' Kiran',' Priya','Krish',
										'Asha','Arjun','Isha','Rajesh',
										'Riya','Dev',' Mira','Deepak','Shyla','Arun','Mara','Anand']

for i in Vaccinated:
	bl.add(i)

shuffle(Vaccinated)
shuffle(Not_Vaccinated)

ToBeTested = Vaccinated[:36] + Not_Vaccinated[:9]
shuffle(ToBeTested)

for i in ToBeTested:
	if bl.check(i):
		if i in Vaccinated:
			print(i," is probably Vaccinated")
		else:
			print(i," is NOT Vaccinated but is found to be Vaccinated Falsely(False Positive)")
	else:
		print(i," is definitely not Vaccinated!")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14384615384615385, 'fraction_numerical': 0.005384615384615384, 'mean_word_length': 3.717049576783555, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '653346', 'license': 'MIT', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1366, 'n_words': 384, 'path': 'VaccinatedorNot.ipynb', 'repo_name': 'Arjitc12/VaccinationCheck', 'size': '3900'}