@Test void applyAnnotators() { Parser p = new Parser(null, null, Collections.singletonList(PhraseAnnotator.INSTANCE)); Parser.Chart chart = p.new Chart(10); List<String> tokens = Arrays.asList("A", "B", "C"); Rule r = PhraseAnnotator.INSTANCE.annotate(tokens).get(0); p.applyAnnotators(chart, tokens, 0, 3); assertEquals(r, chart.getDerivations(0, 3).get(0).rule); }
void applyAnnotators(Chart chart, List<String> tokens, int start, int end) { for(Annotator annotator: annotators) { for(Rule rule: annotator.annotate(tokens.subList(start, end))) { if(chart.isSpanFull(start, end)) return; chart.addDerivation(start, end, new Derivation(rule, null)); } } }
Parser { void applyAnnotators(Chart chart, List<String> tokens, int start, int end) { for(Annotator annotator: annotators) { for(Rule rule: annotator.annotate(tokens.subList(start, end))) { if(chart.isSpanFull(start, end)) return; chart.addDerivation(start, end, new Derivation(rule, null)); } } } }
Parser { void applyAnnotators(Chart chart, List<String> tokens, int start, int end) { for(Annotator annotator: annotators) { for(Rule rule: annotator.annotate(tokens.subList(start, end))) { if(chart.isSpanFull(start, end)) return; chart.addDerivation(start, end, new Derivation(rule, null)); } } } Parser(Grammar grammar, Tokenizer tokenizer, List<Annotator> annotators); }
Parser { void applyAnnotators(Chart chart, List<String> tokens, int start, int end) { for(Annotator annotator: annotators) { for(Rule rule: annotator.annotate(tokens.subList(start, end))) { if(chart.isSpanFull(start, end)) return; chart.addDerivation(start, end, new Derivation(rule, null)); } } } 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); }
Parser { void applyAnnotators(Chart chart, List<String> tokens, int start, int end) { for(Annotator annotator: annotators) { for(Rule rule: annotator.annotate(tokens.subList(start, end))) { if(chart.isSpanFull(start, end)) return; chart.addDerivation(start, end, new Derivation(rule, null)); } } } 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);  }