/** Adds an empty action to the dialogue system to start the interaction. */ @Override public void start() { Assignment emptyAction = new Assignment(system.getSettings().systemOutput, ValueFactory.none()); if (system.isPaused()) { system.getState().addToState(emptyAction); } else { system.addContent(emptyAction); } system.attachModule(RewardLearner.class); }
private void performTurn() { DialogueState systemState = system.getState(); final String outputVar = system.getSettings().systemOutput; try { Value systemAction = ValueFactory.none(); if (systemState.hasChanceNode(outputVar)) { systemAction = systemState.queryProb(outputVar).getBest(); } log.fine("Simulator input: " + systemAction); boolean turnPerformed = performTurn(systemAction); int repeat = 0; while (!turnPerformed && repeat < 5 && system.getModules().contains(this)) { turnPerformed = performTurn(systemAction); repeat++; } } catch (RuntimeException e) { log.fine("cannot update simulator: " + e); } }
// @Test public void parsingTest() throws InterruptedException { DialogueSystem system = new DialogueSystem(XMLDomainReader.extractDomain(DOMAIN_FILE)); system.getSettings().showGUI = false; system.getSettings().params.setProperty("taggingmodel", TAGGING_MODEL); system.getSettings().params.setProperty("parsingmodel", PARSING_MODEL); system.attachModule(MaltParser.class); system.startSystem(); system.addUserInput("move to the left"); assertTrue(system.getState().hasChanceNode("parse(u_u)")); assertTrue(system.getState().hasChanceNode("a_u")); assertEquals(system.getContent("a_u").toDiscrete().getBest().toString(), "Move(left)"); system.addUserInput("what do you see now?"); assertTrue(system.getState().hasChanceNode("parse(u_u)")); assertEquals(system.getContent("a_u").toDiscrete().getBest().toString(), "Move(left)"); Map<String, Double> table = new HashMap<String, Double>(); table.put("move a little bit to the left", 0.7); table.put("move a bit to the left", 0.1); system.addUserInput(table); assertTrue(system.getState().hasChanceNode("parse(u_u)")); assertTrue(system.getState().hasChanceNode("a_u")); assertEquals(system.getContent("a_u").toDiscrete().getProb("Move(left)"), 0.8, 0.01); table = new HashMap<String, Double>(); table.put("now move a bit to the right please", 0.6); system.addUserInput(table); assertTrue(system.getState().hasChanceNode("parse(u_u)")); assertTrue(system.getState().hasChanceNode("a_u")); assertEquals(system.getContent("a_u").toDiscrete().getProb("Move(right)"), 0.6, 0.01); ParseValue pv = (ParseValue) system .getContent("parse(u_u)") .getValues() .stream() .filter(v -> v instanceof ParseValue) .findFirst() .get(); assertTrue(pv.contains(ValueFactory.create("TO DT JJ"))); assertFalse(pv.contains(ValueFactory.create("DT TT JJ"))); assertTrue(pv.contains(ValueFactory.create("(*,the,*,det,7)"))); assertTrue(pv.contains(ValueFactory.create("(7,*,JJ,*,*)"))); assertTrue(pv.contains(ValueFactory.create("(*,*,DT,det,7)"))); assertTrue(pv.contains(ValueFactory.create("(7,right,*,*,*)"))); assertFalse(pv.contains(ValueFactory.create("(7,left,*,*,*)"))); assertTrue(pv.contains(ValueFactory.create("TO the JJ"))); assertTrue(pv.contains(ValueFactory.create("to the JJ"))); assertTrue(pv.contains(ValueFactory.create("TO DT right"))); assertFalse(pv.contains(ValueFactory.create("TO DT left"))); assertTrue(pv.contains(ValueFactory.create("to/TO the/DT right/JJ"))); assertFalse(pv.contains(ValueFactory.create("to/JJ the/DT right/JJ"))); assertTrue(pv.contains(ValueFactory.create("(*,the,DT,det,7)"))); assertTrue(pv.contains(ValueFactory.create("(7,right,JJ,*,*)"))); assertTrue(pv.contains(ValueFactory.create("JJ"))); assertFalse(pv.contains(ValueFactory.create("RBR"))); table = new HashMap<String, Double>(); table.put("this is a gnome", 0.6); system.addUserInput(table); pv = (ParseValue) system .getContent("parse(u_u)") .getValues() .stream() .filter(v -> v instanceof ParseValue) .findFirst() .get(); assertTrue(pv.contains(ValueFactory.create("DT VBZ DT NN"))); assertEquals("Test successful", system.getContent("i_u").getBest().toString()); }