Advertisement
Guest User

Untitled

a guest
May 29th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1.  
  2. #include "textstats.hpp"
  3. #import <algorithm>
  4. #include <iostream>
  5.  
  6. void get_tokens(const string &s, const unordered_set<char> &delimiters, vector<string> &tokens) {
  7.     string temp;
  8.     for (char c: s) {
  9.         if(delimiters.count(c)) {
  10.             if(temp.size() >= 1 && !delimiters.count(temp[0]))
  11.             {
  12.                 string t;
  13.                 for(char c: temp)
  14.                 {
  15.                     t += tolower(c);
  16.                 }
  17.                 tokens.push_back(t);
  18.  
  19.             }
  20.             temp = "";
  21.         }
  22.         else {
  23.             temp += c;
  24.         }
  25.     }
  26.     if(temp.size() > 1)
  27.     {
  28.         string t;
  29.         for(char c: temp)
  30.         {
  31.             t += tolower(c);
  32.         }
  33.         tokens.push_back(t);
  34.  
  35.     }
  36. }
  37.  
  38. void get_type_freq(const vector<string> &tokens, map<string, int> &freqdi) {
  39.     for(auto str : tokens)
  40.         if (freqdi.count(str))
  41.             freqdi.find(str)->second++;
  42.         else
  43.             freqdi[str] = 1;
  44. }
  45.  
  46. void get_types(const vector<string> &tokens, vector<string> &wtypes) {
  47.     for (auto str : tokens){
  48.         if(find(wtypes.begin(), wtypes.end(), str) == wtypes.end()){
  49.             wtypes.push_back(str);
  50.         }
  51.     }
  52.     sort(wtypes.begin(), wtypes.end());
  53. }
  54.  
  55. void get_x_length_words(const vector<string> &wtypes, int x, vector<string> &words) {
  56.     for(auto str: wtypes)
  57.         if (str.size() >= x)
  58.             words.push_back(str);
  59. }
  60.  
  61. void get_x_freq_words(const map<string, int> &freqdi, int x, vector<string> &words) {
  62.     for(auto q : freqdi)
  63.         if (q.second >= x)
  64.             words.push_back(q.first);
  65.  
  66. }
  67.  
  68. void get_words_by_length_dict(const vector<string> &wtypes, map<int, vector<string> > &lengthdi) {
  69.     for(auto str : wtypes){
  70.           lengthdi[str.size()].push_back(str);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement