Commits

Mikhail Korobov  committed c64ece6

в скрипте конвертации словарей сразу говорим, если сконвертировать нельзя из-за того, что DAWG-Python не умеет строить dawg-и.

  • Participants
  • Parent commits 433337e

Comments (0)

Files changed (2)

File pymorphy2/dawg.py

 from __future__ import absolute_import
 
 try:
-    import dawg
+    from dawg import DAWG, RecordDAWG
     CAN_CREATE = True
 
 except ImportError:
-    import dawg_python as dawg
+    from dawg_python import DAWG, RecordDAWG
     CAN_CREATE = False
 
+def assert_can_create():
+    if not CAN_CREATE:
+        raise NotImplementedError("Creating of DAWGs with DAWG-Python is not supported; install 'dawg' package. ")
 
-class WordsDawg(dawg.RecordDAWG):
+
+class WordsDawg(RecordDAWG):
     """
     DAWG for storing words.
     """
         if data is None:
             super(WordsDawg, self).__init__(self.DATA_FORMAT)
         else:
-            if not CAN_CREATE:
-                raise NotImplementedError("Creating of DAWGs with DAWG-Python is not supported; install 'dawg' package. ")
+            assert_can_create()
             super(WordsDawg, self).__init__(self.DATA_FORMAT, data)
 
 class PredictionSuffixesDAWG(WordsDawg):

File pymorphy2/opencorpora_dict.py

 
 import pymorphy2
 from pymorphy2 import tagset
-from pymorphy2.dawg import WordsDawg, PredictionSuffixesDAWG, dawg
+from pymorphy2 import dawg
 from pymorphy2.constants import LEMMA_PREFIXES, PREDICTION_PREFIXES
 
 logger = logging.getLogger(__name__)
     suffixes_dawg_data = _suffixes_prediction_data(words, popularity, gramtab, paradigms, **prediction_options)
 
     logger.debug('building word DAWG..')
-    words_dawg = WordsDawg(words)
+    words_dawg = dawg.WordsDawg(words)
 
     del words
 
     logger.debug('building prediction_suffixes DAWG..')
-    prediction_suffixes_dawg = PredictionSuffixesDAWG(suffixes_dawg_data)
+    prediction_suffixes_dawg = dawg.PredictionSuffixesDAWG(suffixes_dawg_data)
 
     return tuple(gramtab), suffixes, paradigms, words_dawg, prediction_suffixes_dawg
 
 
     ``out_path`` should be a name of folder where to put dictionaries.
     """
+    dawg.assert_can_create()
 
     # create the output folder
     try:
             para.fromfile(f, paradigm_len)
             paradigms.append(para)
 
-    words = WordsDawg().load(_f('words.dawg'))
-    prediction_suffixes = PredictionSuffixesDAWG().load(_f('prediction-suffixes.dawg'))
+    words = dawg.WordsDawg().load(_f('words.dawg'))
+    prediction_suffixes = dawg.PredictionSuffixesDAWG().load(_f('prediction-suffixes.dawg'))
     prediction_prefixes = dawg.DAWG().load(_f('prediction-prefixes.dawg'))
     return DictTuple(meta, gramtab, suffixes, paradigms, words, prediction_prefixes, prediction_suffixes)