-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindWord.cpp
More file actions
116 lines (83 loc) · 3.46 KB
/
Copy pathfindWord.cpp
File metadata and controls
116 lines (83 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <sys/time.h>
#include <regex>
static void removeAccented( std::string & str ) {
std::stringstream result;
std::regex filter("(á)+");
std::regex_replace(std::ostream_iterator<char>(result), str.begin(), str.end(), filter, "&a");
str = result.str();
std::stringstream result1;
filter = std::regex("(é)+");
std::regex_replace(std::ostream_iterator<char>(result1), str.begin(), str.end(), filter, "&e");
str = result1.str();
std::stringstream result2;
filter = std::regex("(í)+");
std::regex_replace(std::ostream_iterator<char>(result2), str.begin(), str.end(), filter, "&i");
str = result2.str();
std::stringstream result3;
filter = std::regex("(ó)+");
std::regex_replace(std::ostream_iterator<char>(result3), str.begin(), str.end(), filter, "&o");
str = result3.str();
std::stringstream result4;
filter = std::regex("(ú)+");
std::regex_replace(std::ostream_iterator<char>(result4), str.begin(), str.end(), filter, "&u");
str = result4.str();
std::stringstream result5;
filter = std::regex("(Á)+");
std::regex_replace(std::ostream_iterator<char>(result5), str.begin(), str.end(), filter, "&a");
str = result5.str();
std::stringstream result6;
filter = std::regex("(É)+");
std::regex_replace(std::ostream_iterator<char>(result6), str.begin(), str.end(), filter, "&e");
str = result6.str();
std::stringstream result7;
filter = std::regex("(Í)+");
std::regex_replace(std::ostream_iterator<char>(result7), str.begin(), str.end(), filter, "&i");
str = result7.str();
std::stringstream result8;
filter = std::regex("(Ó)+");
std::regex_replace(std::ostream_iterator<char>(result8), str.begin(), str.end(), filter, "&o");
str = result8.str();
std::stringstream result9;
filter = std::regex("(Ú)+");
std::regex_replace(std::ostream_iterator<char>(result9), str.begin(), str.end(), filter, "&u");
str = result9.str();
}
int main(int argc, char **argv) {
std::ifstream ifs("sortDic.txt");
std::vector<std::string> vec;
std::string palabra;
while (ifs >> palabra) {
vec.push_back(palabra);
}
ifs.close();
timeval actual{}, final{};
ifs.open("./textos_pruebas/Dostoievski, Fiódor (1880). Los hermanos Karamazov [14926].txt");
while (ifs >> palabra) {
// filtrar puntuacines y numeros
const std::regex filter("([^A-zÁÉÍÓÚáéíóú])+");
std::stringstream result;
std::regex_replace(std::ostream_iterator<char>(result), palabra.begin(), palabra.end(), filter, "");
palabra = result.str();
// Transformar tildes a normales
removeAccented(palabra);
// tranforma a minusculas
std::transform(palabra.begin(), palabra.end(), palabra.begin(),
[](unsigned char c) { return std::tolower(c); });
std::cout << palabra << std::endl;
// bucas palabra
/*if (palabra.length()) {
gettimeofday(&actual, nullptr);
bool found = std::binary_search(vec.begin(), vec.end(), palabra);
gettimeofday(&final, nullptr);
final.tv_sec -= actual.tv_sec;
final.tv_usec -= actual.tv_usec;
std::cout << palabra << " found: " << found << ", " << final.tv_sec << "s " << final.tv_usec << "us"
<< std::endl;
}*/
}
}