File: test.py

package info (click to toggle)
sunpinyin 2.0.3%2Bgit20120607-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,372 kB
  • sloc: cpp: 14,549; python: 1,309; makefile: 154
file content (48 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download
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
#!/usr/bin/python
# -*- 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()