コード例 #1
0
 @Test
 public void testGetSemanticInterpretationCompundObject() throws Exception, SemanticError {
   EngineManager.registerEngineListFactory(SphinxEngineListFactory.class.getName());
   Recognizer recognizer =
       (Recognizer) EngineManager.createEngine(new RecognizerMode(SpeechLocale.ENGLISH));
   recognizer.allocate();
   final GrammarManager manager = recognizer.getGrammarManager();
   final RuleGrammar grammar = manager.createRuleGrammar("grammar:test", "test");
   final RuleComponent[] components =
       new RuleComponent[] {
         new RuleToken("test"),
         new RuleTag("out = new Object(); out.order = new Object();"),
         new RuleTag("out.order.topping=\"salami\";"),
         new RuleTag("out.order.size=\"medium\";"),
         new RuleTag("out.date=\"now\";")
       };
   final RuleSequence sequence = new RuleSequence(components);
   final Rule root = new Rule("test", sequence, Rule.PUBLIC);
   grammar.addRule(root);
   recognizer.processGrammars();
   final BaseResult result = new BaseResult(grammar, "test");
   final Jsapi20RecognitionResult res = new Jsapi20RecognitionResult(result);
   final DataModel model = Mockito.mock(DataModel.class);
   res.getSemanticInterpretation(model);
   Mockito.verify(model).updateVariable("test", 5);
   //
   // Assert.assertEquals("{\"order\":{\"topping\":\"salami\",\"size\":\"medium\"},\"date\":\"now\"}",
   //                ScriptingEngine.toJSON((ScriptableObject) interpretation));
 }
コード例 #2
0
 @Test
 public void testGetSemanticInterpretation() throws Exception, SemanticError {
   EngineManager.registerEngineListFactory(SphinxEngineListFactory.class.getName());
   Recognizer recognizer =
       (Recognizer) EngineManager.createEngine(new RecognizerMode(SpeechLocale.ENGLISH));
   recognizer.allocate();
   final GrammarManager manager = recognizer.getGrammarManager();
   final RuleGrammar grammar = manager.createRuleGrammar("grammar:test", "test");
   final RuleComponent[] components =
       new RuleComponent[] {new RuleToken("test"), new RuleTag("T")};
   final RuleSequence sequence = new RuleSequence(components);
   final Rule root = new Rule("test", sequence, Rule.PUBLIC);
   grammar.addRule(root);
   recognizer.processGrammars();
   final BaseResult result = new BaseResult(grammar, "test");
   final Jsapi20RecognitionResult res = new Jsapi20RecognitionResult(result);
   final DataModel model = Mockito.mock(DataModel.class);
   Assert.assertEquals("T", res.getSemanticInterpretation(model));
 }