summaryrefslogtreecommitdiff
blob: e868943829b3ecfa4012ea1c012b3039cfb69dd3 (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef _ZoO_KNOWLEDGE_KNOWLEDGE_H_
#define _ZoO_KNOWLEDGE_KNOWLEDGE_H_

#include "../core/char_types.h"
#include "../core/index_types.h"

#include "../pipe/pipe_types.h"

#include "knowledge_types.h"

int ZoO_knowledge_lock_access
(
   struct ZoO_knowledge k [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

void ZoO_knowledge_unlock_access
(
   struct ZoO_knowledge k [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_initialize (struct ZoO_knowledge k [const restrict static 1]);

void ZoO_knowledge_finalize (struct ZoO_knowledge k [const restrict static 1]);

/*
 * When returning 0:
 *    {word} was added to {k}, or was already there.
 *    {*result} indicates where {word} is in {k->words}.
 *
 * When returning -1:
 *    Something went wrong when adding the occurrence of {word} to {k}.
 *    {k} remains semantically unchanged.
 *    {*result} may or may not have been altered.
 */
int ZoO_knowledge_learn_word
(
   struct ZoO_knowledge k [const static 1],
   const ZoO_char word [const restrict static 1],
   const size_t word_length,
   ZoO_index result [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

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]
);

int ZoO_knowledge_learn_markov_sequence
(
   struct ZoO_knowledge k [const restrict static 1],
   const ZoO_index sequence [const restrict static 1],
   const ZoO_index markov_order, /* Pre (> markov_order 1) */
   ZoO_index sequence_id [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_get_swt_sequences_ref
(
   const struct ZoO_knowledge k [const static 1],
   const ZoO_index initial_word,
   const ZoO_index * restrict following_sequences_ref [const restrict static 1],
   const ZoO_index * restrict following_sequences_weights [const restrict static 1],
   ZoO_index following_sequences_weights_sum [const static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_get_sequence
(
   const struct ZoO_knowledge k [const static 1],
   const ZoO_index sequences_ref,
   const ZoO_index * restrict sequence [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_get_word
(
   const struct ZoO_knowledge k [const static 1],
   const ZoO_index word_ref,
   const ZoO_char * word [const restrict static 1],
   ZoO_index word_size [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

/*
 * When returning 0:
 *    {word} is in {k}.
 *    {word} is located at {k->words[*result]}.
 *
 * When returning -1:
 *    {word} is not in {k}.
 *    {*result} is where {word} was expected to be found in
 *    {k->sorted_indices}.
 */
int ZoO_knowledge_find_word_id
(
   const struct ZoO_knowledge k [const restrict static 1],
   const ZoO_char word [const restrict static 1],
   const size_t word_size,
   ZoO_index result [const restrict static 1]
);

int ZoO_knowledge_find_tws_targets
(
   const struct ZoO_knowledge k [const static 1],
   const ZoO_index sequence [const restrict],
   const ZoO_index markov_order,
   const ZoO_index * restrict targets [const restrict static 1],
   const ZoO_index * restrict targets_weights [const restrict static 1],
   ZoO_index targets_weights_sum [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_find_swt_targets
(
   const struct ZoO_knowledge k [const static 1],
   const ZoO_index sequence [const restrict],
   const size_t sequence_length,
   const ZoO_index markov_order,
   const ZoO_index * restrict targets [const restrict static 1],
   const ZoO_index * restrict targets_weights [const restrict static 1],
   ZoO_index targets_weights_sum [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_strengthen_swt
(
   struct ZoO_knowledge k [const restrict static 1],
   const ZoO_index sequence_id,
   const ZoO_index word_id,
   const ZoO_index target_id,
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_strengthen_tws
(
   struct ZoO_knowledge k [const restrict static 1],
   const ZoO_index target_id,
   const ZoO_index word_id,
   const ZoO_index sequence_id,
   const struct ZoO_pipe io [const restrict static 1]
);

/*
 * TODO
 */
/*
int ZoO_knowledge_weaken_swt
(
   struct ZoO_knowledge k [const restrict static 1],
   const ZoO_index sequence_id,
   const ZoO_index word_id,
   const ZoO_index target_id,
   const struct ZoO_pipe io [const restrict static 1]
);

int ZoO_knowledge_weaken_tws
(
   struct ZoO_knowledge k [const restrict static 1],
   const ZoO_index target_id,
   const ZoO_index word_id,
   const ZoO_index sequence_id,
   const struct ZoO_pipe io [const restrict static 1]
);
*/
#endif