@Test void parseSyntactic() { Rule r1 = new Rule("$A", "a"); Rule r2 = new Rule("$B", "b"); Rule r3 = new Rule("$C", "$A $B"); Grammar grammar = new Grammar(Arrays.asList(r1, r2, r3), "$C"); Parser p = new Parser(grammar, s -> Arrays.asList(s.split(" ")), Collections.emptyList()); Derivation dc1 = new Derivation(r1, null); Derivation dc2 = new Derivation(r2, null); Derivation expected = new Derivation(r3, Arrays.asList(dc1, dc2)); Derivation actual = p.parseSyntactic("a b").get(0); assertEquals(expected.rule, actual.rule); assertEquals(expected.children.get(0).rule, actual.children.get(0).rule); assertEquals(expected.children.get(1).rule, actual.children.get(1).rule); }
public List<Derivation> parseSyntactic(String input){ List<String> tokens = tokenizer.tokenize(input); List<String> tokensLower = new ArrayList<>(tokens.size()); for(String token: tokens) tokensLower.add(token.toLowerCase()); int N = tokens.size(); Chart chart = new Chart(N+1); for(int e = 1; e <= N; e++) { for(int s = e-1; s >= 0; s--) { applyAnnotators(chart, tokens, s, e); applyLexicalRules(chart, tokensLower, s, e); applyBinaryRules(chart, s, e); applyUnaryRules(chart, s, e); } } List<Derivation> derivations = new LinkedList<>(); for(Derivation d: chart.getDerivations(0, N)) if(grammar.isRoot(d.rule)) derivations.add(d); return derivations; }
Parser { public List<Derivation> parseSyntactic(String input){ List<String> tokens = tokenizer.tokenize(input); List<String> tokensLower = new ArrayList<>(tokens.size()); for(String token: tokens) tokensLower.add(token.toLowerCase()); int N = tokens.size(); Chart chart = new Chart(N+1); for(int e = 1; e <= N; e++) { for(int s = e-1; s >= 0; s--) { applyAnnotators(chart, tokens, s, e); applyLexicalRules(chart, tokensLower, s, e); applyBinaryRules(chart, s, e); applyUnaryRules(chart, s, e); } } List<Derivation> derivations = new LinkedList<>(); for(Derivation d: chart.getDerivations(0, N)) if(grammar.isRoot(d.rule)) derivations.add(d); return derivations; } }
Parser { public List<Derivation> parseSyntactic(String input){ List<String> tokens = tokenizer.tokenize(input); List<String> tokensLower = new ArrayList<>(tokens.size()); for(String token: tokens) tokensLower.add(token.toLowerCase()); int N = tokens.size(); Chart chart = new Chart(N+1); for(int e = 1; e <= N; e++) { for(int s = e-1; s >= 0; s--) { applyAnnotators(chart, tokens, s, e); applyLexicalRules(chart, tokensLower, s, e); applyBinaryRules(chart, s, e); applyUnaryRules(chart, s, e); } } List<Derivation> derivations = new LinkedList<>(); for(Derivation d: chart.getDerivations(0, N)) if(grammar.isRoot(d.rule)) derivations.add(d); return derivations; } Parser(Grammar grammar, Tokenizer tokenizer, List<Annotator> annotators); }
Parser { public List<Derivation> parseSyntactic(String input){ List<String> tokens = tokenizer.tokenize(input); List<String> tokensLower = new ArrayList<>(tokens.size()); for(String token: tokens) tokensLower.add(token.toLowerCase()); int N = tokens.size(); Chart chart = new Chart(N+1); for(int e = 1; e <= N; e++) { for(int s = e-1; s >= 0; s--) { applyAnnotators(chart, tokens, s, e); applyLexicalRules(chart, tokensLower, s, e); applyBinaryRules(chart, s, e); applyUnaryRules(chart, s, e); } } List<Derivation> derivations = new LinkedList<>(); for(Derivation d: chart.getDerivations(0, N)) if(grammar.isRoot(d.rule)) derivations.add(d); return derivations; } 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<Derivation> parseSyntactic(String input){ List<String> tokens = tokenizer.tokenize(input); List<String> tokensLower = new ArrayList<>(tokens.size()); for(String token: tokens) tokensLower.add(token.toLowerCase()); int N = tokens.size(); Chart chart = new Chart(N+1); for(int e = 1; e <= N; e++) { for(int s = e-1; s >= 0; s--) { applyAnnotators(chart, tokens, s, e); applyLexicalRules(chart, tokensLower, s, e); applyBinaryRules(chart, s, e); applyUnaryRules(chart, s, e); } } List<Derivation> derivations = new LinkedList<>(); for(Derivation d: chart.getDerivations(0, N)) if(grammar.isRoot(d.rule)) derivations.add(d); return derivations; } 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);  }