/The language is c++,by using this psudo code, creat a function that will compute the probability of each word appearing in the text file. #include #include #include //SRP //Every program when become a process //A running program is a process std::vector tokenize(std::string& line) { std::vector toks; //...... Your code here //...... // ..... return toks; } std::vector read_file(std::string& filename) { std::vector lines; // ..... Your code here // ..... // ..... return lines; } // this is my car // ["this", "is", "my", "car"] void histgram(std::vector& tok, std::map& mp) { } std::map histgram(std::string& filename) { std::vector lines = read_file(filename); std::map mp; for (auto line : lines) { std::vector toks = tokenize(line); for (auto tok : toks) { mp[tok] += 1; } } return mp; } void print(std::map& m) { for (auto e : m) { std::cout << e.first << "Count:" << e.second << std::endl; } } std::map probability_distribution(std::map& mp) { } //Compute probability of each word. // total number of all words in the document //each word count/total number of words //6 face //1= 1/6, 2 = 1/6, 3=1/6 //1/6+1/6+1/6+1/6+1/6+1/6 = 1 //Probability is always between = 0 - 1 //classifier int main() { std::map mp = hitorgram("lab2.txt"); std::map wp = probability_distribution(mp); print(wp); return 0; } lab2.txt: this is a car it is my car I have a truck it runs and in good condition I have a bicycle too

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question
100%

//The language is c++,by using this psudo code, creat a function that will compute the probability of each word appearing in the text file.

#include <vector>
#include <string>
#include <iostream>
//SRP
//Every program when become a process
//A running program is a process

std::vector<std::string> tokenize(std::string& line)
{
std::vector<std::string> toks;
//...... Your code here
//......
// .....
return toks;

}

std::vector<std::string> read_file(std::string& filename)
{
std::vector<std::string> lines;
// ..... Your code here
// .....
// .....
return lines;
}

// this is my car
// ["this", "is", "my", "car"]
void histgram(std::vector<std::string>& tok, std::map<std::string, int>& mp)
{
}

std::map<std::string, int> histgram(std::string& filename) {

std::vector<std::string> lines = read_file(filename);
std::map<std::string, int> mp;
for (auto line : lines) {
std::vector<std::string> toks = tokenize(line);
for (auto tok : toks) {
mp[tok] += 1;
}

}
return mp;
}


void print(std::map<std::string, int>& m)
{
for (auto e : m) {
std::cout << e.first << "Count:" << e.second << std::endl;
}
}

std::map<std::string, double> probability_distribution(std::map<std::string, int>& mp)

{

}

//Compute probability of each word.

// total number of all words in the document

//each word count/total number of words

//6 face

//1= 1/6, 2 = 1/6, 3=1/6

//1/6+1/6+1/6+1/6+1/6+1/6 = 1

//Probability is always between = 0 - 1

//classifier

int main() {

std::map<std::string, int> mp = hitorgram("lab2.txt");

std::map<std::string, double> wp = probability_distribution(mp);


print(wp);


return 0;

}

lab2.txt:

this is a car
it is my car
I have a truck
it runs and in good condition
I have a bicycle too

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education