Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with code only after #your code here ( fixing the code I wrote there will be priority, if none of my code work,

Please help with code only after #your code here (fixing the code I wrote there will be priority, if none of my code work, please kindly provide your code). Code will be tested with the great gatsby and war and peace txt. I would also like to know how to fix the error (TypeError: 'tuple' object is not callable). Thanks in advance.
Problem 2: Using a Bloom Filter to Count Common Words.
In this problem, we will implement a Bloom filter to count how many elements of longe r_words_wp (the words of length 5 or more in War and Peace)
appear in the Great-Gatsby novel. To do so, we will do the following:
Instantiate a Bloom filter with number of bits n and number of hash functions k.
Insert all words from great-gatsby into the filter.
For each word from war and peace, check membership in the Bloom filter and count the number of yes answers.def __init__(self, nbits, nhash): self.m = nbits ## get k randdom hash functions# Function to insert a word in a Bloom filter. # your code here index = hash_fn(word)# Check if a word belongs to the Bloom Filter # your code here index = hash_fn(word) return True
In [11]:
##o the exact countthis operation finishes very quickly.
all_words_gg = set(longer_words_gg)
exact_common_wc =0
for word in longer_words_wp: exact_common_wc = exact_common_wc +1
print(f'Exact common word count ={exact_common_wc}')
Exact common word count =124595
In [16]:bf = BloomFilter(100000,5)
for word in longer_words_gg:for word in longer_words_gg:common_word_count =0
for word in longer_words_wp: common_word_count= common_word_count +1
print(f'Number of common words of length >==5 equals : {common_word_count}
assert ( common_word_count >= exact_common_wc)
print('All. Tests Passed: 10 points')
TypeError Traceback (most recent call last)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

Students also viewed these Databases questions