test_grammar.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Author: Yuki Furuta <furushchev@jsk.imi.i.u-tokyo.ac.jp>
4 
5 import os
6 import rospkg
7 import rospy
8 import unittest
9 
10 from julius_ros.utils import make_grammar_from_rules
11 from julius_ros.utils import make_voca_from_categories
12 from julius_ros.utils import make_dfa
13 from julius_ros.utils import load_grammar
14 
15 
16 PKG = rospkg.RosPack().get_path("julius_ros")
17 
18 
19 class TestGrammar(unittest.TestCase):
20  def test_load_grammar(self):
21  self.assertTrue(os.path.join(PKG, "data", "udon.grammar"))
22  self.assertTrue(os.path.join(PKG, "data", "udon.voca"))
23  g = load_grammar(os.path.join(PKG, "data"), "udon")
24  self.assertIsNotNone(g)
25 
26  def test_grammar(self):
27  g = load_grammar(os.path.join(PKG, "data"), "udon")
28  gram = make_grammar_from_rules(g.rules)
29  self.assertIsNotNone(gram)
30 
31  def test_voca(self):
32  g = load_grammar(os.path.join(PKG, "data"), "udon")
33  voca = make_voca_from_categories(g.categories, g.vocabularies)
34  self.assertIsNotNone(voca)
35 
36  def test_dfa(self):
37  g = load_grammar(os.path.join(PKG, "data"), "udon")
38  gram = make_grammar_from_rules(g.rules)
39  voca = make_voca_from_categories(g.categories, g.vocabularies)
40  result = make_dfa(gram, voca)
41  self.assertIsNotNone(result)
42  self.assertEqual(len(result), 2)
43 
44 
45 if __name__ == '__main__':
46  import rostest
47  rospy.init_node("test_grammar")
48  rostest.rosrun("julius_ros", "test_grammar", TestGrammar)
def load_grammar(path, name)
Definition: utils.py:37
def make_dfa(grammar, voca)
Definition: utils.py:141
def make_grammar_from_rules(rules)
Definition: utils.py:99
def make_voca_from_categories(cats, vocas)
Definition: utils.py:118


julius_ros
Author(s): Yuki Furuta
autogenerated on Wed Dec 2 2020 04:11:43