Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / python / test.py
1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3
4 from pyslm import Slm, SlmState
5 from pytrie import PinyinTrie, PinyinTrieNode, WordInfo
6
7 def test_pyslm ():
8     slm = Slm ()
9     if not slm.load ("../data/lm_sc.t3g"):
10         return
11
12     pr, result = slm.transfer (SlmState(0,0), 58614)
13     print "pr =", pr, "\tresult = %s" % result
14     
15     pr, result = slm.transfer (result, 75956)
16     print "pr =", pr, "\tresult = %s" % result
17     
18     pr, result = slm.transfer (result, 84582)
19     print "pr =", pr, "\tresult = %s" % result
20     
21     his = slm.history_state_of (result)
22     print "his = %s" % his
23     
24     slm.historify (result)
25     print "result = %s" % result
26
27     print 'last_word_id =', slm.last_word_id (result)
28
29     slm.free ()
30
31 def test_pytrie ():
32     trie = PinyinTrie()
33     if not trie.load ("../data/pydict_sc.bin"):
34         return
35
36     root = trie.get_root_node ()
37     node = trie.transfer (root, 0x1000)
38     for w in node.get_words ():
39         print w
40
41     print trie.is_valid (node, False, 0)
42     print trie[10000]
43
44     print trie.get_symbol_id (u'。')
45     trie.free ()
46
47 test_pyslm()
48 test_pytrie()