26 template <
typename NodeStorageType>
29 template <
typename NodeStorageType>
32 template <
typename NodeStorageType>
53 Model<NodeStorageType>();
109 void AdjustEdge(
const NodeStorageType* payload,
long int occurrence);
176 std::vector<Edge<NodeStorageType>*>*
Edges(){
return &
edges;}
181 std::map<NodeStorageType, Node<NodeStorageType>*>*
Nodes(){
return &
nodes;}
193 std::map<NodeStorageType, Node<NodeStorageType>*>
nodes;
204 std::vector<Edge<NodeStorageType>*>
edges;
209 template <
typename NodeStorageType>
211 this->starterNode =
new Markov::Node<NodeStorageType>(0);
212 this->nodes.insert({ 0,
this->starterNode });
215 template <
typename NodeStorageType>
223 while (std::getline(*f, cell)) {
226 target = cell[cell.length() - 1];
228 oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
230 Markov::Node<NodeStorageType>* srcN;
231 Markov::Node<NodeStorageType>* targetN;
232 Markov::Edge<NodeStorageType>* e;
233 if (
this->nodes.find(src) ==
this->nodes.end()) {
234 srcN =
new Markov::Node<NodeStorageType>(src);
235 this->nodes.insert(std::pair<
char,
Markov::Node<NodeStorageType>*>(src, srcN));
239 srcN =
this->nodes.find(src)->second;
242 if (
this->nodes.find(target) ==
this->nodes.end()) {
243 targetN =
new Markov::Node<NodeStorageType>(target);
244 this->nodes.insert(std::pair<
char,
Markov::Node<NodeStorageType>*>(target, targetN));
248 targetN =
this->nodes.find(target)->second;
250 e = srcN->Link(targetN);
252 this->edges.push_back(e);
259 this->OptimizeEdgeOrder();
264 template <
typename NodeStorageType>
266 for (std::pair<
unsigned char,
Markov::Node<NodeStorageType>*>
const& x :
this->nodes) {
268 std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->
bool{
269 return lhs->EdgeWeight() > rhs->EdgeWeight();
279 template <
typename NodeStorageType>
281 std::ifstream importfile;
282 importfile.open(filename);
283 return this->Import(&importfile);
287 template <
typename NodeStorageType>
289 Markov::Edge<NodeStorageType>* e;
290 for (std::vector<
int>::size_type i = 0; i !=
this->edges.size(); i++) {
293 *f << e->LeftNode()->NodeValue() <<
"," << e->EdgeWeight() <<
"," << e->RightNode()->NodeValue() <<
"\n";
299 template <
typename NodeStorageType>
301 std::ofstream exportfile;
302 exportfile.open(filename);
303 return this->Export(&exportfile);
306 template <
typename NodeStorageType>
308 Markov::Node<NodeStorageType>* n =
this->starterNode;
310 Markov::Node<NodeStorageType>* temp_node;
312 temp_node = n->RandomNext(randomEngine);
313 if (len >= maxSetting) {
316 else if ((temp_node == NULL) && (len < minSetting)) {
320 else if (temp_node == NULL){
326 buffer[len++] = n->NodeValue();
336 template <
typename NodeStorageType>
338 NodeStorageType p = payload[0];
339 Markov::Node<NodeStorageType>* curnode =
this->starterNode;
340 Markov::Edge<NodeStorageType>* e;
345 e = curnode->FindEdge(p);
346 if (e == NULL)
return;
347 e->AdjustEdge(occurrence);
348 curnode = e->RightNode();
352 e = curnode->FindEdge(
'\xff');
353 e->AdjustEdge(occurrence);