在使用 UniDic 2.3.0 构建 MeCab 0.996 用户词典时,如何确定左右上下文 ID 应该是什么?

How does one determine what the left and right context IDs should be when building a MeCab 0.996 user dictionary with UniDic 2.3.0?

我正在尝试使用以下终端命令在 Ubuntu 20.10 上构建 MeCab 0.996 user dictionary with UniDic CWJ 2.3.0

$ /usr/local/libexec/mecab/mecab-dict-index -d /usr/local/lib/unidic/unidic-cwj-2.3.0 -u ~/foo/bar/foo.dic -f utf8 -t utf8 ~/foo/bar/foo.csv

其中 foo.csv 是:

ダイバーシティ,,,-200,名詞,普通名詞,一般,*,*,*,ダイバーシティ,ダイバーシティ-diversity,ダイバーシティ,ダイバーシティ,ダイバーシティ,ダイバーシティ,外,*,*,*,*,*,*,体,ダイバーシティ,ダイバーシティ,ダイバーシティ,ダイバーシティ,,,,,

但是我得到这个错误:

dictionary.cpp(355) [cid->left_size() == matrix.left_size() && cid->right_size() == matrix.right_size()] Context ID files(/usr/local/lib/unidic/unidic-cwj-2.3.0/left-id.def or /usr/local/lib/unidic/unidic-cwj-2.3.0/right-id.def may be broken

这个未解决的 GitHub 问题 post 似乎相关但超出了我的理解:https://github.com/taku910/mecab/issues/42

我可以使用较旧的 unidic-mecab-2.1.2:

构建 MeCab 用户词典
$ /usr/local/libexec/mecab/mecab-dict-index -d ~/mecab/unidic-mecab-2.1.2_src/ -u ~/foo/bar/foo.dic -f utf8 -t utf8 ~/foo/bar/foo.csv
./pos-id.def is not found. minimum setting is used
emitting double-array: 100% |###########################################| 
done!

我还可以使用 reiwa 构建用户词典。33.csv 来自 unidic-py documentation:

/usr/local/libexec/mecab/mecab-dict-index -d /usr/local/lib/unidic/unidic-cwj-2.3.0 -u ~/foo/bar/reiwa33.dic -f utf8 -t utf8 ~/foo/bar/reiwa.33.csv
/usr/local/lib/unidic/unidic-cwj-2.3.0/pos-id.def is not found. minimum setting is used
reading /home/foo/bar/reiwa.33.csv ... 3
emitting double-array: 100% |###########################################| 
done!

令和33.csv是:

令和,4786,4786,8205,名詞,固有名詞,一般,*,*,*,レイワ,令和,令和,レーワ,令和,レーワ,固,*,*,*,*,*,*,*,レイワ,レイワ,レイワ,レイワ,"1,0",*,*,*,*
㋿,5969,5969,2588,補助記号,一般,*,*,*,*,,㋿,㋿,,㋿,,記号,*,*,*,*,*,*,*,,,,,*,*,*,*,999999
㋿,4786,4786,3992,名詞,固有名詞,一般,*,*,*,レイワ,令和,㋿,レーワ,㋿,レーワ,固,*,*,*,*,*,*,*,レイワ,レイワ,レイワ,レイワ,"1,0",*,*,*,*

因此,这两个 csv 文件之间的区别在于,在 reiwa 中为每个表面形式指定了左右上下文 ID(以及 aType 和 lemma_id 用于某些但不是所有条目)。33.csv,但不在 foo.csv.

根据MeCab的instructions,mecab-dict-index会自动分配左右ID,unidic-mecab-2.1.2似乎是这样,但UniDic不是2.3.0.

那么,我想问题就变成了:如何确定左右上下文 ID 应该是什么?哪里有解释吗?

我在 this Qiita post 中找到了答案。

判断左右上下文ID:

  1. 分别查看左-id.def和右-id.def文件:
    $ gedit /usr/local/lib/unidic/unidic-cwj-2.3.0/left-id.def

    $ gedit /usr/local/lib/unidic/unidic-cwj-2.3.0/right-id.def
  1. 找到与单词特征匹配的行。

    对于一般外来词名词(例如,ダイバーシティ)没有 指定的重音类型 (aType) 或重音变化类型 (aConType) 值为:

    left-id: 15917 名詞,普通名詞,一般,*,*,*,*,*,外,*,*,*,*,*,*

    right-id: 17160 名詞,普通名詞,一般,*,*,*,*,*,外,*,*,*,*,*,*
  1. 因此foo.csv应该是:
    ダイバーシティ,15917,17160,-200,名詞,普通名詞,一般,*,*,*,ダイバーシティ,ダイバーシティ-diversity,ダイバーシティ,ダイバーシティ,ダイバーシティ,ダイバーシティ,外,*,*,*,*,*,*,体,ダイバーシティ,ダイバーシティ,ダイバーシティ,ダイバーシティ,*,*,*,*,*
  1. 使用来自 foo.csv 的 UniDic CWJ 2.3.0 编译 MeCab 字典然后在没有“左-或右-id.def 可能被破坏的错误”的情况下工作:
    $ /usr/local/libexec/mecab/mecab-dict-index -d /usr/local/lib/unidic/unidic-cwj-2.3.0/ -u ~/foo/bar/foo.dic -f utf8 -t utf8 ~/foo/bar/foo.csv
    /usr/local/lib/unidic/unidic-cwj-2.3.0/pos-id.def is not found. minimum setting is used
    reading /home/foo/bar/foo.csv ... 1
    emitting double-array: 100% |###########################################| 
    done!

注意:reiwa 中的值。33.csv 似乎适用于 UniDic 2.1.2。

为什么会出现left/right-id.def错误以及如何交换matrix.def中所有左右值的详细解释,请参见this Japanese Stack Overflow post