File: test.py

package info (click to toggle)
sunpinyin 3.0.0~rc1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,944 kB
  • sloc: cpp: 13,586; python: 923; makefile: 198
file content (50 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python3
# -*- coding: UTF-8 -*-

from pyslm import Slm, SlmState
from pytrie import PinyinTrie, PinyinTrieNode, WordInfo

def test_pyslm ():
    slm = Slm ()
    if not slm.load ("../data/lm_sc.t3g"):
        return

    pr, result = slm.transfer (SlmState(0,0), 58614)
    print("pr =", pr, "\tresult = %s" % result)
    
    pr, result = slm.transfer (result, 75956)
    print("pr =", pr, "\tresult = %s" % result)
    
    pr, result = slm.transfer (result, 84582)
    print("pr =", pr, "\tresult = %s" % result)
    
    his = slm.history_state_of (result)
    print("his = %s" % his)
    
    slm.historify (result)
    print("result = %s" % result)

    print('last_word_id =', slm.last_word_id (result))

    slm.free ()

def test_pytrie ():
    trie = PinyinTrie()
    if not trie.load ("../data/pydict_sc.bin"):
        return

    root = trie.get_root_node ()
    node = trie.transfer (root, 0x1000)
    for w in node.get_words ():
        print(w)

    print(trie.is_valid (node, False, 0))
    print(trie[10000])

    print(trie.get_symbol_id (u'。'))
    trie.free ()

test_pyslm()
test_pytrie()

# -*- indent-tabs-mode: nil -*- vim:et:ts=4