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

Pickling UDPipe #387 #447

Merged
merged 1 commit into from
Aug 27, 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
7 changes: 7 additions & 0 deletions orangecontrib/text/preprocess/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,10 @@ def language(self):
def language(self, value):
self._language = value
self.model = None

def __getstate__(self):
return {'language': self.language}

def __setstate__(self, state):
self.__init__(state['language'])

10 changes: 10 additions & 0 deletions orangecontrib/text/tests/test_preprocess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle
import tempfile
import unittest
import os.path
Expand Down Expand Up @@ -187,6 +188,15 @@ def test_udpipe_doc(self):
self.assertListEqual(normalizer.normalize_doc('Gori na gori hiša gori'),
['gora', 'na', 'gora', 'hiša', 'goreti'])

def test_udpipe_pickle(self):
normalizer = preprocess.UDPipeLemmatizer()
normalizer.language = 'English'

loaded = pickle.loads(pickle.dumps(normalizer))
self.assertEqual(normalizer.language, loaded.language)
self.assertEqual(loaded.normalize_doc('peter piper pickled'),
['peter', 'piper', 'pickle'])

def test_porter_with_bad_input(self):
stemmer = preprocess.PorterStemmer()
self.assertRaises(TypeError, stemmer, 10)
Expand Down