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
93
|
#include <stdlib.h>
#include <string.h>
#include <stdint.h> /* defines SIZE_MAX */
#include "../sequence/sequence.h"
#include "../pipe/pipe.h"
#include "knowledge.h"
/******************************************************************************/
/** LEARN FOLLOWING SEQUENCE **************************************************/
/******************************************************************************/
static int add_following_sequence
(
struct ZoO_knowledge k [const restrict static 1],
const ZoO_index sequence [const restrict static 1],
const size_t index,
const size_t sequence_length,
const ZoO_index markov_order,
const struct ZoO_pipe io [const restrict static 1]
)
{
/* TODO */
return -1;
}
/******************************************************************************/
/** LEARN PRECEDING SEQUENCE **************************************************/
/******************************************************************************/
static int add_preceding_sequence
(
struct ZoO_knowledge k [const restrict static 1],
const ZoO_index sequence [const restrict static 1],
const size_t index,
const size_t sequence_length,
const ZoO_index markov_order,
const struct ZoO_pipe io [const restrict static 1]
)
{
/* TODO */
return -1;
}
/******************************************************************************/
/** EXPORTED ******************************************************************/
/******************************************************************************/
int ZoO_knowledge_learn_sequence
(
struct ZoO_knowledge k [const restrict static 1],
const ZoO_index sequence [const restrict static 1],
const size_t sequence_length,
const ZoO_index markov_order,
const struct ZoO_pipe io [const restrict static 1]
)
{
ZoO_index * buffer;
size_t i;
const ZoO_index buffer_length = (markov_order - 1);
for (i = 0; i < sequence_length; ++i)
{
k->words[sequence[i]].occurrences += 1;
add_preceding_sequence
(
k,
sequence,
i,
sequence_length,
buffer_length,
io
);
add_following_sequence
(
k,
sequence,
i,
sequence_length,
markov_order,
io
);
/*
* TODO: in case of failure, undo part of the word done so far: instead
* of unlearning, just remove the occurrence count of sequences and
* words so that {k} remains coherent.
*/
}
return 0;
}
|