### Question:
Parser { void applyUnaryRules(Chart chart, int start, int end) { LinkedList<Derivation> queue = new LinkedList<>(chart.getDerivations(start, end)); while(!queue.isEmpty()) { Derivation d = queue.removeFirst(); for(Rule rule: grammar.getUnaryRules(d.rule.getLHS())) { if(chart.isSpanFull(start, end)) return; Derivation parent = new Derivation(rule, Collections.singletonList(d)); queue.addLast(parent); chart.addDerivation(start, end, parent); } } } Parser(Grammar grammar, Tokenizer tokenizer, List<Annotator> annotators); Map<String, Float> getWeights(); void setWeights(Map<String, Float> weights); List<Derivation> parseSyntactic(String input); List<LogicalForm> parse(String input); LogicalForm computeLogicalForm(Derivation d);  }### Answer:
@Test void applyUnaryRules() { List<Rule> rules = Arrays.asList( new Rule("$F", "$E"), new Rule("$E", "$D")); Grammar grammar = new Grammar(rules, "$ROOT"); Parser p = new Parser(grammar, null, null); Parser.Chart chart = p.new Chart(10); chart.addDerivation(1, 3, new Derivation(new Rule("$D", "$B $C"), null)); p.applyUnaryRules(chart, 1, 3); assertEquals(3, chart.getDerivations(1, 3).size()); assertEquals(rules.get(0), chart.getDerivations(1, 3).get(2).rule); assertEquals(rules.get(1), chart.getDerivations(1, 3).get(1).rule); }