@Test void parse() { List<Rule> rules = Arrays.asList( new Rule("$A", "a"), new Rule("$B", "b"), new Rule("$C", "$A $B", "{e:@first, f:@last}") ); Grammar grammar = new Grammar(rules, "$C"); Parser p = new Parser(grammar, s -> Arrays.asList(s.split(" ")), Collections.emptyList()); Map<String, Object> expected = new HashMap<String, Object>(){{ put("e", "a"); put("f", "b"); }}; List<LogicalForm> actual = p.parse("a b"); assertEquals(1, actual.size()); assertEquals(expected, actual.get(0).getMap()); }
public List<LogicalForm> parse(String input) { List<LogicalForm> lfs = new ArrayList<>(); for(Derivation d: parseSyntactic(input)) lfs.add(computeLogicalForm(d)); Collections.sort(lfs, Collections.reverseOrder()); return lfs; }
Parser { public List<LogicalForm> parse(String input) { List<LogicalForm> lfs = new ArrayList<>(); for(Derivation d: parseSyntactic(input)) lfs.add(computeLogicalForm(d)); Collections.sort(lfs, Collections.reverseOrder()); return lfs; } }
Parser { public List<LogicalForm> parse(String input) { List<LogicalForm> lfs = new ArrayList<>(); for(Derivation d: parseSyntactic(input)) lfs.add(computeLogicalForm(d)); Collections.sort(lfs, Collections.reverseOrder()); return lfs; } Parser(Grammar grammar, Tokenizer tokenizer, List<Annotator> annotators); }
Parser { public List<LogicalForm> parse(String input) { List<LogicalForm> lfs = new ArrayList<>(); for(Derivation d: parseSyntactic(input)) lfs.add(computeLogicalForm(d)); Collections.sort(lfs, Collections.reverseOrder()); return lfs; } 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 { public List<LogicalForm> parse(String input) { List<LogicalForm> lfs = new ArrayList<>(); for(Derivation d: parseSyntactic(input)) lfs.add(computeLogicalForm(d)); Collections.sort(lfs, Collections.reverseOrder()); return lfs; } 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);  }