Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

lab6 / badWordsDetector

.cpp
Скачиваний:
5
Добавлен:
05.02.2020
Размер:
1.27 Кб
Скачать
#include "Aho_Corasick.h"

#include <iostream>
#include <string>
#include <set>
#include <experimental/filesystem>
#include <fstream>

using namespace std;
using namespace std::experimental::filesystem;

int main(int argc, char const *argv[]) {
	locale::global(locale(""));

	if (argc <1) {
		wcout << L"Too few arguments. Try again." << endl;
		return 0;
	}
		wifstream fileWithBadWords(argv[1]);

		set<wstring> badWords;

		while(!fileWithBadWords.eof()) {
			wstring newBadWord;

			getline(fileWithBadWords, newBadWord, (wchar_t)'\n');
			badWords.emplace(newBadWord);
		}

		Trie trie(badWords);

		path myPath(".");

		for(auto& fileOrFolder: directory_iterator(myPath)) {
			if (!is_directory(fileOrFolder)) {
				wifstream file(fileOrFolder.path().filename());

				wstring content;

				getline(file, content, (wchar_t)file.eof());

				map<wstring, set<lli>> solutions = AhoCorasick(content, trie);

				if (!solutions.empty()) {
					wcout << fileOrFolder.path().filename() << endl;

					for(auto &solution:solutions) {
						wcout << L"{ " << solution.first << L":";
					
						for(auto &patternIndex: solution.second) {
							wcout << patternIndex << L" ";
						}

						wcout << L"}" << endl;
					}

					wcout << endl;
				}
			}
		}

	return 0;
}
Соседние файлы в папке lab6