JsonExtensionNotificationDataConverter implements ExtensionNotificationDataConverter { @Override public Object convertApplicationLastResult( final List<LastResult> lastresults) throws ConversionException { if (lastresults == null || lastresults.isEmpty()) { return null; } final Context context = Context.enter(); context.setLanguageVersion(Context.VERSION_DEFAULT); final ScriptableObject scope = context.initStandardObjects(); final LastResult lastresult = lastresults.get(0); final Scriptable vxml = context.newObject(scope); ScriptableObject.putProperty(vxml, "utterance", lastresult.getUtterance()); ScriptableObject.putProperty(vxml, "confidence", lastresult.getConfidence()); ScriptableObject.putProperty(vxml, "mode", lastresult.getInputmode()); ScriptableObject.putProperty(vxml, "interpretation", lastresult.getInterpretation()); return toJSON(vxml); } JsonExtensionNotificationDataConverter(); @Override Object convertApplicationLastResult(
            final List<LastResult> lastresults); @Override Object convertSynthesizedOutputEvent(
            final SynthesizedOutputEvent event); @Override Object convertRecognitionEvent(final DataModel model,
            final RecognitionEvent event); @Override Object convertSpokenInputEvent(final SpokenInputEvent input); String toJSON(final Scriptable object);  }
@Test public void testConvertApplicationLastResultComplexSemanticInterpretation() throws Exception { final JsonExtensionNotificationDataConverter converter = new JsonExtensionNotificationDataConverter(); final List<LastResult> list = new java.util.ArrayList<LastResult>(); final Context context = Context.enter(); context.setLanguageVersion(Context.VERSION_1_6); final Scriptable scope = context.initStandardObjects(); context.evaluateString(scope, "var out = new Object();", "expr", 1, null); context.evaluateString(scope, "var out = new Object();", "expr", 1, null); context.evaluateString(scope, "out.order = new Object();", "expr", 1, null); context.evaluateString(scope, "out.order.topping = 'Salami';", "expr", 1, null); context.evaluateString(scope, "out.order.size = 'medium';", "expr", 1, null); context.evaluateString(scope, "out.date = 'now';", "expr", 1, null); final Object out = scope.get("out", scope); final LastResult result = new LastResult("yes", .75f, "voice", out); list.add(result); final String json = (String) converter .convertApplicationLastResult(list); Assert.assertEquals("vxml.input = {\"utterance\":\"yes\"," + "\"confidence\":0.75,\"interpretation\":{\"order\":" + "{\"topping\":\"Salami\",\"size\":\"medium\"}," + "\"date\":\"now\"},\"mode\":\"voice\"}", json); }
@Test public void testConvertApplicationLastResult() throws Exception { final JsonExtensionNotificationDataConverter converter = new JsonExtensionNotificationDataConverter(); final List<LastResult> list = new java.util.ArrayList<LastResult>(); final LastResult result = new LastResult("yes", .75f, "voice", null); list.add(result); final String json = (String) converter .convertApplicationLastResult(list); Assert.assertEquals("vxml.input = {\"utterance\":\"yes\"," + "\"confidence\":0.75,\"interpretation\":null," + "\"mode\":\"voice\"}", json); }
@Test public void testConvertApplicationLastResultSimpleSemanticInterpretation() throws Exception { final JsonExtensionNotificationDataConverter converter = new JsonExtensionNotificationDataConverter(); final List<LastResult> list = new java.util.ArrayList<LastResult>(); final Context context = Context.enter(); context.setLanguageVersion(Context.VERSION_1_6); final Scriptable scope = context.initStandardObjects(); context.evaluateString(scope, "var out = 'yes';", "expr", 1, null); final Object out = scope.get("out", scope); final LastResult result = new LastResult("yeah", .75f, "voice", out); list.add(result); final String json = (String) converter .convertApplicationLastResult(list); Assert.assertEquals("vxml.input = {\"utterance\":\"yeah\"," + "\"confidence\":0.75,\"interpretation\":\"yes\"," + "\"mode\":\"voice\"}", json); }