bugfix
This commit is contained in:
parent
744d0f7a3a
commit
fdae90ad9f
4 changed files with 8 additions and 4 deletions
|
@ -46,7 +46,7 @@ int Dictionary::spit(path p) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int a = 0; a < 25; a++) {
|
for (int a = 0; a < MAXLEN; a++) {
|
||||||
for (auto &word : words[a]) {
|
for (auto &word : words[a]) {
|
||||||
std::vector<std::string> trias = get_trigrams(word.get_word());
|
std::vector<std::string> trias = get_trigrams(word.get_word());
|
||||||
file << word << " " << trias.size();
|
file << word << " " << trias.size();
|
||||||
|
@ -74,6 +74,8 @@ int Dictionary::slurp(path p) {
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
|
if (line.size() > MAXLEN)
|
||||||
|
continue;
|
||||||
words[line.size()].push_back(Word(line, get_trigrams(line)));
|
words[line.size()].push_back(Word(line, get_trigrams(line)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define MAXLEN 30
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::filesystem::path;
|
using std::filesystem::path;
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ class Dictionary {
|
||||||
int spit(path p);
|
int spit(path p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<Word> words[25];
|
vector<Word> words[MAXLEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,7 +31,7 @@ int main() {
|
||||||
Dictionary dict;
|
Dictionary dict;
|
||||||
string word;
|
string word;
|
||||||
dict.slurp(std::filesystem::path("/usr/share/dict/words"));
|
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) {
|
// while (cin >> word) {
|
||||||
// transform(word.begin(), word.end(), word.begin(), ::tolower);
|
// transform(word.begin(), word.end(), word.begin(), ::tolower);
|
||||||
|
|
|
@ -20,6 +20,6 @@ class Word {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string word;
|
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);
|
friend std::ostream &operator<<(std::ostream &out, const Word &o);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue