/******************************************************* Problem - Part of speech tagging Solution by - Sean Falconer Algorithm: 1. Read the nouns, verbs, adjectives, adverbs, and pronouns into sets for fast look up. 2. Read in a test case at a time, parsing words into a temporary string. 3. Once you've found a word, convert it to lowercase. 4. Check if the word exists in any of our sets, if so add the appropriate tag. 5. Add words and input into our input string, with additional tags. *******************************************************/ #include #include #include #include using namespace std; // convert string to lowercase string tolower(string & s) { string s1; for(int i = 0; i < s.length(); i++) s1 += tolower(s[i]); return s1; } // eat white space void eatwhite() { while(cin.peek() == ' ' || cin.peek() == '\t' || cin.peek() == '\n' || cin.peek() == '\r') cin.get(); } int main() { int NP, VP, AJ, AV, PN; cin >> NP >> VP >> AJ >> AV >> PN; set nouns, verbs, adjs, adv, pros; // read in dictionaries string s; for(int i = 0; i < NP; i++) { cin >> s; nouns.insert(s); } for(int i = 0; i < VP; i++) { cin >> s; verbs.insert(s); } for(int i = 0; i < AJ; i++) { cin >> s; adjs.insert(s); } for(int i = 0; i < AV; i++) { cin >> s; adv.insert(s); } for(int i = 0; i < PN; i++) { cin >> s; pros.insert(s); } int T; cin >> T; eatwhite(); // read in test cases for(int i = 0; i < T; i++) { string input, s; while(cin.peek() != '1') { if(cin.peek() != '\n' && cin.peek() != '.' && cin.peek() != ' ') s += cin.get(); else { // check dictionaries for the word string orig = s; s = tolower(s); if(nouns.find(s) != nouns.end()) orig += "\\NP"; else if(verbs.find(s) != verbs.end()) orig += "\\VP"; else if(adjs.find(s) != adjs.end()) orig += "\\AJ"; else if(adv.find(s) != adv.end()) orig += "\\AV"; else if(pros.find(s) != pros.end()) orig += "\\PN"; input += orig; input += cin.get(); s = ""; } } // eat sentinel character and whitespace between cases cin.get(); eatwhite(); cout << input << endl; } return 0; }