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
|
#include "uscxml/util/Trie.h"
#include <iostream>
#include <assert.h>
using namespace uscxml;
int main(int argc, char** argv) {
{
Trie trie;
int nrTokens = 0;
size_t offset = 0;
std::string word = "this is to be tokenized";
std::string token;
while((offset = trie.getNextToken(word, offset, token)) != std::string::npos) {
std::cout << "\"" << token << "\" ";
nrTokens++;
}
std::cout << std::endl;
assert(nrTokens == word.length());
}
{
Trie trie(" ");
int nrTokens = 0;
size_t offset = 0;
std::string word = "this is to be tokenized";
std::string token;
while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
std::cout << "\"" << token << "\" ";
nrTokens++;
}
std::cout << std::endl;
assert(nrTokens == 5);
}
{
Trie trie("#");
int nrTokens = 0;
size_t offset = 0;
std::string word = "#bb#bbbb#b#bbb#bb#b#";
std::string token;
while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
std::cout << "\"" << token << "\" ";
nrTokens++;
}
std::cout << std::endl;
assert(nrTokens == 6);
}
{
Trie trie(" ");
int nrTokens = 0;
size_t offset = 0;
std::string word = " this is to be tokenized";
std::string token;
while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
std::cout << "\"" << token << "\" ";
nrTokens++;
}
std::cout << std::endl;
assert(nrTokens == 3);
}
{
Trie trie("");
trie.addWord("a");
trie.addWord("b");
trie.dump();
}
{
Trie trie(".");
trie.addWord("foo.bar");
trie.addWord("foo.foo");
trie.addWord("foo.foo.baz");
trie.addWord("foz.foo.baz");
trie.addWord("foz.foo");
trie.dump();
std::list<TrieNode*> childs;
childs = trie.getChildsWithWords(trie.root);
assert(childs.size() == 5);
assert(trie.getNodeWithPrefix("") == trie.root);
childs = trie.getWordsWithPrefix("");
assert(childs.size() == 5);
}
}
|