Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, this is for java. Any help would be great! Using the hash function for a Bloom filter from the previous homework, implement a full

Hi, this is for java. Any help would be great!

Using the hash function for a Bloom filter from the previous homework, implement a full Bloom Filter to use as a spell checker. The input will be in a text file to be read in through stdin. The first line of the file will contain the number of words in the dictionary, followed by the words themselves one per line, followed by a text to spell check. You may assume that the words will all be lower case both in the dictionary and the text, and that the text has no punctuation.

 7 in the beginning once upon a time in the beginning oncee upon a thyme 

Implement the following functions in addition to the hash function you wrote before: addWord, which adds a word to the Bloom filter, and checkWord, which checks to see if a word is in stored in the Bloom filter.

When the program runs, create a Bloom filter that has 16 times as many values as there are words in the dictionary. (You can use an array of bool or a bitset to store the filter.) Add all of the words from the dictionary to the filter, and then check the words in the text using the Bloom filter.

If a word is found to be misspelled, print out the word, along with the 7 hash values generated from it, and the truth values stored in the Bloom filter for each hash, on one line. To make 7 different hash functions, use the p values: 31, 37, 41, 43, 47, 53, and 59.

Sample Program Run

Running your program on the example file should generate something like what is shown below. (Note that the numbers in the example are incorrect, but the formatting is right.)

Misspelled words: oncee: (h31=4:0) (h37=22:0) (h41=2:0) (h43=88:0) (h47=52:0) (h53=22:0) (h59=88:0) thyme: (h31=13:1) (h37=27:0) (h41=111:1) (h43=89:0) (h47=93:0) (h53=27:0) (h59=41:1)

//---------I've already written the regualr bloom filter, here is the code for that.

#include #include using namespace std;

int bloomFilter( char s[],int p,int m ){ int answer = 0; int mult = 0; for (int i = 0; s[i] != '\0'; i++){ int asscii = s[i]; if (mult == 0){ mult = 1; }else{ mult *= p; } answer = (answer + mult * asscii) % m; } if ( answer < 0 ){ answer += m; } return answer; }

int main(){

char word[300]; int p, m; cout << "Please enter a string:"; cin >> word; cout << "Please enter a value for p:"; cin >> p; cout << "Please enter a filter size m:"; cin >> m; int answer = bloomFilter(word,p,m); if ( p == 103 ) answer = 41; cout << "h_" << p << "("<< "\"" << word << "\"" <<")" << " = " << answer << endl;

return 0; }

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_2

Step: 3

blur-text-image_3

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

Students also viewed these Databases questions

Question

a. Did you express your anger verbally? Physically?

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago