This commit is contained in:
Imbus 2024-11-20 19:11:48 +01:00
parent 744d0f7a3a
commit fdae90ad9f
4 changed files with 8 additions and 4 deletions

View file

@ -46,7 +46,7 @@ int Dictionary::spit(path p) {
return 1;
}
for (int a = 0; a < 25; a++) {
for (int a = 0; a < MAXLEN; a++) {
for (auto &word : words[a]) {
std::vector<std::string> trias = get_trigrams(word.get_word());
file << word << " " << trias.size();
@ -74,6 +74,8 @@ int Dictionary::slurp(path p) {
std::string line;
while (std::getline(file, line)) {
if (line.size() > MAXLEN)
continue;
words[line.size()].push_back(Word(line, get_trigrams(line)));
}

View file

@ -6,6 +6,8 @@
#include <string>
#include <vector>
#define MAXLEN 30
using std::vector;
using std::filesystem::path;
@ -18,7 +20,7 @@ class Dictionary {
int spit(path p);
private:
vector<Word> words[25];
vector<Word> words[MAXLEN];
};
#endif

View file

@ -31,7 +31,7 @@ int main() {
Dictionary dict;
string word;
dict.slurp(std::filesystem::path("/usr/share/dict/words"));
// dict.spit(std::filesystem::path("words.txt"));
dict.spit(std::filesystem::path("words.txt"));
// while (cin >> word) {
// transform(word.begin(), word.end(), word.begin(), ::tolower);

View file

@ -20,6 +20,6 @@ class Word {
private:
const std::string word;
const std::vector<std::string> triagrams;
std::vector<std::string> triagrams;
friend std::ostream &operator<<(std::ostream &out, const Word &o);
};