bug fixes for deriving empty formula

This commit is contained in:
Sida Wang 2017-01-29 00:40:49 -08:00
parent 0b52931789
commit ce23b45066
2 changed files with 15 additions and 4 deletions

View File

@ -116,7 +116,7 @@ public final class ILUtils {
String formula = pair.get(1);
if (formula.equals("()")) {
LogInfo.error("Got empty formula");
LogInfo.logs("Error: Got empty formula");
continue;
}
@ -130,20 +130,29 @@ public final class ILUtils {
parser.parse(params, ex, false);
boolean found = false;
Formula targetFormula = Formulas.fromLispTree(LispTree.proto.parseFromString(formula));
for (Derivation d : ex.predDerivations) {
// LogInfo.logs("considering: %s", d.formula.toString());
if (d.formula.equals(Formulas.fromLispTree(LispTree.proto.parseFromString(formula)))) {
if (d.formula.equals(targetFormula)) {
found = true;
allDerivs.add(stripDerivation(d));
}
}
if (!found && !formula.equals("?"))
LogInfo.logs("Error: matching formula not found: %s", formula);
LogInfo.logs("Error: matching formula not found (useBest :s): %s", formula, Boolean.toString(opts.useBestFormula));
// just making testing easier, use top derivation when we formula is not
// given
if (!found && ex.predDerivations.size() > 0 && (formula.equals("?") || formula == null || opts.useBestFormula))
allDerivs.add(stripDerivation(ex.predDerivations.get(0)));
else if (!found) {
Derivation res = new Derivation.Builder().formula(targetFormula)
// setting start to -1 is important,
// which grammarInducer interprets to mean we do not want partial rules
.withCallable(new SemanticFn.CallInfo("$Action", -1, -1, null, new ArrayList<>()))
.createDerivation();
allDerivs.add(res);
}
}
return allDerivs;
}

View File

@ -249,7 +249,9 @@ public class GrammarInducer {
List<Derivation> args = deriv.children;
// cant use the standard DerivationStream because formula is final
if (rule.sem instanceof ApplyFn) {
if (rule == null || rule.sem == null) {
deriv.grammarInfo.formula = deriv.formula;
} else if (rule.sem instanceof ApplyFn) {
Formula f = Formulas.fromLispTree(((ApplyFn)rule.sem).formula.toLispTree());
for (Derivation arg : args) {
if (!(f instanceof LambdaFormula))