Home | History | Annotate | Download | only in python
      1 #!/usr/bin/python
      2 # -*- coding: UTF-8 -*-
      3 
      4 from pyslm import Slm, SlmState
      5 from pytrie import PinyinTrie, PinyinTrieNode
      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, 'ce')
     38     print trie.is_valid (node, False, 0)
     39     print trie[10000]
     40 
     41     print trie.get_symbol_id (u'')
     42     trie.free ()
     43 
     44     trie.free ()
     45 
     46 test_pyslm()
     47 test_pytrie()
     48