Skip to content

Commit

Permalink
Database: Pivoting table
Browse files Browse the repository at this point in the history
Normalize: fix unpickling for Normalizers before caching was implemented
  • Loading branch information
PrimozGodec committed Apr 27, 2022
1 parent f0e8c60 commit 001722a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
recursive-include orangecontrib/text/datasets *.tab *.txt
recursive-include orangecontrib/text/models *.ftz
recursive-include orangecontrib/text/sentiment *.txt
recursive-include orangecontrib/text/tests *.txt *.json
recursive-include orangecontrib/text/tests *.txt *.json *.pkl
recursive-include orangecontrib/text/tutorials *.ows
recursive-include orangecontrib/text/widgets/icons *.svg *.png *.ai
recursive-include orangecontrib/text/widgets/resources *.js *.css *.html
Expand Down
8 changes: 7 additions & 1 deletion orangecontrib/text/preprocess/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def __getstate__(self):
d["_normalization_cache"] = {}
return d

def __setstate__(self, state):
self.__dict__.update(state)
# support old pickles (before caching was implemented) that are missing
# _normalization_cache
self._normalization_cache = {}


class WordNetLemmatizer(BaseNormalizer):
name = 'WordNet Lemmatizer'
Expand Down Expand Up @@ -201,7 +207,7 @@ def __setstate__(self, state):
Note: __model will be loaded on __call__
"""
self.__dict__.update(state)
super().__setstate__(state)
self.models = UDPipeModels()


Expand Down
Binary file added orangecontrib/text/tests/normalizer-v1.pkl
Binary file not shown.
10 changes: 10 additions & 0 deletions orangecontrib/text/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ def test_cache(self):
loaded_normalizer = pickle.loads(pickle.dumps(normalizer))
self.assertEqual(0, len(loaded_normalizer._normalization_cache))

def test_nocache_normalizer_restorable(self):
"""
Pickled normalizers made before implementing cache in normalizer must
load correctly
"""
test_folder = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(test_folder, "data", "normalizer-v1.pkl"), "rb") as f:
loaded_normalizer = pickle.load(f)
loaded_normalizer(self.corpus)


class UDPipeModelsTests(unittest.TestCase):
def test_label_transform(self):
Expand Down

0 comments on commit 001722a

Please sign in to comment.