Skip to content

Commit

Permalink
Merge pull request #447 from s-alexey/pickle_udpipe
Browse files Browse the repository at this point in the history
Pickling UDPipe #387
  • Loading branch information
ajdapretnar authored Aug 27, 2019
2 parents 49c24a6 + 0b678f3 commit 70be2b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 70be2b8

Please sign in to comment.