Ошибка при компиляции словаря #3

Closed
anti-social opened this Issue Dec 3, 2012 · 3 comments

Projects

None yet

2 participants

@anti-social
KeyError                                  Traceback (most recent call last)
/home/alexk/projects/test_pymorphy/<ipython-input-6-91afa2c0de53> in <module>()
----> 1 cli.compile_dict('dict.opcorpora.xml')

/home/alexk/v/uaprom-arch/lib/python2.7/site-packages/pymorphy2/cli.pyc in compile_dict(in_filename, out_folder, overwrite, prediction_options)
     24     if out_folder is None:
     25         out_folder = 'dict'
---> 26     opencorpora_dict.to_pymorphy2_format(in_filename, out_folder, overwrite, prediction_options=prediction_options)
     27 
     28 def xml_to_json(in_filename, out_filename):

/home/alexk/v/uaprom-arch/lib/python2.7/site-packages/pymorphy2/opencorpora_dict.pyc in to_pymorphy2_format(opencorpora_dict_path, out_path, overwrite, prediction_options)
    383     lemmas, links, grammemes, version, revision = _load_json_or_xml_dict(opencorpora_dict_path)
    384     gramtab, suffixes, paradigms, words_dawg, prediction_suffixes_dawg = _gram_structures(
--> 385         lemmas, links, prediction_options=prediction_options
    386     )
    387     prediction_prefixes_dawg = dawg.DAWG(PREDICTION_PREFIXES)

/home/alexk/v/uaprom-arch/lib/python2.7/site-packages/pymorphy2/opencorpora_dict.pyc in _gram_structures(lemmas, links, prediction_options)
    287 
    288     logger.info("inlining lemma links...")
--> 289     lemmas = _join_lemmas(lemmas, links)
    290 
    291     logger.info('building paradigms...')

/home/alexk/v/uaprom-arch/lib/python2.7/site-packages/pymorphy2/opencorpora_dict.pyc in _join_lemmas(lemmas, links)
    210 #            continue

    211 
--> 212         move_lemma(link_end, link_start)
    213 
    214     lemma_ids = sorted(lemmas.keys(), key=int)
/home/alexk/v/uaprom-arch/lib/python2.7/site-packages/pymorphy2/opencorpora_dict.pyc in move_lemma(from_id, to_id)
    193 
    194     def move_lemma(from_id, to_id):
--> 195         lm = lemmas[str(from_id)]
    196 
    197         while to_id in moves:

KeyError: '6'
@anti-social

Похоже str тут просто не нужен:

diff --git a/pymorphy2/opencorpora_dict.py b/pymorphy2/opencorpora_dict.py
index 89df947..7852d32 100644
--- a/pymorphy2/opencorpora_dict.py
+++ b/pymorphy2/opencorpora_dict.py
@@ -192,12 +192,12 @@ def _join_lemmas(lemmas, links):
     moves = dict()

     def move_lemma(from_id, to_id):
-        lm = lemmas[str(from_id)]
+        lm = lemmas[from_id]

         while to_id in moves:
             to_id = moves[to_id]

-        lemmas[str(to_id)].extend(lm)
+        lemmas[to_id].extend(lm)
         del lm[:]
         moves[from_id] = to_id
@kmike kmike closed this in 1823075 Dec 3, 2012
@kmike
Owner
kmike commented Dec 3, 2012

Текущий вариант не работал, если компиляция шла из xml, но работал для компиляции из json. Если убрать str, то получалось все наоборот. Поэтому еще int ненужные убрал. Спасибо!

@kmike
Owner
kmike commented Dec 3, 2012

Опс, я коммиты https://github.com/anti-social/pymorphy2 только сейчас увидел. Ну да ладно.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment