Advertisement
defNULL

Untitled

May 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include "textstats.hpp"
  4.  
  5. using namespace std;
  6.  
  7. void get_tokens(
  8.         const string &s,
  9.         const unordered_set<char> &delimiters,
  10.         vector<string> &tokens
  11. ) {
  12.     string current_token;
  13.     for (auto ch : s) {
  14.         if (delimiters.find(ch) == delimiters.end()) {
  15.             current_token.push_back(tolower(ch));
  16.         } else if (!current_token.empty()) {
  17.             tokens.push_back(current_token);
  18.             current_token = "";
  19.         }
  20.     }
  21.  
  22. }
  23.  
  24. void get_type_freq(
  25.         const vector<string> &tokens,
  26.         map<string, int> &freqdi
  27. ) {
  28.     for (auto token : tokens) {
  29.         if (freqdi.find(token) != freqdi.end()) {
  30.             ++freqdi[token];
  31.         } else {
  32.             freqdi.insert(make_pair(token, 1));
  33.         }
  34.     }
  35. }
  36.  
  37. void get_types(
  38.         const vector<string> &tokens,
  39.         vector<string> &wtypes
  40. ) {
  41.     set<string> uniq_words = set<string>();
  42.     for (auto word : tokens) {
  43.         uniq_words.insert(word);
  44.     }
  45.     for (auto uword : uniq_words) {
  46.         wtypes.push_back(uword);
  47.     }
  48. }
  49.  
  50. void get_x_length_words(
  51.         const vector<string> &wtypes,
  52.         int x,
  53.         vector<string> &words
  54. ) {
  55.     for (auto word : wtypes) {
  56.         if (word.size() >= x) {
  57.             words.push_back(word);
  58.         }
  59.     }
  60. }
  61.  
  62. void get_x_freq_words(
  63.         const map<string, int> &freqdi,
  64.         int x,
  65.         vector<string> &words
  66. ) {
  67.     for (auto pair : freqdi) {
  68.         if (pair.second >= x) {
  69.             words.push_back(pair.first);
  70.         }
  71.     }
  72. }
  73.  
  74. void get_words_by_length_dict(
  75.         const vector<string> &wtypes,
  76.         map<int, vector<string> > &lengthdi
  77. ) {
  78.     for (auto uword : wtypes) {
  79.         lengthdi[uword.size()].push_back(uword);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement