InteractionModelRenderer { public InteractionModel render(SkillModel skillModel, Locale locale) { assertNotNull(skillModel, "skillDefinition"); assertNotNull(locale, "locale"); if (!skillModel.getInvocationNames().containsKey(locale)) { throw new IllegalArgumentException("no invocation name specified for locale: " + locale); } SubModel subModel = modelRenderer.render(skillModel.getModel(), locale); LanguageModel languageModel = LanguageModel.builder() .withInvocationName(skillModel.getInvocationNames().get(locale)) .withIntents(new ArrayList<>(subModel.getLanguageModel().getIntents())) .withTypes(new ArrayList<>(subModel.getLanguageModel().getTypes())) .build(); return InteractionModel.builder() .withLanguageModel(languageModel) .withDialog(subModel.getDialog()) .withPrompts(subModel.getPrompts()) .build(); } InteractionModelRenderer(ModelRenderer modelRenderer);  InteractionModelRenderer(); InteractionModel render(SkillModel skillModel, Locale locale);  }
@Test public void testStandardIntentsLanguageModel() throws IOException { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "test") .addModel(Model.builder() .intent(HelpIntent.class) .intent(StopIntent.class) .build()) .build(); LanguageModel actual = underTest.render(skill, Locales.en_US).getLanguageModel(); LanguageModel expected = LanguageModel.builder() .withInvocationName("test") .withIntents(Arrays.asList( makeIntent(HelpIntent.class, null, null), makeIntent(StopIntent.class, null, null) )) .withTypes(Collections.emptyList()) .build(); assertEquals(WRITER.writeValueAsString(expected), WRITER.writeValueAsString(actual)); assertEquals(2, actual.getIntents().size()); }
@Test public void testCustomIntentsLanguageModel() throws IOException { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "test") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); LanguageModel actual = underTest.render(skill, Locales.en_US).getLanguageModel(); LanguageModel expected = LanguageModel.builder() .withInvocationName("test") .withIntents(Collections.singletonList( makeIntent("TestIntent", Arrays.asList( makeIntentSlot("customSlot", "TestCustom"), makeIntentSlot("dateSlot", "AMAZON.DATE"), makeIntentSlot("dayOfWeekSlot", "AMAZON.DayOfWeek"), makeIntentSlot("durationSlot", "AMAZON.DURATION"), makeIntentSlot("listTypeSlot", "AMAZON.Actor"), makeIntentSlot("literalSlot", "AMAZON.LITERAL"), makeIntentSlot("numberSlot", "AMAZON.NUMBER"), makeIntentSlot("timeSlot", "AMAZON.TIME") ), Collections.singletonList("test_en_US")))) .withTypes(Collections.singletonList( makeSlotType("TestCustom", Arrays.asList( makeSlotTypeValue("A", Collections.singletonList("test_A_en_US")), makeSlotTypeValue("B", Collections.singletonList("test_B_en_US")))))) .build(); assertEquals(WRITER.writeValueAsString(expected), WRITER.writeValueAsString(actual)); }
@Test public void testSynonyms() throws IOException { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .withInvocationName(Locales.en_GB, "en_GB") .withInvocationName(Locales.de_DE, "de_DE") .withInvocationName(Locales.fr_FR, "fr_FR") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); for (Locale locale : Locales.values()) { Collection<SlotType> actual = underTest.render(skill, locale).getLanguageModel().getTypes(); List<SlotType> expected = Collections.singletonList( makeSlotType("TestCustom", Arrays.asList( makeSlotTypeValue("A", Collections.singletonList("test_A_" + stringifyLocale(locale))), makeSlotTypeValue("B", Collections.singletonList("test_B_" + stringifyLocale(locale))) ) )); assertEquals(WRITER.writeValueAsString(expected), WRITER.writeValueAsString(actual)); } }
@Test public void testSamples() throws IOException { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .withInvocationName(Locales.en_GB, "en_GB") .withInvocationName(Locales.de_DE, "de_DE") .withInvocationName(Locales.fr_FR, "fr_FR") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); for (Locale locale : Locales.values()) { Collection<com.amazon.ask.interaction.model.Intent> actual = underTest.render(skill, locale).getLanguageModel().getIntents(); List<com.amazon.ask.interaction.model.Intent> expected = Collections.singletonList( makeIntent("TestIntent", Arrays.asList( makeIntentSlot("customSlot", "TestCustom"), makeIntentSlot("dateSlot", "AMAZON.DATE"), makeIntentSlot("dayOfWeekSlot", "AMAZON.DayOfWeek"), makeIntentSlot("durationSlot", "AMAZON.DURATION"), makeIntentSlot("listTypeSlot", "AMAZON.Actor"), makeIntentSlot("literalSlot", "AMAZON.LITERAL"), makeIntentSlot("numberSlot", "AMAZON.NUMBER"), makeIntentSlot("timeSlot", "AMAZON.TIME") ), Collections.singletonList("test_" + stringifyLocale(locale))) ); assertEquals(WRITER.writeValueAsString(expected), WRITER.writeValueAsString(actual)); } }
@Test public void testIntentConfirmation() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); Prompt expectedPrompt = Prompt.builder() .withId("Confirm.Intent-TestIntent") .withVariations(Collections.singletonList(PromptVariation.builder() .withType("PlainText") .withValue("test_en_US confirmation") .build())) .build(); Prompt actualPrompt = model.getPrompts().stream().filter(p -> p.getId().equals("Confirm.Intent-TestIntent")).findFirst().get(); assertEquals(actualPrompt, expectedPrompt); DialogIntent actualIntent = model.getDialog().getIntents().stream().filter(d -> d.getName().equals("TestIntent")).findFirst().get(); assertEquals(actualIntent.getPrompts().getConfirmation(), "Confirm.Intent-TestIntent"); assertEquals(actualIntent.getConfirmationRequired(), true); }
@Test public void testIntentExplicitConfirmationPromptId() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestPrompts.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); Prompt expectedPrompt = Prompt.builder() .withId("testIntentConfirmation") .withVariations(Collections.singletonList(PromptVariation.builder() .withType("PlainText") .withValue("test_en_US confirmation") .build())) .build(); Prompt actualPrompt = model.getPrompts().stream().filter(p -> p.getId().equals("testIntentConfirmation")).findFirst().get(); assertEquals(actualPrompt, expectedPrompt); DialogIntent actualIntent = model.getDialog().getIntents().stream().filter(d -> d.getName().equals("TestPrompts")).findFirst().get(); assertEquals(actualIntent.getPrompts().getConfirmation(), "testIntentConfirmation"); assertEquals(actualIntent.getConfirmationRequired(), true); }
@Test public void testSlotConfirmation() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); DialogSlot slot = model.getDialog().getIntents().get(0).getSlots().stream() .filter(s -> s.getName().equals("customSlot")) .findFirst().get(); assertEquals(slot.getType(), "TestCustom"); assertEquals(slot.getConfirmationRequired(), true); assertEquals(slot.getPrompts().getConfirmation(), "Confirm.Intent-TestIntent.IntentSlot-customSlot"); assertEquals( model.getPrompts().stream().filter(p -> p.getId().equals("Confirm.Intent-TestIntent.IntentSlot-customSlot")).findFirst().get().getVariations(), Collections.singletonList(PromptVariation.builder().withType("PlainText").withValue("test_en_US customSlot confirmation").build())); }
@Test public void testSlotElicitation() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestIntent.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); DialogSlot slot = model.getDialog().getIntents().get(0).getSlots().stream() .filter(s -> s.getName().equals("customSlot")) .findFirst().get(); assertEquals(slot.getType(), "TestCustom"); assertEquals(slot.getElicitationRequired(), true); assertEquals(slot.getPrompts().getElicitation(), "Elicit.Intent-TestIntent.IntentSlot-customSlot"); assertEquals( model.getPrompts().stream().filter(p -> p.getId().equals("Elicit.Intent-TestIntent.IntentSlot-customSlot")).findFirst().get().getVariations(), Collections.singletonList(PromptVariation.builder().withType("PlainText").withValue("test_en_US customSlot elicitation").build())); }
@Test public void testSlotExplicitPromptIds() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestPrompts.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); DialogSlot slot = model.getDialog().getIntents().get(0).getSlots().stream() .filter(s -> s.getName().equals("customSlot")) .findFirst().get(); assertEquals(slot.getPrompts().getConfirmation(), "customSlot.confirmation"); assertEquals(slot.getPrompts().getElicitation(), "customSlot.elicitation"); assertEquals( model.getPrompts().stream().filter(p -> p.getId().equals("customSlot.confirmation")).findFirst().get().getVariations(), Collections.singletonList(PromptVariation.builder().withType("PlainText").withValue("test_en_US customSlot confirmation").build())); assertEquals( model.getPrompts().stream().filter(p -> p.getId().equals("customSlot.elicitation")).findFirst().get().getVariations(), Collections.singletonList(PromptVariation.builder().withType("PlainText").withValue("test_en_US customSlot elicitation").build())); }
@Test(expected = IllegalArgumentException.class) public void testMissingInvocationName() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .build(); underTest.render(skill, Locales.de_DE); }
@Test public void testRepeatedIncludes() { SkillModel skill = SkillModel.builder() .withInvocationName(Locales.en_US, "en_US") .addModel(Model.builder() .intent(TestIntentInherit.class) .build()) .build(); InteractionModel model = underTest.render(skill, Locales.en_US); Intent intent = model.getLanguageModel().getIntents().stream().findFirst().get(); assertEquals(Arrays.asList("merged", "merged2", "test_en_US"), intent.getSamples()); }