Skip to content

Commit

Permalink
Update callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhouyang committed May 20, 2021
1 parent 7793446 commit 3bd3b2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autophrasex/autophrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def mine(self,
callback = CallbackWrapper(callbacks=callbacks)
callback.begin()

callback.on_read_corpus_begin()
self.corpus_reader.read(
corpus_files=corpus_files,
extractor=self.extractor_wrapper,
N=N,
verbose=kwargs.get('verbose', True),
logsteps=kwargs.get('logsteps', 1000))
callback.on_read_corpus_end()

callback.on_build_quality_phrases_begin(quality_phrase_files)
quality_phrases = load_quality_phrase_files(quality_phrase_files)
Expand Down
20 changes: 20 additions & 0 deletions autophrasex/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class Callback(abc.ABC):
def begin(self):
pass

def on_read_corpus_begin(self):
pass

def on_read_corpus_end(self):
pass

def on_build_quality_phrases_begin(self, quality_file):
pass

Expand Down Expand Up @@ -63,6 +69,14 @@ def begin(self):
for cb in self.callbacks:
cb.begin()

def on_read_corpus_begin(self):
for cb in self.callbacks:
cb.on_read_corpus_begin()

def on_read_corpus_end(self):
for cb in self.callbacks:
cb.on_read_corpus_end()

def on_build_quality_phrases_begin(self, quality_file):
for cb in self.callbacks:
cb.on_build_quality_phrases_begin(quality_file)
Expand Down Expand Up @@ -129,6 +143,12 @@ class LoggingCallback(Callback):
def begin(self):
logging.info('Starting to mining phrases...')

def on_read_corpus_begin(self):
logging.info('Starting to read corpus...')

def on_read_corpus_end(self):
logging.info('Finished to read corpus.')

def on_build_quality_phrases_begin(self, quality_file):
pass

Expand Down

0 comments on commit 3bd3b2b

Please sign in to comment.