-
Notifications
You must be signed in to change notification settings - Fork 20
/
colibricore_classes.in.pxd
586 lines (506 loc) · 23.1 KB
/
colibricore_classes.in.pxd
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#*****************************
# Colibri Core
# by Maarten van Gompel
# Centre for Language Studies
# Radboud University Nijmegen
#
# http://proycon.github.io/colibri-core
#
# Licensed under GPLv3
#****************************/
from libcpp.string cimport string
from libcpp.set cimport set as stdset
from libcpp.map cimport map as stdmap
from libcpp.vector cimport vector
from libcpp cimport bool
from unordered_map cimport unordered_map
from unordered_set cimport unordered_set
from libcpp.utility cimport pair
from libc.stdint cimport *
cdef extern from "<iostream>" namespace "std":
cdef cppclass ostream:
pass
cdef cppclass istream:
pass
extern ostream cout
cdef extern from "pattern.h":
cdef cppclass PatternPointer #forward declaration
cdef cppclass Pattern:
unsigned char * data
Pattern() nogil
Pattern(Pattern&, long unsigned int,long unsigned int) nogil
Pattern(Pattern&) nogil
#Pattern(PatternPointer&) nogil
#Pattern(PatternPointer&, int,int) nogil
string tostring(ClassDecoder&) nogil
unsigned int n() nogil
unsigned int bytesize() nogil
int skipcount() nogil
int category() nogil
int hash() nogil
bint operator==(Pattern&) nogil
bint operator==(PatternPointer&) nogil
bint operator<(Pattern&) nogil
bint operator>(Pattern&) nogil
Pattern operator+(Pattern&) nogil
int ngrams(vector[Pattern]& container,int n)
int parts(vector[Pattern]& container) nogil
int gaps(vector[pair[int,int]]& container) nogil
int subngrams(vector[Pattern]& container,int minn=0,int maxn=9)
bool contains(Pattern&) nogil
Pattern toflexgram() nogil
vector[unsigned int] tovector() nogil
void set(unsigned char *,int ) nogil
bool isgap(int) nogil
bool isskipgram() nogil
bool isflexgram() nogil
bool unknown() nogil
Pattern reverse() nogil
PatternPointer getpointer() nogil
bool instanceof(PatternPointer) nogil
Pattern patternfromfile(const string&)
cdef cppclass PatternPointer:
PatternPointer() nogil
PatternPointer(Pattern&, long unsigned int,long unsigned int) nogil
PatternPointer(Pattern&) nogil
PatternPointer(PatternPointer&, long unsigned int,long unsigned int) nogil
PatternPointer(PatternPointer&) nogil
Pattern pattern() nogil
string tostring(ClassDecoder&) nogil
long unsigned int n() nogil
long unsigned int bytesize() nogil
int skipcount() nogil
int category() nogil
int hash() nogil
bint operator==(PatternPointer&) nogil
bint operator==(Pattern&) nogil
int ngrams(vector[PatternPointer]& container,int n)
int parts(vector[PatternPointer]& container) nogil
int gaps(vector[pair[int,int]]& container) nogil
int subngrams(vector[PatternPointer]& container,int minn=0,int maxn=9)
PatternPointer toflexgram() nogil
vector[unsigned int] tovector() nogil
void set(unsigned char *,int ) nogil
bool isgap(int) nogil
bool isskipgram() nogil
bool isflexgram() nogil
bool unknown() nogil
PatternPointer reverse() nogil
bool instanceof(PatternPointer) nogil
cdef extern from "datatypes.h":
cdef cppclass IndexReference:
IndexReference()
IndexReference(int,int)
uint32_t sentence
uint16_t token
cdef cppclass BaseValueHandler[T]:
unsigned int count(T &)
int add(T *, IndexReference&)
str tostring(T&)
cdef cppclass IndexedData:
cppclass iterator:
IndexReference& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
bool has(IndexReference& ref)
cdef cppclass PatternFeatureVector[T]:
vector[T] data
Pattern pattern
cppclass iterator:
T& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
T get(int) nogil
void clear() nogil
void push_back(T) nogil
cdef cppclass PatternFeatureVectorMap[T]:
PatternFeatureVectorMap() nogil
cppclass iterator:
PatternFeatureVector[T] * operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
bool has(Pattern&) nogil
iterator find(Pattern&) nogil
void insert(PatternFeatureVector&)
PatternFeatureVector[T] * getdata(Pattern&) nogil
cdef cppclass PatternVector:
vector[Pattern] data
cppclass iterator:
Pattern& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
bool has(Pattern&) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
Pattern get(int) nogil
void clear() nogil
void insert(Pattern&) nogil
cdef extern from "patternstore.h":
cdef cppclass PatternMap[ValueType,ValueHandler,ReadWriteSizeType]:
cppclass iterator:
pair[Pattern,ValueType] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
PatternMap() nogil
void insert(Pattern&, ValueType& value) nogil
bool has(Pattern&) nogil
ValueType& operator[](Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
cdef cppclass HashOrderedPatternMap[ValueType,ValueHandler,ReadWriteSizeType]:
cppclass iterator:
pair[Pattern,ValueType] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
HashOrderedPatternMap() nogil
void insert(Pattern&, ValueType& value) nogil
bool has(Pattern&) nogil
ValueType& operator[](Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
cdef cppclass PatternSet[ReadWriteSizeType]:
cppclass iterator:
Pattern& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
PatternSet() nogil
void insert(Pattern&) nogil
bool has(Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
cdef cppclass HashOrderedPatternSet[ReadWriteSizeType]:
cppclass iterator:
Pattern& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
HashOrderedPatternSet() nogil
void insert(Pattern&) nogil
bool has(Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
ctypedef pair[IndexReference,PatternPointer] IndexPattern
cdef cppclass IndexedCorpus:
cppclass iterator:
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
PatternPointer patternpointer() nogil
Pattern pattern() nogil #actually returns a patternpointer too but can be converted this way
IndexReference index() nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
IndexedCorpus() nogil
void load(string, bool) nogil
bool has(IndexReference&) nogil
Pattern getpattern(IndexReference&,int) except +KeyError #PatternPointer in reality
vector[pair[IndexReference,PatternPointer]] findpattern(Pattern,int sentence,bool instantiate) nogil #high level
PatternPointer getinstance(IndexReference begin, PatternPointer pattern) nogil #low level (alias for findpattern), returns ngrams since outputcategory uses default parameter NGRAM in C++ code
int operator[](IndexReference&) nogil except +KeyError
int sentencelength(int) nogil
int sentences() nogil
Pattern getsentence(int) nogil except +KeyError #PatternPointer in reality
cdef cppclass AlignedPatternMap[ValueType, ValueHandler, NestedSizeType]:
cppclass iterator:
pair[Pattern,PatternMap[ValueType,ValueHandler,NestedSizeType]]& operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
size_t size() nogil
iterator begin() nogil
iterator end() nogil
AlignedPatternMap() nogil
void insert(Pattern&, PatternMap[ValueType,ValueHandler,NestedSizeType]& value) nogil
bool has(Pattern&) nogil
PatternMap[ValueType,ValueHandler,NestedSizeType]& operator[](Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
extern Pattern SKIPPATTERN
extern Pattern FLEXPATTERN
extern Pattern UNKPATTERN
extern Pattern BOUNDARYPATTERN
cdef extern from "classdecoder.h":
cdef cppclass ClassDecoder:
ClassDecoder() nogil except +
ClassDecoder(string&) nogil except +
void load(string&) nogil
int size() nogil
string decodefiletostring(string&, int begin = 0, int end = 0, bool quiet = False) nogil
cdef extern from "classencoder.h":
cdef cppclass ClassEncoder:
ClassEncoder(int minlength=0, int maxlength=0) nogil except +
ClassEncoder(string, int minlength=0, int maxlength=0) nogil except +
void load(string, int minlength, int maxlength) nogil
int size() nogil
void processcorpus(string filename, unordered_map[string,unsigned int]) nogil
void buildclasses(unordered_map[string,unsigned int] & , int threshold=0) nogil
void build(string& filename,int threshold=0) nogil #build a class from this dataset
void encodefile(string&, string&, bool allowunknown, bool autoaddunknown, bool append,bool ignorenewlines, bool quiet) nogil
void save(string&)
Pattern buildpattern(string&, bool allowunknown, bool autoaddunknown) nogil except +
cdef extern from "patternmodel.h":
cdef cppclass PatternModelOptions:
int MINTOKENS
int MINTOKENS_UNIGRAMS
int MINTOKENS_SKIPGRAMS
int MINLENGTH
int MAXLENGTH
bool DOSKIPGRAMS
bool DOSKIPGRAMS_EXHAUSTIVE
int MINSKIPTYPES
int MAXSKIPS
bool DOREVERSEINDEX
bool DEBUG
bool QUIET
bool DOPATTERNPERLINE
bool DOREMOVENGRAMS
bool DOREMOVESKIPGRAMS
bool DOREMOVEFLEXGRAMS
bool DORESET
int PRUNENONSUBSUMED
int PRUNESUBSUMED
cdef cppclass IndexedDataHandler:
unsigned int count(IndexedData &)
int add(IndexedData *, IndexReference&)
str tostring(IndexedData&)
cdef cppclass PatternModelInterface:
int getmodeltype()
int getmodelversion()
bool has(const Pattern &)
size_t size()
unsigned int occurrencecount(Pattern & pattern)
double frequency(Pattern &)
int maxlength()
int minlength()
unsigned int types()
unsigned int tokens()
@include colibricore_relationmap.pxi
cdef cppclass PatternSetModel:
cppclass iterator:
Pattern & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
iterator begin() nogil
iterator end() nogil
bool has(Pattern&) nogil
unsigned int size() nogil
unsigned int occurrencecount(Pattern&) nogil #always returns 0
float frequency(Pattern&) nogil
PatternModelInterface * getinterface() nogil
void insert(Pattern&) nogil
void load(string, PatternModelOptions) nogil except +IOError
void write(string) nogil except +IOError
cdef cppclass PatternModel[ValueType,ValueHandler,MapType]:
cppclass iterator:
pair[Pattern,ValueType] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
iterator begin() nogil
iterator end() nogil
PatternModel() nogil
unsigned int types() nogil
unsigned int tokens() nogil
int type() nogil
int version() nogil
int maxlength() nogil
int minlength() nogil
unsigned int occurrencecount(Pattern&) nogil
unsigned int coveragecount(Pattern&) nogil
float coverage(Pattern&) nogil
float frequency(Pattern&) nogil
void add(Pattern&, ValueType*, IndexReference&)
IndexedCorpus * reverseindex
PatternModelInterface * getinterface() nogil
void train(string filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train(istream*, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
unsigned int totaloccurrencesingroup(int category, int n)
unsigned int totalpatternsingroup(int category, int n)
unsigned int totaltokensingroup(int category, int n)
unsigned int totalwordtypesingroup(int category, int n)
void insert(Pattern&, ValueType& value) nogil
bool has(Pattern&) nogil
unsigned int size() nogil
ValueType& operator[](Pattern&) nogil
bool erase(Pattern&) nogil
unsigned int prune(int threshold, int n) nogil
iterator find(Pattern&) nogil
void load(string, PatternModelOptions, PatternModelInterface*) nogil except +IOError
void write(string) nogil except +IOError
void printmodel(ostream*, ClassDecoder&) nogil
void printpattern(ostream*, ClassDecoder&, Pattern&,bool instantiate=false,bool eol=true) nogil
void report(ostream*) nogil
void histogram(stdmap[unsigned int,unsigned int] & hist, unsigned int threshold, unsigned int cap,int,unsigned int)
void histogram(ostream*) nogil
unsigned int topthreshold(int,int,int) nogil
void outputrelations(Pattern&,ClassDecoder&, ostream*)
t_relationmap getsubchildren(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getsubparents(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getleftneighbours(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size, unsigned int cutoff) except +KeyError
t_relationmap getrightneighbours(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size, unsigned int cutoff) except +KeyError
t_relationmap getskipcontent(Pattern & pattern) except +KeyError
t_relationmap gettemplates(Pattern & pattern, unsigned int occurrencethreshold) except +KeyError
t_relationmap getinstances(Pattern & pattern, unsigned int occurrencethreshold) except +KeyError
t_relationmap getcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getleftcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getrightcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
unordered_set[PatternPointer] getreverseindex(IndexReference&)
vector[pair[IndexReference,PatternPointer]] getreverseindex_bysentence(int)
Pattern getinstance(IndexReference & begin, const Pattern & pattern) except +KeyError
cdef cppclass IndexedPatternModel[MapType]:
cppclass iterator:
pair[Pattern,IndexedData] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
iterator begin() nogil
iterator end() nogil
PatternModel() nogil
unsigned int types() nogil
unsigned int tokens() nogil
int type() nogil
int version() nogil
int maxlength() nogil
int minlength() nogil
unsigned int occurrencecount(Pattern&) nogil
unsigned int coveragecount(Pattern&) nogil
float coverage(Pattern&) nogil
float frequency(Pattern&) nogil
PatternModelInterface * getinterface() nogil
void train(string filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train(istream*, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
IndexedCorpus * reverseindex
bool externalreverseindex
unsigned int totaloccurrencesingroup(int category, int n)
unsigned int totalpatternsingroup(int category, int n)
unsigned int totaltokensingroup(int category, int n)
unsigned int totalwordtypesingroup(int category, int n)
void insert(Pattern&, IndexedData& value) nogil
bool has(Pattern&) nogil
unsigned int size() nogil
IndexedData& operator[](Pattern&) nogil
bool erase(Pattern&) nogil
unsigned int prune(int threshold, int n) nogil
iterator find(Pattern&) nogil
void load(string, PatternModelOptions, PatternModelInterface* ) nogil except +IOError
void write(string) nogil except +IOError
void printmodel(ostream*, ClassDecoder&) nogil
void printpattern(ostream*, ClassDecoder&, Pattern&,bool instantiate=false,bool eol=true) nogil
void report(ostream*) nogil
void histogram(ostream*) nogil
void histogram(stdmap[unsigned int,unsigned int] & hist, unsigned int threshold , unsigned int cap,int,unsigned int )
unsigned int topthreshold(int,int,int) nogil
void outputrelations(Pattern&,ClassDecoder&, ostream*)
void add(Pattern&, IndexedData*, IndexReference&)
unordered_set[PatternPointer] getreverseindex(IndexReference&)
vector[pair[IndexReference,PatternPointer]] getreverseindex_bysentence(int)
int computeflexgrams_fromskipgrams() nogil
int computeflexgrams_fromcooc(double) nogil
t_relationmap getsubchildren(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getsubparents(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getleftneighbours(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size, unsigned int cutoff) except +KeyError
t_relationmap getrightneighbours(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size, unsigned int cutoff) except +KeyError
t_relationmap getskipcontent(Pattern & pattern) except +KeyError
t_relationmap gettemplates(Pattern & pattern, unsigned int occurrencethreshold) except +KeyError
t_relationmap getinstances(Pattern & pattern, unsigned int occurrencethreshold) except +KeyError
t_relationmap getcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getleftcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
t_relationmap getrightcooc(Pattern & pattern, unsigned int occurrencethreshold, int category, unsigned int size) except +KeyError
Pattern getinstance(IndexReference & begin, const Pattern & pattern) except +KeyError
cdef extern from "alignmodel.h":
cdef cppclass PatternAlignmentModel[FeatureType]:
cppclass iterator:
pair[Pattern,PatternFeatureVectorMap[FeatureType]] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
iterator begin() nogil
iterator end() nogil
PatternAlignmentModel() nogil
unsigned int types() nogil
unsigned int tokens() nogil
int getmodeltype()
int getmodelversion()
int maxlength() nogil
int minlength() nogil
void add(Pattern&, Pattern&, vector[FeatureType]&)
PatternModelInterface * getinterface() nogil
void insert(Pattern&, PatternFeatureVectorMap[FeatureType]& value) nogil
bool has(Pattern&) nogil
bool has(Pattern&, Pattern&) nogil
unsigned int size() nogil
PatternFeatureVectorMap[FeatureType]& operator[](Pattern&) nogil
PatternFeatureVectorMap[FeatureType]* getdata(Pattern&, bool makeifnew=False) nogil
PatternFeatureVector[FeatureType]* getfeaturevector(Pattern&, Pattern&, bool makeifnew=False) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void load(string&, PatternModelOptions) nogil except +IOError
void write(string&) nogil except +IOError
cdef cppclass BasicPatternAlignmentModel:
cppclass iterator:
pair[Pattern,PatternVector] & operator*() nogil
iterator operator++() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
iterator begin() nogil
iterator end() nogil
BasicPatternAlignmentModel() nogil
unsigned int types() nogil
unsigned int tokens() nogil
int getmodeltype()
int getmodelversion()
int maxlength() nogil
int minlength() nogil
void add(Pattern&, Pattern&)
PatternModelInterface * getinterface() nogil
void insert(Pattern&, PatternVector& value) nogil
bool has(Pattern&) nogil
bool has(Pattern&, Pattern&) nogil
unsigned int size() nogil
PatternVector& operator[](Pattern&) nogil
PatternVector* getdata(Pattern&, bool makeifnew=False) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void load(string&, PatternModelOptions) nogil except +IOError
void write(string&) nogil except +IOError