Ejemplo n.º 1
0
 def test_study_template_with_same_template(self):
     """Dictionary#study_template: 同じテンプレートは学習しない"""
     parts1 = analyze('テンプレートを学習する')
     parts2 = analyze('プログラムを作成する')
     self.dictionary.study_template(parts1)
     self.dictionary.study_template(parts2)
     eq_(len(self.dictionary.template), 1)
     eq_(self.dictionary.template[2], ['%noun%を%noun%する'])
Ejemplo n.º 2
0
 def test_study_template(self):
     """Dictionary#study_template: テンプレートを学習する"""
     eq_(len(self.dictionary.template), 0)
     parts = analyze('テンプレートを学習する')
     self.dictionary.study_template(parts)
     eq_(len(self.dictionary.template), 1)
     eq_(self.dictionary.template[2], ['%noun%を%noun%する'])
Ejemplo n.º 3
0
def test_markov_save_and_load():
    """Dictionary#markov: 保存した辞書を読み込める"""
    sentense = '私はプログラムの女の子です'
    parts = analyze(sentense)
    d1 = Dictionary()
    d1.study_markov(parts)
    d1.save()
    d2 = Dictionary()
    ok_(d2.markov.generate('私').startswith('私は'))
Ejemplo n.º 4
0
def test_dictionary_dir():
    """Dictionary#save: 辞書ファイルは~/.unmo/dics/に保存する"""
    sentense = 'こんにちは'
    parts = analyze(sentense)
    d = Dictionary()
    d.study(sentense, parts)
    d.save()
    dics_dir = os.path.join(HOME, '.unmo', 'dics')
    ok_(os.path.isdir(dics_dir))
Ejemplo n.º 5
0
 def test_study(self):
     """Dictionary#study: すべての辞書に学習させる"""
     sentense = '私はプログラムの女の子です'
     parts = analyze(sentense)
     self.dictionary.study(sentense, parts)
     eq_(len(self.dictionary.random), 2)  # デフォルト + 1
     eq_(len(self.dictionary.pattern), 3)  # 名詞の数
     eq_(len(self.dictionary.template), 1)  # template[3]
     eq_(len(self.dictionary.markov._starts), 1)  # _starts['私']
Ejemplo n.º 6
0
def test_template_save_and_load():
    """Dictionary#template: 保存した辞書を読み込める"""
    sentense = '私はプログラムの女の子です'
    result = '%noun%は%noun%の%noun%です'
    parts = analyze(sentense)
    d1 = Dictionary()
    d1.study_template(parts)
    d1.save()
    d2 = Dictionary()
    ok_(d2.template[3] == [result])
Ejemplo n.º 7
0
 def test_study_pattern_with_same_word(self):
     """Dictionary#study_pattern: 同じ単語があれば追加する"""
     sentenses = ['波が立つ', '波が引く']
     parts_per_sentense = [analyze(s) for s in sentenses]
     for sentense, parts in zip(sentenses, parts_per_sentense):
         self.dictionary.study_pattern(sentense, parts)
     eq_(len(self.dictionary.pattern), 1)
     eq_(self.dictionary.pattern[0]['pattern'], '波')
     for i, sentense in enumerate(sentenses):
         eq_(self.dictionary.pattern[0]['phrases'][i], sentense)
Ejemplo n.º 8
0
 def test_study_pattern(self):
     """Dictionary#study_pattern: 名詞の数だけパターンを学習する"""
     sentense = '名詞の数だけパターンを学習する'
     parts = analyze(sentense)
     self.dictionary.study_pattern(sentense, parts)
     eq_(len(self.dictionary.pattern), 4)
     nouns = ['名詞', '数', 'パターン', '学習']
     for pattern in self.dictionary.pattern:
         ok_(pattern['pattern'] in nouns)
         eq_(pattern['phrases'], [sentense])
Ejemplo n.º 9
0
def test_pattern_save_and_load():
    """Dictionary#pattern: 保存した辞書を読み込める"""
    word = '名詞'
    sentense = '名詞です'
    parts = analyze(sentense)
    d1 = Dictionary()
    d1.study_pattern(sentense, parts)
    d1.save()
    d2 = Dictionary()
    patterns = [
        ptn for ptn in d2.pattern if re.search(ptn['pattern'], sentense)
    ]
    eq_(len(patterns), 1)
    ok_(patterns[0], {'pattern': word, 'phrases': [sentense]})
Ejemplo n.º 10
0
 def test_study_pattern_without_nouns(self):
     """Dictionary#study_pattern: 名詞がなければ学習しない"""
     sentense = '実はさっきから寒い'
     parts = analyze(sentense)
     self.dictionary.study_pattern(sentense, parts)
     eq_(len(self.dictionary.pattern), 0)
Ejemplo n.º 11
0
 def test_study_template_without_nouns(self):
     """Dictionary#study_template: 名詞がなければ学習しない"""
     parts = analyze('実はさっきから寒い')
     self.dictionary.study_template(parts)
     eq_(len(self.dictionary.template), 0)
Ejemplo n.º 12
0
 def test_study_template_count(self):
     """Dictionary#study_template: 名詞の数を辞書のインデックスにする"""
     parts = analyze('私はプログラムの女の子です')
     ok_(3 not in self.dictionary.template)
     self.dictionary.study_template(parts)
     ok_(3 in self.dictionary.template)
Ejemplo n.º 13
0
 def test_study_template_replace_nouns(self):
     """Dictionary#study_template: 形態素のリストを受け取り、名詞のみ%noun%に変換する"""
     parts = analyze('私はプログラムの女の子です')
     self.dictionary.study_template(parts)
     eq_(self.dictionary.template[3], ['%noun%は%noun%の%noun%です'])