add action formula to core

This commit is contained in:
Sida Wang 2017-03-17 16:02:55 -07:00
parent 9f08f21633
commit 341d27a363
13 changed files with 13 additions and 52 deletions

View File

@ -10,4 +10,5 @@ potentially reset citation and grammar information as well?
Default port: 8410 for sempre, 8406 for user
Run: ./run @mode=interactive -Server.port 8410
Test command : ./run @mode=test @class=interactive.actions.ActionExecutorTest -verbose 5
Test command : .shrdlurn/run @mode=test @class=interactive.test.ActionExecutorTest -verbose 5
Test command : .shrdlurn/run @mode=test -verbose 5

View File

@ -175,7 +175,7 @@ nil)})
############################################################
# {2016-07-02} [Sida Wang]: interactive semantic parsing
addMode('interactive', 'interactive semantic parsing in a blocksworld', lambda { |e| l(
addMode('interactive', 'interactive semantic parsing in a VoxelWorld', lambda { |e| l(
#rlwrap,
header('core,interactive'),
'edu.stanford.nlp.sempre.Main',
@ -185,7 +185,7 @@ addMode('interactive', 'interactive semantic parsing in a blocksworld', lambda {
o('LanguageAnalyzer', 'interactive.ActionLanguageAnalyzer'),
o('ActionExecutor.convertNumberValues', true),
o('ActionExecutor.printStackTrace', true),
o('BlocksWorld.maxBlocks', 3000),
o('VoxelWorld.maxBlocks', 3000),
selo(0, 'ActionExecutor.FlatWorldType', 'BlocksWorld', 'CalendarWorld'),
selo(0, 'Grammar.inPaths', './shrdlurn/blocksworld.grammar', './shrdlurn/calendar.grammar'),

View File

@ -1,9 +1,8 @@
package edu.stanford.nlp.sempre.interactive;
package edu.stanford.nlp.sempre;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import edu.stanford.nlp.sempre.Formula;
import edu.stanford.nlp.sempre.Formulas;
import fig.basic.LispTree;
import fig.basic.LogInfo;

View File

@ -3,7 +3,6 @@ package edu.stanford.nlp.sempre;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import edu.stanford.nlp.sempre.interactive.ActionFormula;
import fig.basic.LispTree;
import java.util.HashSet;

View File

@ -22,7 +22,6 @@ import org.testng.collections.Lists;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import edu.stanford.nlp.sempre.interactive.ActionFormula;
import edu.stanford.nlp.sempre.interactive.BadInteractionException;
import edu.stanford.nlp.sempre.interactive.BlockFn;
import edu.stanford.nlp.sempre.interactive.DefinitionAligner;
@ -143,7 +142,7 @@ public final class ILUtils {
}
}
if (!found && !formula.equals("?"))
LogInfo.logs("Error: matching formula not found (useBest :s): %s", formula, Boolean.toString(opts.useBestFormula));
LogInfo.errors("matching formula not found: %s :: %s", utt, formula);
// just making testing easier, use top derivation when we formula is not
// given

View File

@ -206,8 +206,6 @@ public class Learner {
Execution.putOutput("example", e);
ParserState state = parseExample(params, ex, computeExpectedCounts);
// training for definitions for interative stuff
addToAutocomplete(ex, params);
if (computeExpectedCounts) {
if (opts.checkGradient) {
@ -368,15 +366,4 @@ public class Learner {
eventsOut.println(Joiner.on('\t').join(fields));
eventsOut.flush();
}
public static boolean addToAutocomplete(Example ex, Params params) {
int num = ex.predDerivations.size();
// i guess or if it's in core
if (num > 0) {
params.autocompleteTrie.add(ex.getTokens());
LogInfo.logs("added %s to trie %s", ex.getTokens(), params.autocompleteTrie.toLispTree(1));
return true;
}
return false;
}
}

View File

@ -7,7 +7,6 @@ import com.google.common.collect.Lists;
import edu.stanford.nlp.sempre.interactive.BadInteractionException;
import edu.stanford.nlp.sempre.interactive.CitationTracker;
import edu.stanford.nlp.sempre.interactive.GrammarInducer;
import edu.stanford.nlp.sempre.interactive.PrefixTrie;
import fig.basic.*;
import jline.console.ConsoleReader;
@ -264,7 +263,6 @@ public class Master {
// Parse!
ParserState state;
state = builder.parser.parse(builder.params, ex, false);
Learner.addToAutocomplete(ex, builder.params);
response.ex = ex;
ex.logWithoutContext();
@ -580,20 +578,6 @@ public class Master {
}
out.close();
LogInfo.logs("Done printing and overriding grammar and parameters...");
} else if (command.equals(":autocomplete")) {
if (tree.children.size() == 2) {
String prefix = tree.children.get(1).value;
LogInfo.logs("Getting autocomplete for prefix: %s", prefix);
List<String> prefixTokens = LanguageAnalyzer.getSingleton().analyze(prefix).tokens;
PrefixTrie trieMatch = builder.params.autocompleteTrie.traverse(prefixTokens);
if (trieMatch != null)
response.lines = trieMatch.getRandomMatches(opts.autocompleteCount);
else
response.lines = Lists.newArrayList();
LogInfo.logs("%d options are %s", opts.autocompleteCount, response.lines);
} else {
LogInfo.logs("autocomplete just takes a prefix");
}
} else if (command.equals(":action")) {
// test code for mutating worlds, updates the context
String query = tree.children.get(1).value;

View File

@ -3,8 +3,6 @@ package edu.stanford.nlp.sempre;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import edu.stanford.nlp.sempre.interactive.PragmaticListener;
import edu.stanford.nlp.sempre.interactive.PrefixTrie;
import fig.basic.*;
import java.io.BufferedReader;
@ -38,12 +36,7 @@ public class Params {
@Option(gloss = "Lazy L1 full update frequency") public int lazyL1FullUpdateFreq = 5000;
}
public static Options opts = new Options();
// interactive stuff, stores the autocomplete trie
public PragmaticListener pragmaticListener = new PragmaticListener();
public PrefixTrie autocompleteTrie = new PrefixTrie();
public List<Rule> inducedRules = new ArrayList<>();
public enum L1Reg {
LAZY,

View File

@ -4,8 +4,6 @@ import fig.basic.*;
import java.util.*;
import edu.stanford.nlp.sempre.interactive.ActionFormula;
/**
* Performs type inference: given a Formula, return a SemType.
*

View File

@ -5,6 +5,7 @@ import java.util.stream.Collectors;
import org.testng.collections.Lists;
import edu.stanford.nlp.sempre.ActionFormula;
import edu.stanford.nlp.sempre.Derivation;
import edu.stanford.nlp.sempre.DerivationStream;
import edu.stanford.nlp.sempre.Example;

View File

@ -14,6 +14,7 @@ import org.testng.collections.Sets;
import com.beust.jcommander.internal.Lists;
import com.google.common.base.Function;
import edu.stanford.nlp.sempre.ActionFormula;
import edu.stanford.nlp.sempre.ConstantFn;
import edu.stanford.nlp.sempre.Derivation;
import edu.stanford.nlp.sempre.Example;

View File

@ -37,7 +37,7 @@ import fig.basic.Evaluation;
public class Simulator implements Runnable {
@Option public static String serverURL = "http://localhost:8410";
@Option public static int numThreads = 4;
@Option public static int numThreads = 1;
@Option public static int verbose = 1;
@Option public static String reqParams = "grammar=0&cite=0&learn=0";
@Option public static List<String> logFiles = Lists.newArrayList("./shrdlurn/commandInputs/sidaw.json.log");
@ -47,7 +47,7 @@ public class Simulator implements Runnable {
//T.printAllRules();
//A.assertAll();
for (String fileName : logFiles) {
ExecutorService executor = new ThreadPoolExecutor(JsonServer.opts.numThreads, JsonServer.opts.numThreads,
ExecutorService executor = new ThreadPoolExecutor(numThreads, numThreads,
5000, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
@ -99,7 +99,7 @@ public class Simulator implements Runnable {
SimulationAnalyzer.flush();
LogInfo.end_track();
try {
sempreQuery("(:admin withcrappysecurity)", "simulator");
sempreQuery("(:admin withcrappysecurityWRONG)", "simulator");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@ -9,12 +9,11 @@ import java.util.function.Predicate;
import fig.basic.*;
import edu.stanford.nlp.sempre.*;
import edu.stanford.nlp.sempre.ActionFormula.Mode;
import edu.stanford.nlp.sempre.Parser.Spec;
import edu.stanford.nlp.sempre.interactive.ActionExecutor;
import edu.stanford.nlp.sempre.interactive.ActionFormula;
import edu.stanford.nlp.sempre.interactive.DefinitionAligner;
import edu.stanford.nlp.sempre.interactive.GrammarInducer;
import edu.stanford.nlp.sempre.interactive.ActionFormula.Mode;
import edu.stanford.nlp.sempre.interactive.DefinitionAligner.Strategies;
import org.testng.Assert;