exclude my tests in main

This commit is contained in:
Sida Wang 2017-03-17 22:40:39 -07:00
parent 4c765362d0
commit 068bdbfcac
7 changed files with 153 additions and 279 deletions

View File

@ -1,5 +1,6 @@
package edu.stanford.nlp.sempre;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
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")
public String contextPrefix = "context:";
@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();
@ -194,7 +195,7 @@ public class JavaExecutor extends Executor {
id = MapUtils.get(shortcuts, id, id);
// 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;
}

View File

@ -50,6 +50,7 @@ public class Rule {
@Override
public String toString() {
if (stringRepn == null) {
if (sem == null) return "NoSemanticFunction";
String semStr = sem.toString();
// stop printing very long rules
int maxLength = 100;

View File

@ -1,26 +1,31 @@
package edu.stanford.nlp.sempre.interactive.test;
import static org.testng.AssertJUnit.assertEquals;
import java.util.*;
import java.util.Set;
import java.util.function.Predicate;
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.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
* @author Sida Wang
*/
public class ActionExecutorTest {
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;};
}
@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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testJoin");
@ -71,7 +77,8 @@ public class ActionExecutorTest {
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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testSpecial");
@ -84,7 +91,8 @@ public class ActionExecutorTest {
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\",[]]]";
ContextValue context = getContext(defaultBlocks);
@ -96,7 +104,8 @@ public class ActionExecutorTest {
}
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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testBasicActions");
@ -116,7 +125,8 @@ public class ActionExecutorTest {
private Set<Item> real(Set<Item> all) {
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
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[\"S\"]],[1,1,3,\"Red\",[\"S\"]],[1,1,4,\"Green\",[]]]";
ContextValue context = getContext(defaultBlocks);
@ -131,7 +141,8 @@ public class ActionExecutorTest {
LogInfo.end_track();
}
@Test public void testMoreActions() {
@Test(groups = { "Interactive" })
public void testMoreActions() {
// this is a green stick
String defaultBlocks = "[[1,1,1,\"Green\",[]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
ContextValue context = getContext(defaultBlocks);
@ -147,7 +158,8 @@ public class ActionExecutorTest {
LogInfo.end_track();
}
@Test public void troubleCases() {
@Test(groups = { "Interactive" })
public void troubleCases() {
// this is a green stick
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
ContextValue context = getContext(defaultBlocks);
@ -159,7 +171,8 @@ public class ActionExecutorTest {
LogInfo.end_track();
}
@Test public void testFake() {
@Test(groups = { "Interactive" })
public void testFake() {
// this is a green stick
String defaultBlocks = "[[1,1,0,\"Fake\",[\"S\"]]]";
ContextValue context = getContext(defaultBlocks);
@ -174,7 +187,8 @@ public class ActionExecutorTest {
LogInfo.end_track();
}
@Test public void testIsolation() {
@Test(groups = { "Interactive" })
public void testIsolation() {
// this is a green stick
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
ContextValue context = getContext(defaultBlocks);
@ -186,7 +200,8 @@ public class ActionExecutorTest {
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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testUpdate");
@ -197,7 +212,8 @@ public class ActionExecutorTest {
LogInfo.end_track();
}
@Test public void testScoping() {
@Test(groups = { "Interactive" })
public void testScoping() {
// this is a green stick
String defaultBlocks = "[[1,1,1,\"Green\",[\"S\"]],[1,1,2,\"Green\",[]],[1,1,3,\"Green\",[]],[1,1,4,\"Green\",[]]]";
ContextValue context = getContext(defaultBlocks);

View File

@ -18,6 +18,7 @@ import org.testng.collections.Lists;
* Test the parser, and some floating examples
* @author Sida Wang
*/
@Test(groups = { "InteractiveLearning" })
public class FloatingParsingTest {
Predicate<Example> contains(String 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));
}
@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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testJoin");
@ -115,7 +116,7 @@ public class FloatingParsingTest {
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\",[]]]";
ContextValue context = getContext(defaultBlocks);
LogInfo.begin_track("testJoin");

View File

@ -1,29 +1,38 @@
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.asserts.Assertion;
import org.testng.asserts.SoftAssert;
import org.testng.collections.Lists;
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
* @author Sida Wang
@ -150,7 +159,8 @@ public class GrammarInducerTest {
}
}
// tests simple substitutions
@Test public void simpleTest() {
@Test(groups = { "Interactive" })
public void simpleTest() {
LogInfo.begin_track("simpleTest");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -191,7 +201,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void actionTest() {
@Test(groups = { "Interactive" })
public void actionTest() {
LogInfo.begin_track("actionTest");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -213,7 +224,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void notActionTest() {
@Test(groups = { "Interactive" })
public void notActionTest() {
LogInfo.begin_track("notActionTest");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -232,7 +244,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void learnCatTest() {
@Test(groups = { "Interactive" })
public void learnCatTest() {
LogInfo.begin_track("test the learning via alignment");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -265,7 +278,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void cubeTest() {
@Test(groups = { "Interactive" })
public void cubeTest() {
LogInfo.begin_track("cubeTest");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -284,7 +298,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void rectTest() {
@Test(groups = { "Interactive" })
public void rectTest() {
LogInfo.begin_track("rectTest");
ParseTester T = new ParseTester();
Assertion A = hard;
@ -302,7 +317,8 @@ public class GrammarInducerTest {
LogInfo.end_track();
}
@Test public void setsTest() {
@Test(groups = { "Interactive" })
public void setsTest() {
LogInfo.begin_track("setsTest");
ParseTester T = new ParseTester();
Assertion A = hard;

View File

@ -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();
}
}
}
}

View File

@ -1,23 +1,17 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SempreTestSuite" verbose="10">
<!-- <test name="AllTests">
<test name="AllTests">
<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>
<groups>
<run>
<exclude name="grammar" />
</run>
</groups>
</test> -->
<test name="GrammarTest">
<classes>
<class name="edu.stanford.nlp.sempre.interactive.actions.GrammarInducerTest">
<methods>
<include name="basicTest" />
</methods>
</class>
</classes>
</test>
</suite>