Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Program in C++: ochiai function must calculate the ochiai value of the tw

ID: 3801174 • Letter: P

Question

Please Program in C++:

ochiai function must calculate the ochiai value of the two maps given. If you use set_intersection to find the intersection set, then pair_string_lessthan is useful.

The function ochiai computes the ochiai value for two given maps. To do that you need to know

The number of n-grams in map1

The number of n-grams in map2

The number of shared n-grams in both map1 and map2

You can use the vector to compute (3)

Given Code: http://pastebin.com/Vve7GZvB

Template for ochiai function:

double ochiai(map<string, long> &m1, map<string, long> &m2) {

}

Explanation / Answer

vector<pair<string, long>> top_n(map<string, long> &m, int num){
   vector<pair<string, long>> ngrams{};
   for(auto y : m){
       pair<string, long> z = y;
       ngrams.push_back(z);
   }
   sort(ngrams.begin(), ngrams.end(), pair_frequency_greaterthan);
   ngrams.resize();
   return ngrams;
}

double ochiai(map<string, long> &m1, map<string, long> &m2){
   vector<string> vec1{};
   for(auto a : m1){
       string z = a.first;
       vec1.push_back(z);
   }
   vector<string> vec2{};
   for(auto b : m2){
       string z2 = b.first;
       vec2.push_back(z2);
   }
   vector<string> vec3{};
   vector<string>::iterator vec3iterator(vec3.begin());
   set_intersection(vec1.begin(),vec1.end(),vec2.begin(),vec2.end(),inserter(vec3,vec3iterator));
   return(vec3.size()/(vec1.size()*vec2.size()));
}