public boolean isCategorial() { for(String item: rhs) if(!isCat(item)) return false; return true; }
public LogicalForm(Derivation derivation, Map<String, Object> map) { this.derivation = derivation; this.map = map; fields = fields(map); score = derivation.score; }
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; //System.out.println(rule); Derivation parent = new Derivation(rule, Collections.singletonList(d)); queue.addLast(parent); chart.addDerivation(start, end, parent); } } }
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)); } } }
void applyLexicalRules(Chart chart, List<String> tokens, int start, int end) { for(Rule rule: grammar.getLexicalRules(tokens.subList(start, end))) { chart.addDerivation(start, end, new Derivation(rule, null)); } }
public LogicalForm computeLogicalForm(Derivation d){ LogicalForm lf = new LogicalForm(d, applySemantics(d).get(0)); lf.updateScore(weights); return lf; }
public Rule(String lhs, String rhs, Map<String, Object> semantics) { this(lhs, rhs); this.semantics = SemanticUtils.parseTemplate(semantics); }
public Rule(String lhs, String rhs, String semantics) { this(lhs, rhs); this.semantics = SemanticUtils.parseSemantics(semantics); }
public static ChainMap<String, Object> value(Object value){ return named(KEY_UNNAMED, value); }
public boolean isBinary() { return rhs.size() == 2; }
public Rule(String lhs, StringTuple rhs) { this.lhs = lhs; this.rhs = rhs; validate(); }
public boolean hasOptionals() { for(String item: rhs) if(isOptional(item)) return true; return false; }
public ChainMap<K, V> named(K name, V value){ put(name, value); return this; } }
public Model(Parser parser){ this.parser = parser; weights = parser.getWeights(); }
public StringTuple(String s){ this(s, stringToItems(s)); }
public boolean isUnary() { return rhs.size() == 1; }