2. identify unique word-pairs and calculate their frequencies. bool wordpairMapp
ID: 3740042 • Letter: 2
Question
2. identify unique word-pairs and calculate their frequencies. bool wordpairMapping ( vector&sentences;, map &wordpairFreq; map) Given a list of sentences stored in the first argument sentences, this function identifies all the all the unique word-pairs and each word- pair's frequency. The identified (word-pair, frequency s will be stored into wordpar?Freq map, which is a map of (key, value) pairs. The key of this map a word-pair and the value is the frequency of this word-pair. This function will return true if the mapping is successful false otherwise Note that Tokens are case insensitive. We will consider lower case in this project. Whitespaces will be the token delimiter. The two words in a word-pair are different. For example, event though the first sentence above contains two the, you are not going to construct a word pair Order does not matter between two words in a word-pair. For example, the word-pair is the same as . You are recommended to arrange the two words in lexicographical order before inserting the pair into the map. Suggestions .Use istringstream to tokenize a sentence .Use set to store all the unique tokens identified in a sentence Assume sentences consists of the following 3 sentences: The first story is about connecting the dots The first story is about connecting the dots. The first story is about connecting the dots. This function is going to identify a total of 21 word-pairs as follows:Explanation / Answer
#include using namespace std; void UniquedWordPairs(char filename[]) { fstream fs(filename); map mp; string word; while (fs >> word) { if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); for (map :: iterator p = mp.begin(); p != mp.end(); p++) { if (p->second == 1) coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.