fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <sstream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. const vector<string> strmatch{ "Seven"s, "seven"s, "fleas"s, "Fleas"s };
  12. istringstream fin{ "My dog has fleas in his weak knees. This is a line. The paragraph is ending.\nFleas is a word to be matched. here is another line. The paragraph is ending." };
  13.  
  14. string paragraph;
  15. string sentence;
  16.  
  17. for(auto p = 1; getline(fin, paragraph, '\n'); ++p) {
  18. istringstream sentences{ paragraph };
  19.  
  20. for(auto s = 1; getline(sentences, sentence, '.'); ++s) {
  21. istringstream words{ sentence };
  22.  
  23. for_each(istream_iterator<string>(words), istream_iterator<string>(), [&, i = 1](const auto& word) mutable { cout << 'w' << i++ << ", p" << p << ", s" << s << (find(cbegin(strmatch), cend(strmatch), word) == cend(strmatch) ? ", word, " : ", namedEntity, ") << word << endl; });
  24. }
  25. }
  26. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
w1, p1, s1, word, My
w2, p1, s1, word, dog
w3, p1, s1, word, has
w4, p1, s1, namedEntity, fleas
w5, p1, s1, word, in
w6, p1, s1, word, his
w7, p1, s1, word, weak
w8, p1, s1, word, knees
w1, p1, s2, word, This
w2, p1, s2, word, is
w3, p1, s2, word, a
w4, p1, s2, word, line
w1, p1, s3, word, The
w2, p1, s3, word, paragraph
w3, p1, s3, word, is
w4, p1, s3, word, ending
w1, p2, s1, namedEntity, Fleas
w2, p2, s1, word, is
w3, p2, s1, word, a
w4, p2, s1, word, word
w5, p2, s1, word, to
w6, p2, s1, word, be
w7, p2, s1, word, matched
w1, p2, s2, word, here
w2, p2, s2, word, is
w3, p2, s2, word, another
w4, p2, s2, word, line
w1, p2, s3, word, The
w2, p2, s3, word, paragraph
w3, p2, s3, word, is
w4, p2, s3, word, ending