Skip to content

Commit

Permalink
next attempt to fix Cython stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Dec 11, 2024
1 parent 2b22978 commit 1c657b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
54 changes: 27 additions & 27 deletions colibricore_classes.in.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ cdef extern from "patternstore.h":
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 operator[](IndexReference&) except +KeyError nogil
int sentencelength(int) nogil
int sentences() nogil
Pattern getsentence(int) nogil except +KeyError #PatternPointer in reality
Pattern getsentence(int) except +KeyError nogil #PatternPointer in reality

cdef cppclass AlignedPatternMap[ValueType, ValueHandler, NestedSizeType]:
cppclass iterator:
Expand Down Expand Up @@ -292,24 +292,24 @@ cdef extern from "patternstore.h":

cdef extern from "classdecoder.h":
cdef cppclass ClassDecoder:
ClassDecoder() nogil except +
ClassDecoder(string&) nogil except +
ClassDecoder() except + nogil
ClassDecoder(string&) except + nogil
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 +
ClassEncoder(int minlength=0, int maxlength=0) except + nogil
ClassEncoder(string, int minlength=0, int maxlength=0) except + nogil
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 +
Pattern buildpattern(string&, bool allowunknown, bool autoaddunknown) except + nogil

cdef extern from "patternmodel.h":
cdef cppclass PatternModelOptions:
Expand Down Expand Up @@ -374,8 +374,8 @@ cdef extern from "patternmodel.h":

void insert(Pattern&) nogil

void load(string, PatternModelOptions) nogil except +IOError
void write(string) nogil except +IOError
void load(string, PatternModelOptions) except +IOError nogil
void write(string) except +IOError nogil

cdef cppclass PatternModel[ValueType,ValueHandler,MapType]:
cppclass iterator:
Expand Down Expand Up @@ -416,15 +416,15 @@ cdef extern from "patternmodel.h":
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 load(string, PatternModelOptions, PatternModelInterface*) except +IOError nogil
void write(string) except +IOError nogil
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
void histogram(ostream) nogil
unsigned int topthreshold(int,int,int) nogil
void outputrelations(Pattern&,ClassDecoder&, ostream*)
void outputrelations(Pattern&,ClassDecoder&, ostream)



Expand Down Expand Up @@ -484,15 +484,15 @@ cdef extern from "patternmodel.h":
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 load(string, PatternModelOptions, PatternModelInterface* ) except +IOError nogil
void write(string) except +IOError nogil
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 outputrelations(Pattern&,ClassDecoder&, ostream)

void add(Pattern&, IndexedData*, IndexReference&)

Expand Down Expand Up @@ -548,8 +548,8 @@ cdef extern from "alignmodel.h":
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil

void load(string&, PatternModelOptions) nogil except +IOError
void write(string&) nogil except +IOError
void load(string&, PatternModelOptions) except +IOError nogil
void write(string&) except +IOError nogil

cdef cppclass BasicPatternAlignmentModel:
cppclass iterator:
Expand Down Expand Up @@ -582,5 +582,5 @@ cdef extern from "alignmodel.h":
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil

void load(string&, PatternModelOptions) nogil except +IOError
void write(string&) nogil except +IOError
void load(string&, PatternModelOptions) except +IOError nogil
void write(string&) except +IOError nogil
2 changes: 1 addition & 1 deletion colibricore_indexedpatternmodel.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ cpdef outputrelations(self, Pattern pattern, ClassDecoder decoder):
:param decoder: The class decoder
:type decoder: ClassDecoder
"""
self.data.outputrelations(pattern.cpattern,decoder.data,&cout)
self.data.outputrelations(pattern.cpattern,decoder.data,cout)


def getsubchildren(self, Pattern pattern, int occurrencethreshold = 0, int category = 0, int size = 0):
Expand Down
7 changes: 3 additions & 4 deletions colibricore_patternmodel.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ cpdef printmodel(self,ClassDecoder decoder):
:param decoder: The class decoder
:type decoder: ClassDecoder
"""
self.data.printmodel(&cout, decoder.data )
self.data.printmodel(cout, decoder.data )

cpdef train(self, str filename, PatternModelOptions options, constrainmodel = None):
"""Train the patternmodel on the specified corpus data (a *.colibri.dat file)
Expand Down Expand Up @@ -349,11 +349,11 @@ cpdef trainconstrainedbyalignmodel(self, str filename, PatternModelOptions optio

cpdef report(self):
"""Print a detailed statistical report to stdout"""
self.data.report(&cout)
self.data.report(cout)

cpdef printhistogram(self):
"""Print a histogram to stdout"""
self.data.histogram(&cout)
self.data.histogram(cout)



Expand Down Expand Up @@ -459,4 +459,3 @@ def getinstance(self, tuple pos, Pattern pattern):
if self.data.reverseindex == NULL:
raise ValueError("No reverse index loaded")
return self.corpus.getinstance(pos, pattern)

0 comments on commit 1c657b3

Please sign in to comment.