Make cprune less verbose

This commit is contained in:
Panupong Pasupat 2017-09-01 17:25:41 -07:00
parent 4c1bcffebd
commit 3ef45877f3
4 changed files with 20 additions and 7 deletions

View File

@ -5,6 +5,9 @@ import java.util.List;
import edu.stanford.nlp.sempre.*;
import fig.basic.LogInfo;
/**
* A parser that first tries to exploit the macro grammar and only fall back to full search when needed.
*/
public class CPruneFloatingParser extends FloatingParser {
FloatingParser exploreParser;
@ -105,9 +108,12 @@ class MiniGrammar extends Grammar {
public MiniGrammar(List<Rule> rules) {
this.rules.addAll(rules);
LogInfo.begin_track("MiniGrammar Rules");
for (Rule rule : rules) LogInfo.logs("%s %s", rule, rule.isAnchored() ? "[A]" : "[F]");
LogInfo.end_track();
if (CollaborativePruner.opts.verbose >= 2) {
LogInfo.begin_track("MiniGrammar Rules");
for (Rule rule : rules)
LogInfo.logs("%s %s", rule, rule.isAnchored() ? "[A]" : "[F]");
LogInfo.end_track();
}
}
}

View File

@ -11,6 +11,8 @@ import edu.stanford.nlp.sempre.*;
*/
public class CollaborativePruner {
public static class Options {
@Option(gloss = "Logging verbosity")
public int verbose = 0;
@Option(gloss = "K = Maximum number of nearest-neighbor examples to consider (-1 to use all examples so far)")
public int maxNumNeighbors = -1;
@Option(gloss = "Load cached neighbors from this file")

View File

@ -7,7 +7,7 @@ import fig.basic.*;
public class CustomGrammar extends Grammar {
public static class Options {
@Option
@Option(gloss = "Whether to decompose the templates into multiple rules")
public boolean enableTemplateDecomposition = true;
}
@ -125,7 +125,8 @@ public class CustomGrammar extends Grammar {
formula = formula.replace(target + " ", replacement + " ");
formula = formula.replace("(ARGMIN", "(argmin (number 1) (number 1)");
formula = formula.replace("(ARGMAX", "(argmax (number 1) (number 1)");
LogInfo.logs("REPLACE: [%s | %s] %s | %s", targetBefore, replacement, before, formula);
if (CollaborativePruner.opts.verbose >= 2)
LogInfo.logs("REPLACE: [%s | %s] %s | %s", targetBefore, replacement, before, formula);
return formula;
}

View File

@ -16,6 +16,7 @@ public class FormulaPattern implements Comparable<FormulaPattern> {
}
public Double complexity() {
// Roughly the number of predicates
return (double) (pattern.length() - pattern.replace("(@R", "***").replace("(", "").length());
}
@ -42,6 +43,7 @@ public class FormulaPattern implements Comparable<FormulaPattern> {
private static Pattern reverseRelation = Pattern.compile("!(fb:[._a-z0-9]+)");
private static Pattern varName = Pattern.compile("\\((lambda|var) [a-z0-9]+");
private static Pattern compare = Pattern.compile("(<=|>=|>|<)");
private static Pattern whitespace = Pattern.compile("\\s+");
public static String convertToIndexedPattern(Derivation deriv) {
String formula = deriv.formula.toString();
@ -58,10 +60,12 @@ public class FormulaPattern implements Comparable<FormulaPattern> {
formula = formula.replace("fb:row.row.index", "(reverse (lambda x ((reverse @index) (var x))))");
formula = formula.replace("fb:row.row.next", "@next");
formula = varName.matcher(formula).replaceAll("($1 x");
formula = formula.replaceAll("\\s+", " ");
formula = formula.replace("reverse", "@R");
formula = compare.matcher(formula).replaceAll("@compare");
LogInfo.logs("PATTERN: %s -> %s", deriv.formula, formula);
formula = whitespace.matcher(formula).replaceAll(" ");
if (CollaborativePruner.opts.verbose >= 2)
LogInfo.logs("PATTERN: %s -> %s", deriv.formula, formula);
return formula;
}