mirror of https://github.com/percyliang/sempre
exclude my tests in main
This commit is contained in:
parent
4c765362d0
commit
068bdbfcac
|
|
@ -1,5 +1,6 @@
|
||||||
package edu.stanford.nlp.sempre;
|
package edu.stanford.nlp.sempre;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ public class JavaExecutor extends Executor {
|
||||||
@Option(gloss = "Formula in the grammar whose name startsWith contextPrefix is context sensitive")
|
@Option(gloss = "Formula in the grammar whose name startsWith contextPrefix is context sensitive")
|
||||||
public String contextPrefix = "context:";
|
public String contextPrefix = "context:";
|
||||||
@Option(gloss = "Reduce verbosity by automatically appending, for example, edu.stanford.nlp.sempre to java calls")
|
@Option(gloss = "Reduce verbosity by automatically appending, for example, edu.stanford.nlp.sempre to java calls")
|
||||||
public String classPathPrefix = "edu.stanford.nlp.sempre";
|
public String classPathPrefix = ""; // e.g. "edu.stanford.nlp.sempre";
|
||||||
}
|
}
|
||||||
public static Options opts = new Options();
|
public static Options opts = new Options();
|
||||||
|
|
||||||
|
|
@ -194,7 +195,7 @@ public class JavaExecutor extends Executor {
|
||||||
id = MapUtils.get(shortcuts, id, id);
|
id = MapUtils.get(shortcuts, id, id);
|
||||||
|
|
||||||
// classPathPrefix, like edu.stanford.nlp.sempre.interactive
|
// classPathPrefix, like edu.stanford.nlp.sempre.interactive
|
||||||
if (opts.classPathPrefix != "" && !id.startsWith(".") && !id.startsWith(opts.classPathPrefix)) {
|
if (!Strings.isNullOrEmpty(opts.classPathPrefix) && !id.startsWith(".") && !id.startsWith(opts.classPathPrefix)) {
|
||||||
id = opts.classPathPrefix + "." + id;
|
id = opts.classPathPrefix + "." + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public class Rule {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (stringRepn == null) {
|
if (stringRepn == null) {
|
||||||
|
if (sem == null) return "NoSemanticFunction";
|
||||||
String semStr = sem.toString();
|
String semStr = sem.toString();
|
||||||
// stop printing very long rules
|
// stop printing very long rules
|
||||||
int maxLength = 100;
|
int maxLength = 100;
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,31 @@
|
||||||
package edu.stanford.nlp.sempre.interactive.test;
|
package edu.stanford.nlp.sempre.interactive.test;
|
||||||
|
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
import java.util.Set;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import fig.basic.*;
|
|
||||||
import edu.stanford.nlp.sempre.*;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.ActionExecutor;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.World;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.Item;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.voxelurn.Color;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.voxelurn.Voxel;
|
|
||||||
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import edu.stanford.nlp.sempre.ContextValue;
|
||||||
|
import edu.stanford.nlp.sempre.Executor;
|
||||||
|
import edu.stanford.nlp.sempre.Formulas;
|
||||||
|
import edu.stanford.nlp.sempre.Json;
|
||||||
|
import edu.stanford.nlp.sempre.NaiveKnowledgeGraph;
|
||||||
|
import edu.stanford.nlp.sempre.StringValue;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.ActionExecutor;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.Item;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.World;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.voxelurn.Color;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.voxelurn.Voxel;
|
||||||
|
import fig.basic.LispTree;
|
||||||
|
import fig.basic.LogInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the ActionExecutor
|
* Test the ActionExecutor
|
||||||
* @author Sida Wang
|
* @author Sida Wang
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ActionExecutorTest {
|
public class ActionExecutorTest {
|
||||||
ActionExecutor executor = new ActionExecutor();
|
ActionExecutor executor = new ActionExecutor();
|
||||||
|
|
||||||
|
|
@ -54,7 +59,8 @@ public class ActionExecutorTest {
|
||||||
return x -> {LogInfo.logs("Got %d, expected %d", x.selected().size(), n); return x.selected().size()==n;};
|
return x -> {LogInfo.logs("Got %d, expected %d", x.selected().size(), n); return x.selected().size()==n;};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testJoin() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testJoin() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testJoin");
|
LogInfo.begin_track("testJoin");
|
||||||
|
|
@ -71,7 +77,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test public void testSpecialSets() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testSpecialSets() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,2,1,\"Blue\",[\"S\"]],[2,2,1,\"Red\",[\"S\"]],[2,2,2,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,2,1,\"Blue\",[\"S\"]],[2,2,1,\"Red\",[\"S\"]],[2,2,2,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testSpecial");
|
LogInfo.begin_track("testSpecial");
|
||||||
|
|
@ -84,7 +91,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testMerge() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testMerge() {
|
||||||
{
|
{
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[2,2,2,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[2,2,2,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -96,7 +104,8 @@ public class ActionExecutorTest {
|
||||||
}
|
}
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
@Test public void testBasicActions() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testBasicActions() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[2,2,3,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[2,2,3,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testBasicActions");
|
LogInfo.begin_track("testBasicActions");
|
||||||
|
|
@ -116,7 +125,8 @@ public class ActionExecutorTest {
|
||||||
private Set<Item> real(Set<Item> all) {
|
private Set<Item> real(Set<Item> all) {
|
||||||
return all.stream().filter(c -> ((Voxel)c).color != Color.Fake).collect(Collectors.toSet());
|
return all.stream().filter(c -> ((Voxel)c).color != Color.Fake).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
@Test public void testRemove() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testRemove() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[\"S\"]],[1,1,3,\"Red\",[\"S\"]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[\"S\"]],[1,1,3,\"Red\",[\"S\"]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -131,7 +141,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testMoreActions() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testMoreActions() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -147,7 +158,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void troubleCases() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void troubleCases() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -159,7 +171,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testFake() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testFake() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,0,\"Fake\",[\"S\"]]]";
|
String defaultBlocks = "[[1,1,0,\"Fake\",[\"S\"]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -174,7 +187,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testIsolation() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testIsolation() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
@ -186,7 +200,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testUpdate() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testUpdate() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Red\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Red\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testUpdate");
|
LogInfo.begin_track("testUpdate");
|
||||||
|
|
@ -197,7 +212,8 @@ public class ActionExecutorTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testScoping() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void testScoping() {
|
||||||
// this is a green stick
|
// this is a green stick
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import org.testng.collections.Lists;
|
||||||
* Test the parser, and some floating examples
|
* Test the parser, and some floating examples
|
||||||
* @author Sida Wang
|
* @author Sida Wang
|
||||||
*/
|
*/
|
||||||
|
@Test(groups = { "InteractiveLearning" })
|
||||||
public class FloatingParsingTest {
|
public class FloatingParsingTest {
|
||||||
Predicate<Example> contains(String formula) {
|
Predicate<Example> contains(String formula) {
|
||||||
Formula answer = Formulas.fromLispTree(LispTree.proto.parseFromString(formula));
|
Formula answer = Formulas.fromLispTree(LispTree.proto.parseFromString(formula));
|
||||||
|
|
@ -96,7 +97,7 @@ public class FloatingParsingTest {
|
||||||
return ContextValue.fromString(String.format("(context (graph NaiveKnowledgeGraph ((string \"%s\") (name b) (name c))))", strigify2));
|
return ContextValue.fromString(String.format("(context (graph NaiveKnowledgeGraph ((string \"%s\") (name b) (name c))))", strigify2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void basicTest() {
|
public void basicTest() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testJoin");
|
LogInfo.begin_track("testJoin");
|
||||||
|
|
@ -115,7 +116,7 @@ public class FloatingParsingTest {
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void advanced() {
|
public void advanced() {
|
||||||
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,2,1,\"Blue\",[]],[2,2,1,\"Red\",[]],[3,2,2,\"Yellow\",[]]]";
|
||||||
ContextValue context = getContext(defaultBlocks);
|
ContextValue context = getContext(defaultBlocks);
|
||||||
LogInfo.begin_track("testJoin");
|
LogInfo.begin_track("testJoin");
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,38 @@
|
||||||
package edu.stanford.nlp.sempre.interactive.test;
|
package edu.stanford.nlp.sempre.interactive.test;
|
||||||
|
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
|
||||||
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.DefinitionAligner;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.GrammarInducer;
|
|
||||||
import edu.stanford.nlp.sempre.interactive.DefinitionAligner.Strategies;
|
|
||||||
|
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.asserts.SoftAssert;
|
|
||||||
import org.testng.asserts.Assertion;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.asserts.Assertion;
|
||||||
|
import org.testng.asserts.SoftAssert;
|
||||||
import org.testng.collections.Lists;
|
import org.testng.collections.Lists;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import edu.stanford.nlp.sempre.ActionFormula;
|
||||||
|
import edu.stanford.nlp.sempre.BeamFloatingParser;
|
||||||
|
import edu.stanford.nlp.sempre.Derivation;
|
||||||
|
import edu.stanford.nlp.sempre.ExactValueEvaluator;
|
||||||
|
import edu.stanford.nlp.sempre.Example;
|
||||||
|
import edu.stanford.nlp.sempre.FeatureExtractor;
|
||||||
|
import edu.stanford.nlp.sempre.FloatingParser;
|
||||||
|
import edu.stanford.nlp.sempre.Grammar;
|
||||||
|
import edu.stanford.nlp.sempre.ILUtils;
|
||||||
|
import edu.stanford.nlp.sempre.Json;
|
||||||
|
import edu.stanford.nlp.sempre.LanguageAnalyzer;
|
||||||
|
import edu.stanford.nlp.sempre.Params;
|
||||||
|
import edu.stanford.nlp.sempre.Parser;
|
||||||
|
import edu.stanford.nlp.sempre.Parser.Spec;
|
||||||
|
import edu.stanford.nlp.sempre.ParserState;
|
||||||
|
import edu.stanford.nlp.sempre.Rule;
|
||||||
|
import edu.stanford.nlp.sempre.ValueEvaluator;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.ActionExecutor;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.DefinitionAligner;
|
||||||
|
import edu.stanford.nlp.sempre.interactive.GrammarInducer;
|
||||||
|
import fig.basic.LogInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the grammar induction
|
* Test the grammar induction
|
||||||
* @author Sida Wang
|
* @author Sida Wang
|
||||||
|
|
@ -31,33 +40,33 @@ import com.google.common.collect.Sets;
|
||||||
public class GrammarInducerTest {
|
public class GrammarInducerTest {
|
||||||
Assertion hard = new Assertion();
|
Assertion hard = new Assertion();
|
||||||
Assertion soft = new SoftAssert();
|
Assertion soft = new SoftAssert();
|
||||||
|
|
||||||
private static Spec defaultSpec() {
|
private static Spec defaultSpec() {
|
||||||
FloatingParser.opts.defaultIsFloating = true;
|
FloatingParser.opts.defaultIsFloating = true;
|
||||||
ActionExecutor.opts.convertNumberValues = true;
|
ActionExecutor.opts.convertNumberValues = true;
|
||||||
ActionExecutor.opts.printStackTrace = true;
|
ActionExecutor.opts.printStackTrace = true;
|
||||||
ActionExecutor.opts.FlatWorldType = "BlocksWorld";
|
ActionExecutor.opts.FlatWorldType = "BlocksWorld";
|
||||||
|
|
||||||
Derivation.opts.showTypes = false;
|
Derivation.opts.showTypes = false;
|
||||||
Derivation.opts.showRules = false;
|
Derivation.opts.showRules = false;
|
||||||
Derivation.opts.showCat = true;
|
Derivation.opts.showCat = true;
|
||||||
|
|
||||||
LanguageAnalyzer.opts.languageAnalyzer = "interactive.ActionLanguageAnalyzer";
|
LanguageAnalyzer.opts.languageAnalyzer = "interactive.ActionLanguageAnalyzer";
|
||||||
Grammar.opts.inPaths = Lists.newArrayList("./shrdlurn/blocksworld.grammar");
|
Grammar.opts.inPaths = Lists.newArrayList("./shrdlurn/blocksworld.grammar");
|
||||||
Grammar.opts.useApplyFn = "interactive.ApplyFn";
|
Grammar.opts.useApplyFn = "interactive.ApplyFn";
|
||||||
Grammar.opts.binarizeRules = false;
|
Grammar.opts.binarizeRules = false;
|
||||||
|
|
||||||
FeatureExtractor.opts.featureComputers = Sets.newHashSet("interactive.ActionFeatureComputer");
|
FeatureExtractor.opts.featureComputers = Sets.newHashSet("interactive.ActionFeatureComputer");
|
||||||
FeatureExtractor.opts.featureDomains = Sets.newHashSet(":rule", ":stats", ":window");
|
FeatureExtractor.opts.featureDomains = Sets.newHashSet(":rule", ":stats", ":window");
|
||||||
|
|
||||||
DefinitionAligner.opts.strategies = Sets.newHashSet(DefinitionAligner.Strategies.ExactExclusion);
|
DefinitionAligner.opts.strategies = Sets.newHashSet(DefinitionAligner.Strategies.ExactExclusion);
|
||||||
DefinitionAligner.opts.verbose = 2;
|
DefinitionAligner.opts.verbose = 2;
|
||||||
GrammarInducer.opts.verbose = 2;
|
GrammarInducer.opts.verbose = 2;
|
||||||
|
|
||||||
ActionExecutor executor = new ActionExecutor();
|
ActionExecutor executor = new ActionExecutor();
|
||||||
|
|
||||||
FeatureExtractor extractor = new FeatureExtractor(executor);
|
FeatureExtractor extractor = new FeatureExtractor(executor);
|
||||||
|
|
||||||
ValueEvaluator valueEvaluator = new ExactValueEvaluator();
|
ValueEvaluator valueEvaluator = new ExactValueEvaluator();
|
||||||
Grammar grammar = new Grammar();
|
Grammar grammar = new Grammar();
|
||||||
grammar.read();
|
grammar.read();
|
||||||
|
|
@ -72,7 +81,7 @@ public class GrammarInducerTest {
|
||||||
}
|
}
|
||||||
return Json.writeValueAsStringHard(defList);
|
return Json.writeValueAsStringHard(defList);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ParseTester {
|
class ParseTester {
|
||||||
Parser parser;
|
Parser parser;
|
||||||
Params params;
|
Params params;
|
||||||
|
|
@ -93,12 +102,12 @@ public class GrammarInducerTest {
|
||||||
b.setUtterance(head);
|
b.setUtterance(head);
|
||||||
Example exHead = b.createExample();
|
Example exHead = b.createExample();
|
||||||
exHead.preprocess();
|
exHead.preprocess();
|
||||||
|
|
||||||
// LogInfo.logs("Parsing definition: %s", ex.utterance);
|
// LogInfo.logs("Parsing definition: %s", ex.utterance);
|
||||||
parser.parse(params, exHead, true);
|
parser.parse(params, exHead, true);
|
||||||
|
|
||||||
Derivation defDeriv = ILUtils.combine(ILUtils.derivsfromJson(def, parser, params), ActionFormula.Mode.sequential);
|
Derivation defDeriv = ILUtils.combine(ILUtils.derivsfromJson(def, parser, params), ActionFormula.Mode.sequential);
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
for (Derivation d : exHead.predDerivations) {
|
for (Derivation d : exHead.predDerivations) {
|
||||||
|
|
@ -116,24 +125,24 @@ public class GrammarInducerTest {
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(String head, String def) {
|
public void accept(String head, String def) {
|
||||||
LogInfo.begin_track("Accepting");
|
LogInfo.begin_track("Accepting");
|
||||||
Example.Builder b = new Example.Builder();
|
Example.Builder b = new Example.Builder();
|
||||||
b.setUtterance(head);
|
b.setUtterance(head);
|
||||||
Example exHead = b.createExample();
|
Example exHead = b.createExample();
|
||||||
exHead.preprocess();
|
exHead.preprocess();
|
||||||
|
|
||||||
Derivation defDeriv = ILUtils.combine(ILUtils.derivsfromJson(def, parser, params), ActionFormula.Mode.block);
|
Derivation defDeriv = ILUtils.combine(ILUtils.derivsfromJson(def, parser, params), ActionFormula.Mode.block);
|
||||||
|
|
||||||
// LogInfo.logs("Parsing definition: %s", ex.utterance);
|
// LogInfo.logs("Parsing definition: %s", ex.utterance);
|
||||||
parser.parse(params, exHead, true);
|
parser.parse(params, exHead, true);
|
||||||
|
|
||||||
for (Derivation deriv : exHead.predDerivations) {
|
for (Derivation deriv : exHead.predDerivations) {
|
||||||
deriv.compatibility = defDeriv.formula.equals(deriv.formula)? 1 : 0;
|
deriv.compatibility = defDeriv.formula.equals(deriv.formula)? 1 : 0;
|
||||||
}
|
}
|
||||||
exHead.predDerivations.forEach(d -> LogInfo.logs("Compatibility %s : %f", d.formula, d.compatibility));
|
exHead.predDerivations.forEach(d -> LogInfo.logs("Compatibility %s : %f", d.formula, d.compatibility));
|
||||||
|
|
||||||
HashMap<String, Double> counts = new HashMap<>();
|
HashMap<String, Double> counts = new HashMap<>();
|
||||||
ParserState.computeExpectedCounts(exHead.predDerivations, counts);
|
ParserState.computeExpectedCounts(exHead.predDerivations, counts);
|
||||||
LogInfo.logs("Gradients: %s", counts);
|
LogInfo.logs("Gradients: %s", counts);
|
||||||
|
|
@ -142,7 +151,7 @@ public class GrammarInducerTest {
|
||||||
// LogInfo.logs("paramsafter: %s", params.getWeights());
|
// LogInfo.logs("paramsafter: %s", params.getWeights());
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printAllRules() {
|
public void printAllRules() {
|
||||||
LogInfo.begin_track("Rules induced");
|
LogInfo.begin_track("Rules induced");
|
||||||
allRules.forEach(r -> LogInfo.log(r));
|
allRules.forEach(r -> LogInfo.log(r));
|
||||||
|
|
@ -150,74 +159,77 @@ public class GrammarInducerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// tests simple substitutions
|
// tests simple substitutions
|
||||||
@Test public void simpleTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void simpleTest() {
|
||||||
LogInfo.begin_track("simpleTest");
|
LogInfo.begin_track("simpleTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("add red twice", d("add red top","add red top"));
|
T.def("add red twice", d("add red top","add red top"));
|
||||||
A.assertTrue(T.match("add blue twice", d("add blue top","add blue top")));
|
A.assertTrue(T.match("add blue twice", d("add blue top","add blue top")));
|
||||||
|
|
||||||
T.def("add red 3 times", d("repeat 3 [add red]"));
|
T.def("add red 3 times", d("repeat 3 [add red]"));
|
||||||
A.assertTrue(T.match("add yellow 5 times", d("repeat 5 [add yellow]")));
|
A.assertTrue(T.match("add yellow 5 times", d("repeat 5 [add yellow]")));
|
||||||
|
|
||||||
T.def("add red 3 ^ 2 times", d("repeat 3 {[repeat 3 [add red]]}"));
|
T.def("add red 3 ^ 2 times", d("repeat 3 {[repeat 3 [add red]]}"));
|
||||||
A.assertTrue(T.match("add blue 2 ^ 2 times", d("repeat 2 {[repeat 2 [add blue]]}")));
|
A.assertTrue(T.match("add blue 2 ^ 2 times", d("repeat 2 {[repeat 2 [add blue]]}")));
|
||||||
|
|
||||||
T.def("add a red block to the left", d("add red left"));
|
T.def("add a red block to the left", d("add red left"));
|
||||||
A.assertTrue(T.match("add a yellow block to the right", d("add yellow right")));
|
A.assertTrue(T.match("add a yellow block to the right", d("add yellow right")));
|
||||||
|
|
||||||
T.def("remove the leftmost red block", d("remove very left of has color red"));
|
T.def("remove the leftmost red block", d("remove very left of has color red"));
|
||||||
A.assertTrue(T.match("remove the leftmost yellow block", d("remove very left of has color yellow")));
|
A.assertTrue(T.match("remove the leftmost yellow block", d("remove very left of has color yellow")));
|
||||||
|
|
||||||
T.def("add red to both sides", d("add red left", "add red right"));
|
T.def("add red to both sides", d("add red left", "add red right"));
|
||||||
T.def("add red to both sides", d("add red back", "add red front"));
|
T.def("add red to both sides", d("add red back", "add red front"));
|
||||||
A.assertTrue(T.match("add green to both sides", d("add green left", "add green right")));
|
A.assertTrue(T.match("add green to both sides", d("add green left", "add green right")));
|
||||||
A.assertTrue(T.match("add green to both sides", d("add green back", "add green front")));
|
A.assertTrue(T.match("add green to both sides", d("add green back", "add green front")));
|
||||||
A.assertFalse(T.match("add green to both sides", d("add green left", "add green back")));
|
A.assertFalse(T.match("add green to both sides", d("add green left", "add green back")));
|
||||||
|
|
||||||
T.def("select all but yellow", d("select not has color yellow"));
|
T.def("select all but yellow", d("select not has color yellow"));
|
||||||
A.assertTrue(T.match("select all but blue", d("select not has color blue")));
|
A.assertTrue(T.match("select all but blue", d("select not has color blue")));
|
||||||
|
|
||||||
T.def("add a yellow block on top of red blocks", d("select has color red", "add yellow top"));
|
T.def("add a yellow block on top of red blocks", d("select has color red", "add yellow top"));
|
||||||
A.assertTrue(T.match("add a green block on top of blue blocks", d("select has color blue", "add green top")));
|
A.assertTrue(T.match("add a green block on top of blue blocks", d("select has color blue", "add green top")));
|
||||||
|
|
||||||
T.def("add a yellow block on top of red blocks", d("select has color red; add yellow top"));
|
T.def("add a yellow block on top of red blocks", d("select has color red; add yellow top"));
|
||||||
A.assertTrue(T.match("add a green block on top of blue blocks", d("select has color blue ; add green top")));
|
A.assertTrue(T.match("add a green block on top of blue blocks", d("select has color blue ; add green top")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void actionTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void actionTest() {
|
||||||
LogInfo.begin_track("actionTest");
|
LogInfo.begin_track("actionTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
// by default, we prefer higher level abstractions
|
// by default, we prefer higher level abstractions
|
||||||
T.def("add red twice", d("repeat 2 [add red]"));
|
T.def("add red twice", d("repeat 2 [add red]"));
|
||||||
// T.def("select has color red twice", d("repeat 2 [select has color red]"));
|
// T.def("select has color red twice", d("repeat 2 [select has color red]"));
|
||||||
A.assertTrue(T.match("add blue top twice", d("repeat 2 [add blue top]")));
|
A.assertTrue(T.match("add blue top twice", d("repeat 2 [add blue top]")));
|
||||||
|
|
||||||
T.def("add red 3 times", d("repeat 3 [add red]"));
|
T.def("add red 3 times", d("repeat 3 [add red]"));
|
||||||
A.assertTrue(T.match("add yellow top 5 times", d("repeat 5 [add yellow top]")));
|
A.assertTrue(T.match("add yellow top 5 times", d("repeat 5 [add yellow top]")));
|
||||||
|
|
||||||
T.def("add red then add yellow left", d("add red; add yellow left"));
|
T.def("add red then add yellow left", d("add red; add yellow left"));
|
||||||
A.assertTrue(T.match("remove has color red then add brown", d("remove has color red; add brown")));
|
A.assertTrue(T.match("remove has color red then add brown", d("remove has color red; add brown")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void notActionTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void notActionTest() {
|
||||||
LogInfo.begin_track("notActionTest");
|
LogInfo.begin_track("notActionTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("add red top twice", d("add red; add red top"));
|
T.def("add red top twice", d("add red; add red top"));
|
||||||
T.accept("add yellow top twice", d("add yellow; add yellow top"));
|
T.accept("add yellow top twice", d("add yellow; add yellow top"));
|
||||||
//T.accept("add yellow bot twice", d("add yellow; add yellow bot"));
|
//T.accept("add yellow bot twice", d("add yellow; add yellow bot"));
|
||||||
|
|
@ -225,29 +237,30 @@ public class GrammarInducerTest {
|
||||||
T.def("add red top twice", d("add red; add red top"));
|
T.def("add red top twice", d("add red; add red top"));
|
||||||
A.assertTrue(T.match("add blue right twice", d("add blue; add blue right")));
|
A.assertTrue(T.match("add blue right twice", d("add blue; add blue right")));
|
||||||
|
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void learnCatTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void learnCatTest() {
|
||||||
LogInfo.begin_track("test the learning via alignment");
|
LogInfo.begin_track("test the learning via alignment");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("add cardinal", d("add red"));
|
T.def("add cardinal", d("add red"));
|
||||||
A.assertTrue(T.match("select has color cardinal", d("select has color red")));
|
A.assertTrue(T.match("select has color cardinal", d("select has color red")));
|
||||||
|
|
||||||
T.def("move up", d("move top"));
|
T.def("move up", d("move top"));
|
||||||
A.assertTrue(T.match("select up", d("select top")));
|
A.assertTrue(T.match("select up", d("select top")));
|
||||||
A.assertTrue(T.match("add red up", d("add red top")));
|
A.assertTrue(T.match("add red up", d("add red top")));
|
||||||
|
|
||||||
T.def("move it up", d("move top"));
|
T.def("move it up", d("move top"));
|
||||||
A.assertTrue(T.match("select up", d("select top")));
|
A.assertTrue(T.match("select up", d("select top")));
|
||||||
A.assertTrue(T.match("add red up", d("add red top")));
|
A.assertTrue(T.match("add red up", d("add red top")));
|
||||||
|
|
||||||
// do not redefine core test
|
// do not redefine core test
|
||||||
T.def("move it top", d("move it bot"));
|
T.def("move it top", d("move it bot"));
|
||||||
A.assertFalse(T.match("select top", d("select bot")));
|
A.assertFalse(T.match("select top", d("select bot")));
|
||||||
|
|
@ -255,69 +268,72 @@ public class GrammarInducerTest {
|
||||||
|
|
||||||
T.def("select the highest of has color red", d("select very top of has color red"));
|
T.def("select the highest of has color red", d("select very top of has color red"));
|
||||||
A.assertTrue(T.match("remove the highest of all", d("remove very top of all")));
|
A.assertTrue(T.match("remove the highest of all", d("remove very top of all")));
|
||||||
|
|
||||||
T.def("select the top most of has color red", d("select very top of has color red"));
|
T.def("select the top most of has color red", d("select very top of has color red"));
|
||||||
A.assertTrue(T.match("remove the bot most of all", d("remove very bot of all")));
|
A.assertTrue(T.match("remove the bot most of all", d("remove very bot of all")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void cubeTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void cubeTest() {
|
||||||
LogInfo.begin_track("cubeTest");
|
LogInfo.begin_track("cubeTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("red stick of size 3", d("{repeat 3 [add red; select top]}"));
|
T.def("red stick of size 3", d("{repeat 3 [add red; select top]}"));
|
||||||
T.def("red plate of size 3", d("{repeat 3 [red stick of size 3; select left]}"));
|
T.def("red plate of size 3", d("{repeat 3 [red stick of size 3; select left]}"));
|
||||||
T.def("red cube of size 3", d("{repeat 3 [red plate of size 3; select back]}"));
|
T.def("red cube of size 3", d("{repeat 3 [red plate of size 3; select back]}"));
|
||||||
|
|
||||||
A.assertTrue(T.match("blue stick of size 4", d("{repeat 4 [add blue; select top]}")));
|
A.assertTrue(T.match("blue stick of size 4", d("{repeat 4 [add blue; select top]}")));
|
||||||
A.assertTrue(T.match("blue plate of size 4", d("{repeat 4 [blue stick of size 4; select left]}")));
|
A.assertTrue(T.match("blue plate of size 4", d("{repeat 4 [blue stick of size 4; select left]}")));
|
||||||
A.assertTrue(T.match("blue cube of size 5", d("{repeat 5 [blue plate of size 5; select back]}")));
|
A.assertTrue(T.match("blue cube of size 5", d("{repeat 5 [blue plate of size 5; select back]}")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void rectTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void rectTest() {
|
||||||
LogInfo.begin_track("rectTest");
|
LogInfo.begin_track("rectTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("red stick of size 4", d("{repeat 4 [add red; select top]}"));
|
T.def("red stick of size 4", d("{repeat 4 [add red; select top]}"));
|
||||||
T.def("red plate of size 3 by 4", d("{repeat 3 [red stick of size 4; select left]}"));
|
T.def("red plate of size 3 by 4", d("{repeat 3 [red stick of size 4; select left]}"));
|
||||||
T.def("red cube of size 2 by 3 by 4", d("{repeat 2 [red plate of size 3 by 4; select back]}"));
|
T.def("red cube of size 2 by 3 by 4", d("{repeat 2 [red plate of size 3 by 4; select back]}"));
|
||||||
|
|
||||||
A.assertTrue(T.match("red plate of size 1 by 2", d("{repeat 1 [red stick of size 2; select left]}")));
|
A.assertTrue(T.match("red plate of size 1 by 2", d("{repeat 1 [red stick of size 2; select left]}")));
|
||||||
A.assertTrue(T.match("red cube of size 1 by 2 by 3", d("{repeat 1 [red plate of size 2 by 3; select back]}")));
|
A.assertTrue(T.match("red cube of size 1 by 2 by 3", d("{repeat 1 [red plate of size 2 by 3; select back]}")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void setsTest() {
|
@Test(groups = { "Interactive" })
|
||||||
|
public void setsTest() {
|
||||||
LogInfo.begin_track("setsTest");
|
LogInfo.begin_track("setsTest");
|
||||||
ParseTester T = new ParseTester();
|
ParseTester T = new ParseTester();
|
||||||
Assertion A = hard;
|
Assertion A = hard;
|
||||||
|
|
||||||
T.def("remove those red blocks", d("remove has color red"));
|
T.def("remove those red blocks", d("remove has color red"));
|
||||||
A.assertTrue(T.match("select those red blocks", d("select has color red")));
|
A.assertTrue(T.match("select those red blocks", d("select has color red")));
|
||||||
|
|
||||||
T.def("remove the leftmost red block", d("remove very left of has color red"));
|
T.def("remove the leftmost red block", d("remove very left of has color red"));
|
||||||
A.assertTrue(T.match("select the leftmost red block", d("select very left of has color red")));
|
A.assertTrue(T.match("select the leftmost red block", d("select very left of has color red")));
|
||||||
|
|
||||||
//T.printAllRules();
|
//T.printAllRules();
|
||||||
//A.assertAll();
|
//A.assertAll();
|
||||||
|
|
||||||
LogInfo.end_track();
|
LogInfo.end_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,155 +0,0 @@
|
||||||
package edu.stanford.nlp.sempre.interactive.test;
|
|
||||||
|
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import fig.basic.*;
|
|
||||||
import edu.stanford.nlp.sempre.*;
|
|
||||||
import edu.stanford.nlp.sempre.Master.Response;
|
|
||||||
import edu.stanford.nlp.sempre.Parser.Spec;
|
|
||||||
|
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.asserts.SoftAssert;
|
|
||||||
import org.testng.asserts.Assertion;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
import org.testng.collections.Lists;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test server threading
|
|
||||||
* @author Sida Wang
|
|
||||||
*/
|
|
||||||
public class StressTest {
|
|
||||||
Assertion hard = new Assertion();
|
|
||||||
Assertion soft = new SoftAssert();
|
|
||||||
|
|
||||||
|
|
||||||
@Test public void realQueryTest() {
|
|
||||||
|
|
||||||
//String fileName = "int-output/interactive.log";
|
|
||||||
while(true) {
|
|
||||||
LogInfo.begin_track("setsTest");
|
|
||||||
//T.printAllRules();
|
|
||||||
//A.assertAll();
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
String fileName = "/Users/sidaw/turk_acl17/int-output-0119/json/sidaw.log.json";
|
|
||||||
{
|
|
||||||
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
|
|
||||||
LogInfo.logs("Reading %s", fileName);
|
|
||||||
if (fileName.endsWith(".json") || fileName.endsWith(".log")) {
|
|
||||||
stream.forEach(l -> {
|
|
||||||
Map<String, Object> json = Json.readMapHard(l);
|
|
||||||
String command = json.get("log").toString();
|
|
||||||
try {
|
|
||||||
sempreQuery(command);
|
|
||||||
//Thread.sleep(10);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
long endTime = System.nanoTime();
|
|
||||||
LogInfo.logs("Stresstest time = %d ns or %.4f s", (endTime - startTime), (endTime - startTime)/1.0e9);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LogInfo.end_track();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test public void stressTest() throws IOException, InterruptedException {
|
|
||||||
LogInfo.begin_track("stressTest");
|
|
||||||
|
|
||||||
List<String> queries = Lists.newArrayList("(:q \"add red; add yellow; select left\")",
|
|
||||||
"(:accept \"add red\" \"(: add red here)\")",
|
|
||||||
"(:q \"repeat 3 [repeat 3 [select top; add red]]\")"
|
|
||||||
);
|
|
||||||
Random rand = new Random();
|
|
||||||
// continue to spam the server
|
|
||||||
while (LogInfo.stdin.readLine() != null) {
|
|
||||||
sempreQuery(queries.get(rand.nextInt(queries.size())));
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
|
||||||
LogInfo.end_track();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void sempreQuery(String query) throws UnsupportedEncodingException {
|
|
||||||
String params = "q=" + URLEncoder.encode(query, "UTF-8") + "&sessionId=stresstester";
|
|
||||||
// params = URLEncoder.encode(params);
|
|
||||||
String url = "http://jonsson.stanford.edu:8410/sempre?";
|
|
||||||
LogInfo.log(params);
|
|
||||||
String response = executePost(url + params,"");
|
|
||||||
LogInfo.log(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String executePost(String targetURL, String urlParameters) {
|
|
||||||
HttpURLConnection connection = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
//Create connection
|
|
||||||
URL url = new URL(targetURL);
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type",
|
|
||||||
"application/x-www-form-urlencoded");
|
|
||||||
|
|
||||||
connection.setRequestProperty("Content-Length",
|
|
||||||
Integer.toString(urlParameters.getBytes().length));
|
|
||||||
connection.setRequestProperty("Content-Language", "en-US");
|
|
||||||
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
//Send request
|
|
||||||
DataOutputStream wr = new DataOutputStream (
|
|
||||||
connection.getOutputStream());
|
|
||||||
wr.writeBytes(urlParameters);
|
|
||||||
wr.close();
|
|
||||||
|
|
||||||
//Get Response
|
|
||||||
InputStream is = connection.getInputStream();
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
|
||||||
StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
|
|
||||||
String line;
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
response.append(line);
|
|
||||||
response.append('\r');
|
|
||||||
}
|
|
||||||
rd.close();
|
|
||||||
return response.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
if (connection != null) {
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
16
testng.xml
16
testng.xml
|
|
@ -1,23 +1,17 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
||||||
|
|
||||||
<suite name="SempreTestSuite" verbose="10">
|
<suite name="SempreTestSuite" verbose="10">
|
||||||
<!-- <test name="AllTests">
|
<test name="AllTests">
|
||||||
<packages>
|
<packages>
|
||||||
<package name="edu.stanford.nlp.sempre" />
|
<package name="edu.stanford.nlp.sempre">
|
||||||
|
<exclude name="edu.stanford.nlp.sempre.interactive"></exclude>
|
||||||
|
<exclude name="edu.stanford.nlp.sempre.interactive.test"></exclude>
|
||||||
|
</package>
|
||||||
</packages>
|
</packages>
|
||||||
<groups>
|
<groups>
|
||||||
<run>
|
<run>
|
||||||
<exclude name="grammar" />
|
<exclude name="grammar" />
|
||||||
</run>
|
</run>
|
||||||
</groups>
|
</groups>
|
||||||
</test> -->
|
|
||||||
<test name="GrammarTest">
|
|
||||||
<classes>
|
|
||||||
<class name="edu.stanford.nlp.sempre.interactive.actions.GrammarInducerTest">
|
|
||||||
<methods>
|
|
||||||
<include name="basicTest" />
|
|
||||||
</methods>
|
|
||||||
</class>
|
|
||||||
</classes>
|
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue