XmlExtensionNotificationDataExtractor implements ExtensionNotificationDataExtractor { @Override public RecognitionResult getRecognitionResult(final Mmi mmi, final ExtensionNotification ext) throws ConversionException { JAXBContext context; try { context = JAXBContext.newInstance(Mmi.class); Marshaller marshaller = context.createMarshaller(); final EmmaSemanticInterpretationExtractor extractor = new EmmaSemanticInterpretationExtractor(); marshaller.marshal(mmi, extractor); return extractor.getRecognitonResult(); } catch (JAXBException e) { throw new ConversionException(e.getMessage(), e); } }  @Override RecognitionResult getRecognitionResult(final Mmi mmi,
            final ExtensionNotification ext);  }
@Test public void testSimple() throws Exception { final Mmi mmi = new Mmi(); final ExtensionNotification notification = new ExtensionNotification(); mmi.setExtensionNotification(notification); notification.setContext(UUID.randomUUID().toString()); notification.setRequestId("42"); notification.setSource("fromhere"); notification.setTarget("tothere"); final AnyComplexType any = new AnyComplexType(); notification.setData(any); final DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.newDocument(); final Element emma = document.createElementNS(EMMA_NAMESPACE, "emma:emma"); emma.setAttribute("version", "1.0"); document.appendChild(emma); final Element interpretation = document.createElementNS(EMMA_NAMESPACE, "emma:interpretation"); interpretation.setAttribute("id", "dummy"); interpretation .setAttributeNS(EMMA_NAMESPACE, "emma:medium", "acoustic"); any.addContent(emma); interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:mode", "mmi"); float confidence = 0.4f; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:confidence", Float.toString(confidence)); final String tokens = "this is a test"; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:tokens", tokens); emma.appendChild(interpretation); final XmlExtensionNotificationDataExtractor extractor = new XmlExtensionNotificationDataExtractor(); final ExtensionNotification ext = mmi.getExtensionNotification(); final RecognitionResult result = extractor.getRecognitionResult(mmi, ext); Assert.assertEquals(tokens, result.getUtterance()); Assert.assertEquals(confidence, result.getConfidence(), .001); }
@Test public void testSimpleSemanticIntperpretation() throws Exception, SemanticError { final Mmi mmi = new Mmi(); final ExtensionNotification notification = new ExtensionNotification(); mmi.setExtensionNotification(notification); notification.setContext(UUID.randomUUID().toString()); notification.setRequestId("42"); notification.setSource("fromhere"); notification.setTarget("tothere"); final AnyComplexType any = new AnyComplexType(); notification.setData(any); final DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.newDocument(); final Element emma = document.createElementNS(EMMA_NAMESPACE, "emma:emma"); emma.setAttribute("version", "1.0"); document.appendChild(emma); final Element interpretation = document.createElementNS(EMMA_NAMESPACE, "emma:interpretation"); interpretation.setAttribute("id", "dummy"); interpretation .setAttributeNS(EMMA_NAMESPACE, "emma:medium", "acoustic"); any.addContent(emma); interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:mode", "mmi"); float confidence = 0.4f; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:confidence", Float.toString(confidence)); final String tokens = "this is a test"; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:tokens", tokens); emma.appendChild(interpretation); final Element literal = document.createElementNS(EMMA_NAMESPACE, "emma:literal"); interpretation.appendChild(literal); final Text text = document.createTextNode("test"); literal.appendChild(text); final XmlExtensionNotificationDataExtractor extractor = new XmlExtensionNotificationDataExtractor(); final ExtensionNotification ext = mmi.getExtensionNotification(); final RecognitionResult result = extractor.getRecognitionResult(mmi, ext); Assert.assertEquals(tokens, result.getUtterance()); Assert.assertEquals(confidence, result.getConfidence(), .001); final DataModel model = Mockito.mock(DataModel.class); Assert.assertEquals("test", result.getSemanticInterpretation(model)); }
@Test public void testCompundSemanticIntperpretation() throws Exception, SemanticError { final Mmi mmi = new Mmi(); final ExtensionNotification notification = new ExtensionNotification(); mmi.setExtensionNotification(notification); notification.setContext(UUID.randomUUID().toString()); notification.setRequestId("42"); notification.setSource("fromhere"); notification.setTarget("tothere"); final AnyComplexType any = new AnyComplexType(); notification.setData(any); final DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.newDocument(); final Element emma = document.createElementNS(EMMA_NAMESPACE, "emma:emma"); emma.setAttribute("version", "1.0"); document.appendChild(emma); final Element interpretation = document.createElementNS(EMMA_NAMESPACE, "emma:interpretation"); interpretation.setAttribute("id", "dummy"); interpretation .setAttributeNS(EMMA_NAMESPACE, "emma:medium", "acoustic"); any.addContent(emma); interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:mode", "mmi"); float confidence = 0.4f; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:confidence", Float.toString(confidence)); final String tokens = "this is a test"; interpretation.setAttributeNS(EMMA_NAMESPACE, "emma:tokens", tokens); emma.appendChild(interpretation); final Element order = document.createElement("order"); interpretation.appendChild(order); final Element topping = document.createElement("topping"); order.appendChild(topping); final Text orderText = document.createTextNode("Salami"); topping.appendChild(orderText); final Element size = document.createElement("size"); order.appendChild(size); final Text sizeText = document.createTextNode("medium"); size.appendChild(sizeText); final XmlExtensionNotificationDataExtractor extractor = new XmlExtensionNotificationDataExtractor(); final ExtensionNotification ext = mmi.getExtensionNotification(); final RecognitionResult result = extractor.getRecognitionResult(mmi, ext); Assert.assertEquals(tokens, result.getUtterance()); Assert.assertEquals(confidence, result.getConfidence(), .001); final DataModel model = Mockito.mock(DataModel.class); System.out.println(result.getSemanticInterpretation(model)); }