Skip to content

Commit

Permalink
Updatet API using 'stream&' instead of 'stream *', also more referenc…
Browse files Browse the repository at this point in the history
…es and const parameters.

Cherry picked all stuff from the 'efficient' branch
  • Loading branch information
kosloot committed Jul 4, 2023
1 parent 4d28346 commit 8e869d3
Show file tree
Hide file tree
Showing 11 changed files with 901 additions and 944 deletions.
50 changes: 25 additions & 25 deletions colibricore_classes.in.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ cdef extern from "patternstore.h":
ValueType& operator[](Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
void read(const string& filename) nogil
void write(const string& filename) nogil

cdef cppclass HashOrderedPatternMap[ValueType,ValueHandler,ReadWriteSizeType]:
cppclass iterator:
Expand All @@ -202,8 +202,8 @@ cdef extern from "patternstore.h":
ValueType& operator[](Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
void read(const string& filename) nogil
void write(const string& filename) nogil

cdef cppclass PatternSet[ReadWriteSizeType]:
cppclass iterator:
Expand All @@ -219,8 +219,8 @@ cdef extern from "patternstore.h":
bool has(Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
void read(const string& filename) nogil
void write(const string& filename) nogil

cdef cppclass HashOrderedPatternSet[ReadWriteSizeType]:
cppclass iterator:
Expand All @@ -236,8 +236,8 @@ cdef extern from "patternstore.h":
bool has(Pattern&) nogil
iterator erase(Pattern&) nogil
iterator find(Pattern&) nogil
void read(string filename) nogil
void write(string filename) nogil
void read(const string& filename) nogil
void write(const string& filename) nogil

ctypedef pair[IndexReference,PatternPointer] IndexPattern

Expand Down Expand Up @@ -279,8 +279,8 @@ cdef extern from "patternstore.h":
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
void read(const string& filename) nogil
void write(const string& filename) nogil



Expand All @@ -304,10 +304,10 @@ cdef extern from "classencoder.h":
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 processcorpus(const 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 build(const string& filename,int threshold=0) nogil #build a class from this dataset
void encodefile(const 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 +

Expand Down Expand Up @@ -401,7 +401,7 @@ cdef extern from "patternmodel.h":
IndexedCorpus * reverseindex

PatternModelInterface * getinterface() nogil
void train(string filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train( const string& filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train(istream*, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)

unsigned int totaloccurrencesingroup(int category, int n)
Expand All @@ -418,13 +418,13 @@ cdef extern from "patternmodel.h":
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 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 @@ -466,7 +466,7 @@ cdef extern from "patternmodel.h":
float frequency(Pattern&) nogil

PatternModelInterface * getinterface() nogil
void train(string filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train( const string& filename, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)
void train(istream*, PatternModelOptions options, PatternModelInterface *, PatternSet[uint] *)

IndexedCorpus * reverseindex
Expand All @@ -486,13 +486,13 @@ cdef extern from "patternmodel.h":
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 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
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)

Loading

0 comments on commit 8e869d3

Please sign in to comment.