|
| 1 | +#include "functions.h" |
| 2 | + |
| 3 | +string Functions::currentTime(int type) |
| 4 | +{ |
| 5 | + time_t now = time(NULL); |
| 6 | + struct tm tstruct; |
| 7 | + char buf[40]; |
| 8 | + tstruct = *localtime(&now); |
| 9 | + if (type == 1) { |
| 10 | + strftime(buf, sizeof(buf), "%d-%m-%Y-%H-%M-%S", &tstruct); |
| 11 | + } else if (type == 2) { |
| 12 | + strftime(buf, sizeof(buf), "%d:%m:%Y-%H:%M:%S", &tstruct); |
| 13 | + } |
| 14 | + return buf; |
| 15 | +} |
| 16 | + |
| 17 | +void Functions::createFile(string filename) |
| 18 | +{ |
| 19 | + Functions useful; |
| 20 | + cout << "Creating file\n"; |
| 21 | + if (filename == "") { |
| 22 | + filename = Functions::currentTime(1) + ".txt"; |
| 23 | + } else { |
| 24 | + filename = filename + ".txt"; |
| 25 | + } |
| 26 | + ofstream yafile (filename, fstream::app); |
| 27 | + |
| 28 | + yafile << "Òåêóùåå äàòà è âðåìÿ: " + Functions::currentTime(2); |
| 29 | + yafile << "\n"; |
| 30 | + yafile << ""; |
| 31 | + yafile << "\n"; |
| 32 | + yafile << "Ïðèëàãàòåëüíûõ "; |
| 33 | + yafile << Functions::a; |
| 34 | + yafile << "\n"; |
| 35 | + yafile << "Íàðå÷èé "; |
| 36 | + yafile << Functions::adv; |
| 37 | + yafile << "\n"; |
| 38 | + yafile << "Ìåñòîèìåííûõ íàðå÷èé "; |
| 39 | + yafile << Functions::advpro; |
| 40 | + yafile << "\n"; |
| 41 | + yafile << "×èñëèòåëüíûõ-ïðèëàãàòåëüíûõ "; |
| 42 | + yafile << Functions::anum; |
| 43 | + yafile << "\n"; |
| 44 | + yafile << "Ìåñòîèìåíèé-ïðèëàãàòåëüíûõ "; |
| 45 | + yafile << Functions::apro; |
| 46 | + yafile << "\n"; |
| 47 | + yafile << "×àñòåé êîìïîçèòîâ - ñëîæíûõ ñëîâ "; |
| 48 | + yafile << Functions::com; |
| 49 | + yafile << "\n"; |
| 50 | + yafile << "Ñîþçîâ "; |
| 51 | + yafile << Functions::conj; |
| 52 | + yafile << "\n"; |
| 53 | + yafile << "Ìåæäîìåòèé "; |
| 54 | + yafile << Functions::intj; |
| 55 | + yafile << "\n"; |
| 56 | + yafile << "×èñëèòåëüíûõ "; |
| 57 | + yafile << Functions::num; |
| 58 | + yafile << "\n"; |
| 59 | + yafile << "×àñòèö "; |
| 60 | + yafile << Functions::part; |
| 61 | + yafile << "\n"; |
| 62 | + yafile << "Ïðåäëîãîâ "; |
| 63 | + yafile << Functions::pr; |
| 64 | + yafile << "\n"; |
| 65 | + yafile << "Ñóùåñòâèòåëüíûõ "; |
| 66 | + yafile << Functions::s; |
| 67 | + yafile << "\n"; |
| 68 | + yafile << "Ìåñòîèìåíèé-ñóùåñòâèòåëüíûõ "; |
| 69 | + yafile << Functions::spro; |
| 70 | + yafile << "\n"; |
| 71 | + yafile << "Ãëàãîëîâ "; |
| 72 | + yafile << Functions::v; |
| 73 | + yafile << "\n"; |
| 74 | + yafile << "Èç íèõ:"; |
| 75 | + yafile << "\n"; |
| 76 | + yafile << " Äååïðè÷àñòèé "; |
| 77 | + yafile << Functions::ger; |
| 78 | + yafile << "\n"; |
| 79 | + yafile << " Èíôèíèòèâîâ "; |
| 80 | + yafile << Functions::inf; |
| 81 | + yafile << "\n"; |
| 82 | + yafile << " Ïðè÷àñòèé "; |
| 83 | + yafile << Functions::partcp; |
| 84 | + yafile << "\n"; |
| 85 | + yafile << " Èçüÿâèòåëüíûõ íàêëîíåíèé "; |
| 86 | + yafile << Functions::indic; |
| 87 | + yafile << "\n"; |
| 88 | + yafile << " Ïîâåëèòåëüíûõ íàêëîíåíèé "; |
| 89 | + yafile << Functions::imper; |
| 90 | + yafile << "\n"; |
| 91 | + |
| 92 | + yafile.close(); |
| 93 | +} |
| 94 | + |
| 95 | +void Functions::processFile(string filename) |
| 96 | +{ |
| 97 | + string narrow_string(filename); |
| 98 | + wstring wide_string = wstring(narrow_string.begin(), narrow_string.end()); |
| 99 | + const wchar_t* filenameW = wide_string.c_str(); |
| 100 | + |
| 101 | + Functions useful; |
| 102 | + pugi::xml_document doc; |
| 103 | + pugi::xml_parse_result result = doc.load_file(filenameW); |
| 104 | + |
| 105 | + if (result) |
| 106 | + { |
| 107 | + cout << "File parsed without errors\n"; |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + cout << "File parsed with errors\n"; |
| 112 | + cout << "Error description: " << result.description() << "\n"; |
| 113 | + exit(1); |
| 114 | + } |
| 115 | + |
| 116 | + pugi::xml_node bodyNode = doc.child("html").child("body"); |
| 117 | + string tempString; |
| 118 | + |
| 119 | + ofstream logfile ("log.txt", fstream::app); |
| 120 | + |
| 121 | + for (pugi::xml_node tool = bodyNode.child("se"); tool; tool = tool.next_sibling("se")) |
| 122 | + { |
| 123 | + for (pugi::xml_node tool1 = tool.child("w"); tool1; tool1 = tool1.next_sibling("w")) |
| 124 | + { |
| 125 | + pugi::xml_node tool2 = tool1.child("ana"); |
| 126 | + tempString = tool2.attribute("gr").value(); |
| 127 | + |
| 128 | + string outputString = tempString.substr(0, tempString.find(",")); |
| 129 | + string outputString1 = outputString.substr(0, outputString.find("=")); |
| 130 | + |
| 131 | + if (outputString1 == "") { |
| 132 | + useful.unknown++; |
| 133 | + } else if (outputString1 == "A") { |
| 134 | + Functions::a++; |
| 135 | + } else if (outputString1 == "ADV") { |
| 136 | + Functions::adv++; |
| 137 | + } else if (outputString1 == "ADVPRO") { |
| 138 | + Functions::advpro++; |
| 139 | + } else if (outputString1 == "ANUM") { |
| 140 | + Functions::anum++; |
| 141 | + } else if (outputString1 == "APRO") { |
| 142 | + Functions::apro++; |
| 143 | + } else if (outputString1 == "COM") { |
| 144 | + Functions::com++; |
| 145 | + } else if (outputString1 == "CONJ") { |
| 146 | + Functions::conj++; |
| 147 | + } else if (outputString1 == "INTJ") { |
| 148 | + Functions::intj++; |
| 149 | + } else if (outputString1 == "NUM") { |
| 150 | + Functions::num++; |
| 151 | + } else if (outputString1 == "PART") { |
| 152 | + Functions::part++; |
| 153 | + } else if (outputString1 == "PR") { |
| 154 | + Functions::pr++; |
| 155 | + } else if (outputString1 == "S") { |
| 156 | + Functions::s++; |
| 157 | + } else if (outputString1 == "SPRO") { |
| 158 | + Functions::spro++; |
| 159 | + } else if (outputString1 == "V") { |
| 160 | + Functions::v++; |
| 161 | + string diffverbs = tool2.attribute("gr").value(); |
| 162 | + |
| 163 | + if (diffverbs.find("ger") != string::npos) { |
| 164 | + Functions::ger++; |
| 165 | + } |
| 166 | + if (diffverbs.find("inf") != string::npos) { |
| 167 | + Functions::inf++; |
| 168 | + } |
| 169 | + if (diffverbs.find("partcp") != string::npos) { |
| 170 | + Functions::partcp++; |
| 171 | + } |
| 172 | + if (diffverbs.find("indic") != string::npos) { |
| 173 | + Functions::indic++; |
| 174 | + } |
| 175 | + if (diffverbs.find("imper") != string::npos) { |
| 176 | + Functions::imper++; |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +string Functions::consoleInput() |
| 184 | +{ |
| 185 | + string temp; |
| 186 | + getline(cin, temp); |
| 187 | + |
| 188 | + if (temp.empty()) { |
| 189 | + temp = ""; |
| 190 | + } |
| 191 | + |
| 192 | + return temp; |
| 193 | +} |
0 commit comments