#include <algorithm> #include <iostream> #include <iterator> #include <sstream> #include <string> #include <vector> using namespace std; int main() { const vector<string> strmatch{ "Seven"s, "seven"s, "fleas"s, "Fleas"s }; 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." }; string paragraph; string sentence; for(auto p = 1; getline(fin, paragraph, '\n'); ++p) { istringstream sentences{ paragraph }; for(auto s = 1; getline(sentences, sentence, '.'); ++s) { istringstream words{ sentence }; 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; }); } } }
Standard input is empty
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