-
Notifications
You must be signed in to change notification settings - Fork 1
/
vocabulary.cpp
52 lines (45 loc) · 1013 Bytes
/
vocabulary.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
#include "vocabulary.h"
#include <fstream>
#include <QDebug>
#include <QFile>
Vocabulary::Vocabulary()
{
myTrie = new Trie();
}
Vocabulary::~Vocabulary()
{
delete myTrie;
}
void Vocabulary::build()
{
QFile reader(":/new/prefix1/vocabulary.txt");
if (!reader.open(QIODevice::ReadOnly | QIODevice::Text))
{
assert(false);
}
QTextStream inReader(&reader);
string wordFromDictionary;
while(!inReader.atEnd())
{
QString wordTmp = inReader.readLine();
wordFromDictionary = "";
for (int i = 0; i < wordTmp.size(); ++i)
wordFromDictionary += wordTmp[i].toLatin1();
if ((int)wordFromDictionary.size() < 3)
continue;
myTrie->add(wordFromDictionary);
}
}
bool Vocabulary::add(string &word)
{
bool result = myTrie->setWord(word);
return result;
}
string Vocabulary::getRandomStartWord()
{
return myTrie->getRandomWord(Size);
}
Trie *Vocabulary::getTrie()
{
return myTrie;
}