Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when cleaning up crfsuite files #843

Merged
merged 2 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Invalidate importlib caches after dynamically installing module [#838](https://github.com/snipsco/snips-nlu/pull/838)
- Automatically generate documentation for supported languages and builtin entities [#841](https://github.com/snipsco/snips-nlu/pull/841)
- Fix issue when cleaning up crfsuite files [#843](https://github.com/snipsco/snips-nlu/pull/843)

## [0.20.0] - 2019-07-16
### Added
Expand Down
12 changes: 5 additions & 7 deletions snips_nlu/slot_filler/crf_slot_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,12 @@ def from_path(cls, path, **shared):
slot_filler.crf_model = crf
return slot_filler

def _cleanup(self):
if self.crf_model is not None:
self.crf_model.modelfile.cleanup()

def __del__(self):
if self.crf_model is None or self.crf_model.modelfile.name is None:
return
try:
Path(self.crf_model.modelfile.name).unlink()
except OSError as e:
logger.warning("Unable to remove CRF model file at path '%s': %s",
self.crf_model.modelfile.name, repr(e))
self._cleanup()


def _get_crf_model(crf_args):
Expand Down
20 changes: 20 additions & 0 deletions snips_nlu/tests/test_crf_slot_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,3 +1014,23 @@ def test_training_should_be_reproducible(self):
slot_filler2.crf_model.state_features_)
self.assertDictEqual(slot_filler1.crf_model.transition_features_,
slot_filler2.crf_model.transition_features_)

def test_should_cleanup(self):
# Given
dataset_stream = io.StringIO("""
---
type: intent
name: MakeTea
utterances:
- make me a [beverage_temperature:Temperature](hot) cup of tea
- make me [number_of_cups:snips/number](five) tea cups""")
dataset = Dataset.from_yaml_files("en", [dataset_stream])
slot_filler = CRFSlotFiller().fit(dataset, "MakeTea")
crf_file = Path(slot_filler.crf_model.modelfile.name)
self.assertTrue(crf_file.exists())

# When
slot_filler._cleanup() # pylint:disable=protected-access

# Then
self.assertFalse(crf_file.exists())