-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
185 lines (142 loc) · 4.94 KB
/
main.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* @file main.cpp
* @author Marc S. Ressl, Albertina Galan, Alejandro Nahuel Heir
* @brief Language identification based on trigrams.
* @version 0.1
* @date 2022-03-29
*
* @copyright Copyright (c) 2022
*
* @note Se provee en resources/corpus una lista de textos de idiomas para agregar.
* El idioma Catalán ya fue incorporado. Referirse al README de esa carpeta y al
* del directorio principal.
*/
#include <iostream>
#include <map>
#include "raylib.h"
#include "LanguageManager.h"
using namespace std;
enum OPERATION_MODES
{
DETECTION,
ADD_LANGUAGE
};
int main(int, char *[])
{
map<string, string> languageCodeNames;
Languages languages;
if (!loadLanguagesData(languageCodeNames, languages))
{
cout << "Could not load trigram data." << endl;
return 1;
}
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "Lequel?");
SetTargetFPS(60);
string languageCodes[3] = {"---", "---", "---"};
int lequelMode = DETECTION;
string operationResult;
while (!WindowShouldClose())
{
if (IsKeyPressed(KEY_D))
lequelMode = DETECTION;
else if (IsKeyPressed(KEY_A))
lequelMode = ADD_LANGUAGE;
switch (lequelMode)
{
case DETECTION:
{
if (IsKeyPressed(KEY_V) &&
(IsKeyDown(KEY_LEFT_CONTROL) ||
IsKeyDown(KEY_RIGHT_CONTROL) ||
IsKeyDown(KEY_LEFT_SUPER) ||
IsKeyDown(KEY_RIGHT_SUPER)))
{
const char *clipboard = GetClipboardText();
Text text;
getText(clipboard, text);
identifyLanguage(text, languages, languageCodes);
}
if (IsFileDropped())
{
int count;
char **droppedFiles = {0};
droppedFiles = GetDroppedFiles(&count);
Text text;
getTextFromFile(droppedFiles[0], text);
identifyLanguage(text, languages, languageCodes);
ClearDroppedFiles();
}
BeginDrawing();
ClearBackground(BEIGE);
DrawText("Lequel?",
80, 80, 128, BROWN);
DrawText("Copia y pega con Ctrl+V, o arrastra un archivo...",
80, 220, 24, BROWN);
DrawText("... o presione A para agregar un idioma.",
80, 250, 24, BROWN);
string languageStrings[3];
for (int i = 0; i < 3; i++)
{
if (languageCodes[i] != "---")
{
if (languageCodeNames.find(languageCodes[i]) != languageCodeNames.end())
languageStrings[i] = languageCodeNames[languageCodes[i]];
else
languageStrings[i] = "Desconocido";
}
}
for (int i = 0; i < 3; i++)
{
int languageStringWidth = MeasureText(languageStrings[i].c_str(), 48 / (i + 1));
DrawText(languageStrings[i].c_str(), (screenWidth - languageStringWidth) / 2,
315 + 140 * i / (i + 1), 48 / (i + 1), BROWN);
}
EndDrawing();
break;
}
case ADD_LANGUAGE:
{
if (IsFileDropped())
{
int count;
char **droppedFiles = {0};
droppedFiles = GetDroppedFiles(&count);
Text text;
getTextFromFile(droppedFiles[0], text);
ClearDroppedFiles();
string languageIdentifier = text.front();
text.pop_front();
string languageName, languageCode;
if (verifyNewLanguage(languageCodeNames, languageIdentifier, languageCode,
languageName, operationResult))
{
addLanguage(text, languageCodeNames, languages, languageCode, languageName,
operationResult);
}
}
BeginDrawing();
ClearBackground(BEIGE);
DrawText("Lequel?",
80, 80, 128, BROWN);
DrawText("Arrastra un corpus en algún idioma para agregarlo:",
80, 220, 24, BROWN);
DrawText("La primera linea debe tener una identificacion del idioma:",
80, 250, 24, BROWN);
DrawText("[código del idioma (3caracteres)],[nombre del idioma]",
80, 280, 20, RED);
DrawText("Para volver al modo de detección, presione D",
80, 310, 24, BROWN);
DrawText(operationResult.data(),
80, 340, 24, BROWN);
EndDrawing();
break;
}
default:
break;
}
}
CloseWindow();
return 0;
}