Revision: 14473
http://gate.svn.sourceforge.net/gate/?rev=14473&view=rev
Author: valyt
Date: 2011-11-01 14:55:19 +0000 (Tue, 01 Nov 2011)
Log Message:
-----------
Support for testing mutiple helper implementations in parallel.
Modified Paths:
--------------
mimir/trunk/mimir-test/build.xml
mimir/trunk/mimir-test/src/gate/mimir/test/QueryTests.java
mimir/trunk/mimir-test/src/gate/mimir/test/Scratch.java
Modified: mimir/trunk/mimir-test/build.xml
===================================================================
--- mimir/trunk/mimir-test/build.xml 2011-11-01 13:55:19 UTC (rev 14472)
+++ mimir/trunk/mimir-test/build.xml 2011-11-01 14:55:19 UTC (rev 14473)
@@ -8,6 +8,9 @@
<property name="core-home" location="../${mimir-core.dirname}"/>
+ <property name="helpers.to.test"
+ value="gate.mimir.db.DBSemanticAnnotationHelper" />
+
<path id="libs">
<fileset dir="lib" includes="**/*.jar" />
<fileset dir="${core-home}/lib" includes="**/*.jar" />
@@ -89,6 +92,7 @@
<pathelement location="${classes.dir}" />
<path refid="compile.classpath" />
</classpath>
+ <sysproperty key="helpers.to.test" value="${helpers.to.test}" />
<formatter type="xml" />
<batchtest>
<fileset dir="${src.dir}" includes="**/*Tests.java" />
Modified: mimir/trunk/mimir-test/src/gate/mimir/test/QueryTests.java
===================================================================
--- mimir/trunk/mimir-test/src/gate/mimir/test/QueryTests.java 2011-11-01
13:55:19 UTC (rev 14472)
+++ mimir/trunk/mimir-test/src/gate/mimir/test/QueryTests.java 2011-11-01
14:55:19 UTC (rev 14473)
@@ -64,16 +64,19 @@
*/
public class QueryTests {
+ private static final String resultsPath = "reports/query-results";
+ private static final String NEW_LINE = System.getProperty("line.separator");
+
+ public static final String[] helperTypes = System.getProperty(
+ "helpers.to.test", "gate.mimir.db.DBSemanticAnnotationHelper").split(
+ "\\s*,\\s*");
+
/**
- * The QueryEngine used for the tests.
+ * The indexes being tested against
*/
- private static QueryEngine engine;
+ private static File[] indexDirs;
-
- private static String resultsPath;
- private static final String NEW_LINE = System.getProperty("line.separator");
-
/**
* Prepares the QueryEngine used by all tests.
*/
@@ -86,40 +89,38 @@
Gate.getCreoleRegister().registerDirectories(new
File("gate-home/plugins/ANNIE-tokeniser").toURI().toURL());
// load the DB plugin
Gate.getCreoleRegister().registerDirectories(new
File("../plugins/db-h2").toURI().toURL());
-// // load the Sesame plugin
-// Gate.getCreoleRegister().registerDirectories(new
File("../plugins/sesame").toURI().toURL());
+ // load the Sesame plugin
+ Gate.getCreoleRegister().registerDirectories(new
File("../plugins/sesame").toURI().toURL());
// load the measurements plugin
Gate.getCreoleRegister().registerDirectories(new
File("../plugins/measurements").toURI().toURL());
- File indexDir = File.createTempFile("mimir-index", null);
- indexDir.delete();
- // change this to use a different helper (e.g for the the ORDI one you
- IndexConfig indexConfig = TestUtils.getTestIndexConfig(indexDir,
- Class.forName("gate.mimir.db.DBSemanticAnnotationHelper", true,
-
Gate.getClassLoader()).asSubclass(AbstractSemanticAnnotationHelper.class));
-// IndexConfig indexConfig = TestUtils.getTestIndexConfig(indexDir,
-// Class.forName("gate.mimir.sesame.SesameSemanticAnnotationHelper",
true,
-//
Gate.getClassLoader()).asSubclass(AbstractSemanticAnnotationHelper.class));
- // now start indexing the documents
- Indexer indexer = new Indexer(indexConfig);
- String pathToZipFile = "data/gatexml-output.zip";
- File zipFile = new File(pathToZipFile);
- String fileURI = zipFile.toURI().toString();
- ZipFile zip = new ZipFile(pathToZipFile);
- Enumeration<? extends ZipEntry> entries = zip.entries();
- while(entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- if(entry.isDirectory()) {
- continue;
+ indexDirs = new File[helperTypes.length];
+ for(int i = 0; i < helperTypes.length; i++) {
+ indexDirs[i] = File.createTempFile("mimir-index", null);
+ indexDirs[i].delete();
+ IndexConfig indexConfig = TestUtils.getTestIndexConfig(indexDirs[i],
+ Class.forName(helperTypes[i], true, Gate.getClassLoader()).asSubclass(
+ AbstractSemanticAnnotationHelper.class));
+
+ // now start indexing the documents
+ Indexer indexer = new Indexer(indexConfig);
+ String pathToZipFile = "data/gatexml-output.zip";
+ File zipFile = new File(pathToZipFile);
+ String fileURI = zipFile.toURI().toString();
+ ZipFile zip = new ZipFile(pathToZipFile);
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while(entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if(entry.isDirectory()) {
+ continue;
+ }
+ URL url = new URL("jar:" + fileURI + "!/" + entry.getName());
+ Document doc = gate.Factory.newDocument(url, "UTF-8");
+ indexer.indexDocument(doc);
}
- URL url = new URL("jar:" + fileURI + "!/" + entry.getName());
- Document doc = gate.Factory.newDocument(url, "UTF-8");
- indexer.indexDocument(doc);
+ indexer.close();
}
- indexer.close();
- engine = new QueryEngine(indexDir);
- resultsPath = "reports/query-results";
}
/**
@@ -127,14 +128,11 @@
*/
@AfterClass
public static void oneTimeTearDown() {
- if(engine != null) {
- File indexDir = engine.getIndexDir();
- engine.close();
- engine = null;
+ for(File indexDir : indexDirs) {
// recursively delete index dir
if(!TestUtils.deleteDir(indexDir)) {
System.err.println("Could not delete index directory " + indexDir);
- }
+ }
}
}
@@ -143,23 +141,28 @@
* that the results of one are included in the other one.
*
* @throws IOException
+ * @throws IndexException
*/
@Test
- public void testSequenceQueryGaps() throws IOException {
- TermQuery tq1 = new TermQuery("string", "up");
- TermQuery tq2 = new TermQuery("string", "to");
- TermQuery tq3 = new TermQuery("string", "the");
- SequenceQuery sQuery = new SequenceQuery(null, tq1, tq2, tq3);
- SequenceQuery sQueryGaps =
- new SequenceQuery(new SequenceQuery.Gap[]{SequenceQuery
- .getGap(1, 1)}, tq1, tq3);
- List<Binding>[] diff = TestUtils.calculateDiff(sQuery, sQueryGaps, engine);
- // second query is more permissive than first
- assertNotNull("The two queries returned the same result set!", diff);
- assertTrue("The non gaps query has results not included in the gaps one!",
- diff[0].isEmpty());
- assertTrue("The gaps query returned no additional hits!",
- diff[1].size() > 0);
+ public void testSequenceQueryGaps() throws IOException, IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ TermQuery tq1 = new TermQuery("string", "up");
+ TermQuery tq2 = new TermQuery("string", "to");
+ TermQuery tq3 = new TermQuery("string", "the");
+ SequenceQuery sQuery = new SequenceQuery(null, tq1, tq2, tq3);
+ SequenceQuery sQueryGaps =
+ new SequenceQuery(new SequenceQuery.Gap[]{SequenceQuery
+ .getGap(1, 1)}, tq1, tq3);
+ List<Binding>[] diff = TestUtils.calculateDiff(sQuery, sQueryGaps,
engine);
+ // second query is more permissive than first
+ assertNotNull("The two queries returned the same result set!", diff);
+ assertTrue("The non gaps query has results not included in the gaps
one!",
+ diff[0].isEmpty());
+ assertTrue("The gaps query returned no additional hits!",
+ diff[1].size() > 0);
+ engine.close();
+ }
}
/**
@@ -171,18 +174,22 @@
*/
@Test
public void testRepeatsAndOrQueries() throws IndexException, IOException {
- Map<String, String> empty = Collections.emptyMap();
- AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
- RepeatsQuery rQuery = new RepeatsQuery(annQuery, 1, 3);
- OrQuery orQuery =
- new OrQuery(annQuery, new SequenceQuery(null, annQuery, annQuery),
- new SequenceQuery(null, annQuery, annQuery, annQuery));
- List<Binding>[] diff = TestUtils.calculateDiff(rQuery, orQuery, engine);
- if(diff != null) {
- System.err.println(TestUtils.printDiffResults(diff, engine));
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ Map<String, String> empty = Collections.emptyMap();
+ AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
+ RepeatsQuery rQuery = new RepeatsQuery(annQuery, 1, 3);
+ OrQuery orQuery =
+ new OrQuery(annQuery, new SequenceQuery(null, annQuery,
annQuery),
+ new SequenceQuery(null, annQuery, annQuery, annQuery));
+ List<Binding>[] diff = TestUtils.calculateDiff(rQuery, orQuery, engine);
+ if(diff != null) {
+ System.err.println(TestUtils.printDiffResults(diff, engine));
+ }
+ assertNull("Repeats query result different from equivalent OR query. "
+ + "See system.err for details!", diff);
+ engine.close();
}
- assertNull("Repeats query result different from equivalent OR query. "
- + "See system.err for details!", diff);
}
/**
@@ -195,17 +202,21 @@
@Test
public void testSequenceAndRepeatsQueries() throws IndexException,
IOException {
- Map<String, String> empty = Collections.emptyMap();
- AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
- SequenceQuery sQuery =
- new SequenceQuery(null, annQuery, annQuery, annQuery);
- RepeatsQuery rQuery = new RepeatsQuery(annQuery, 3, 3);
- List<Binding>[] diff = TestUtils.calculateDiff(sQuery, rQuery, engine);
- if(diff != null) {
- System.err.println(TestUtils.printDiffResults(diff, engine));
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ Map<String, String> empty = Collections.emptyMap();
+ AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
+ SequenceQuery sQuery =
+ new SequenceQuery(null, annQuery, annQuery, annQuery);
+ RepeatsQuery rQuery = new RepeatsQuery(annQuery, 3, 3);
+ List<Binding>[] diff = TestUtils.calculateDiff(sQuery, rQuery, engine);
+ if(diff != null) {
+ System.err.println(TestUtils.printDiffResults(diff, engine));
+ }
+ assertNull("Repeats query result different from equivalent OR query. "
+ + "See system.err for details!", diff);
+ engine.close();
}
- assertNull("Repeats query result different from equivalent OR query. "
- + "See system.err for details!", diff);
}
/**
@@ -219,17 +230,21 @@
*/
@Test
public void testGapImplementations() throws IndexException, IOException {
- TermQuery tq1 = new TermQuery("string", "up");
- TermQuery tq3 = new TermQuery("root", "the");
- SequenceQuery sQuery1 =
- new SequenceQuery(new SequenceQuery.Gap[]{SequenceQuery
- .getGap(1, 1)}, tq1, tq3);
- TermQuery tq1Gap = new TermQuery(TermQuery.IndexType.TOKENS, "string",
"up", 2);
- SequenceQuery sQuery2 = new SequenceQuery(null, tq1Gap, tq3);
- GapQuery gQ1 = new GapQuery(tq1, 1);
- SequenceQuery sQuery3 = new SequenceQuery(null, gQ1, tq3);
- assertTrue("Not all results are the same!", TestUtils.allEqual(engine,
- sQuery1, sQuery2, sQuery3));
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ TermQuery tq1 = new TermQuery("string", "up");
+ TermQuery tq3 = new TermQuery("root", "the");
+ SequenceQuery sQuery1 =
+ new SequenceQuery(new SequenceQuery.Gap[]{SequenceQuery
+ .getGap(1, 1)}, tq1, tq3);
+ TermQuery tq1Gap = new TermQuery(TermQuery.IndexType.TOKENS, "string",
"up", 2);
+ SequenceQuery sQuery2 = new SequenceQuery(null, tq1Gap, tq3);
+ GapQuery gQ1 = new GapQuery(tq1, 1);
+ SequenceQuery sQuery3 = new SequenceQuery(null, gQ1, tq3);
+ assertTrue("Not all results are the same!", TestUtils.allEqual(engine,
+ sQuery1, sQuery2, sQuery3));
+ engine.close();
+ }
}
/**
@@ -241,6 +256,8 @@
*/
@Test
public void testDiffer() throws IOException, IndexException {
+ File indexDir = indexDirs[0];
+ QueryEngine engine = new QueryEngine(indexDir);
String[] terms = new String[]{"up", "to", "the"};
TermQuery[] tqs = new TermQuery[terms.length];
for(int i = 0; i < terms.length; i++) {
@@ -249,99 +266,135 @@
SequenceQuery seqQuery = new SequenceQuery(null, tqs);
List<Binding>[] res = TestUtils.calculateDiff(seqQuery, seqQuery, engine);
assertNull("Different results from the same query!", res);
+ engine.close();
}
@Test
- public void annotationQuery() {
- Map<String, String> constraints = new HashMap<String, String>();
- constraints.put("spec", "1 to 32 degF");
- AnnotationQuery annQuery = new AnnotationQuery("Measurement", constraints);
- performQuery("annotation", annQuery);
+ public void annotationQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ Map<String, String> constraints = new HashMap<String, String>();
+ constraints.put("spec", "1 to 32 degF");
+ AnnotationQuery annQuery = new AnnotationQuery("Measurement",
constraints);
+ performQuery("annotation", annQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testStringSequenceQuery() {
- String[] terms = new String[] {"up", "to", "the"};
- // String[] terms = new String[]{"ability", "of", /*"the", "agent",*/ "to",
- // "form", "an", "acid", "or", "base", "upon", "heating", "whereby",
- // "dehydrating", "cellulose", "at", "a", "low", "temperature",
- // "within", "a", "short", "period", "to", "yield", "water", "and",
- // "carbon"};
- TermQuery[] termQueries = new TermQuery[terms.length];
- for(int i = 0; i < terms.length; i++) {
- termQueries[i] = new TermQuery("string", terms[i]);
+ public void testStringSequenceQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ String[] terms = new String[] {"up", "to", "the"};
+ // String[] terms = new String[]{"ability", "of", /*"the", "agent",*/
"to",
+ // "form", "an", "acid", "or", "base", "upon", "heating", "whereby",
+ // "dehydrating", "cellulose", "at", "a", "low", "temperature",
+ // "within", "a", "short", "period", "to", "yield", "water", "and",
+ // "carbon"};
+ TermQuery[] termQueries = new TermQuery[terms.length];
+ for(int i = 0; i < terms.length; i++) {
+ termQueries[i] = new TermQuery("string", terms[i]);
+ }
+ SequenceQuery.Gap[] gaps = new SequenceQuery.Gap[28];
+ gaps[1] = SequenceQuery.getGap(2, 3);
+ SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */,
termQueries);
+ performQuery("termSequence", sequenceQuery, engine);
+ engine.close();
}
- SequenceQuery.Gap[] gaps = new SequenceQuery.Gap[28];
- gaps[1] = SequenceQuery.getGap(2, 3);
- SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */,
termQueries);
-
- performQuery("termSequence", sequenceQuery);
}
@Test
- public void testCategorySequenceQuery() {
- String[] terms = new String[]{"NN", "NN", "NN"};
- TermQuery[] termQueries = new TermQuery[terms.length];
- for(int i = 0; i < terms.length; i++) {
- termQueries[i] = new TermQuery("category", terms[i]);
+ public void testCategorySequenceQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ String[] terms = new String[]{"NN", "NN", "NN"};
+ TermQuery[] termQueries = new TermQuery[terms.length];
+ for(int i = 0; i < terms.length; i++) {
+ termQueries[i] = new TermQuery("category", terms[i]);
+ }
+ SequenceQuery.Gap[] gaps = new SequenceQuery.Gap[28];
+ gaps[1] = SequenceQuery.getGap(2, 3);
+ SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */,
termQueries);
+ performQuery("categorySequence", sequenceQuery, engine);
+ engine.close();
}
- SequenceQuery.Gap[] gaps = new SequenceQuery.Gap[28];
- gaps[1] = SequenceQuery.getGap(2, 3);
- SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */,
termQueries);
- performQuery("categorySequence", sequenceQuery);
}
@Test
- public void testAnnotationSequenceQuery() {
- Map<String, String> empty = Collections.emptyMap();
- AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
- SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */, annQuery,
annQuery, annQuery);
- performQuery("annotationSequence", sequenceQuery);
+ public void testAnnotationSequenceQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ Map<String, String> empty = Collections.emptyMap();
+ AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
+ SequenceQuery sequenceQuery = new SequenceQuery(null/* gaps */,
annQuery, annQuery, annQuery);
+ performQuery("annotationSequence", sequenceQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testRepeatsQuery() {
- Map<String, String> empty = Collections.emptyMap();
- AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
- RepeatsQuery repeatsQuery = new RepeatsQuery(annQuery, 3, 3);
- performQuery("repeats", repeatsQuery);
+ public void testRepeatsQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ Map<String, String> empty = Collections.emptyMap();
+ AnnotationQuery annQuery = new AnnotationQuery("Measurement", empty);
+ RepeatsQuery repeatsQuery = new RepeatsQuery(annQuery, 3, 3);
+ performQuery("repeats", repeatsQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testWithinQuery() {
- AnnotationQuery intervalQuery = new AnnotationQuery("Measurement",
Collections.singletonMap("type", "interval"));
- TermQuery toQuery = new TermQuery("string", "to");
- WithinQuery withinQuery = new WithinQuery(toQuery, intervalQuery);
- performQuery("within", withinQuery);
+ public void testWithinQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ AnnotationQuery intervalQuery = new AnnotationQuery("Measurement",
Collections.singletonMap("type", "interval"));
+ TermQuery toQuery = new TermQuery("string", "to");
+ WithinQuery withinQuery = new WithinQuery(toQuery, intervalQuery);
+ performQuery("within", withinQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testInAndQuery() {
- QueryNode inAndQuery = new WithinQuery(new AndQuery(new TermQuery(null,
"London"),
- new TermQuery(null, "press")), new AnnotationQuery(
- "Reference", new HashMap<String, String>()));
- performQuery("inAnd", inAndQuery);
+ public void testInAndQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ QueryNode inAndQuery = new WithinQuery(new AndQuery(new TermQuery(null,
"London"),
+ new TermQuery(null, "press")), new AnnotationQuery(
+ "Reference", new HashMap<String, String>()));
+ performQuery("inAnd", inAndQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testMeasurementSpecQuery() {
- AnnotationQuery specQuery = new AnnotationQuery("Measurement",
Collections.singletonMap("spec", "5 cm"));
- performQuery("measurementSpec", specQuery);
+ public void testMeasurementSpecQuery() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ AnnotationQuery specQuery = new AnnotationQuery("Measurement",
Collections.singletonMap("spec", "5 cm"));
+ performQuery("measurementSpec", specQuery, engine);
+ engine.close();
+ }
}
@Test
- public void testQueryEngineRenderDocument() {
- List<Binding> hits = new ArrayList<Binding>();
- hits.add(new Binding(null, 0, 100, 5, null));
- hits.add(new Binding(null, 0, 110, 4, null));
- try {
- engine.renderDocument(0, hits, new FileWriter(resultsPath +
"/renderDocumentResult.txt"));
- } catch(Exception e) {
- fail(e.getMessage());
+ public void testQueryEngineRenderDocument() throws IndexException {
+ for(File indexDir : indexDirs) {
+ QueryEngine engine = new QueryEngine(indexDir);
+ List<Binding> hits = new ArrayList<Binding>();
+ hits.add(new Binding(null, 0, 100, 5, null));
+ hits.add(new Binding(null, 0, 110, 4, null));
+ try {
+ engine.renderDocument(0, hits, new FileWriter(resultsPath +
"/renderDocumentResult.txt"));
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+ engine.close();
}
}
- private void performQuery(String name, QueryNode query) {
+ private void performQuery(String name, QueryNode query, QueryEngine engine) {
QueryExecutor executor = null;
Binding hit = null;
Modified: mimir/trunk/mimir-test/src/gate/mimir/test/Scratch.java
===================================================================
--- mimir/trunk/mimir-test/src/gate/mimir/test/Scratch.java 2011-11-01
13:55:19 UTC (rev 14472)
+++ mimir/trunk/mimir-test/src/gate/mimir/test/Scratch.java 2011-11-01
14:55:19 UTC (rev 14473)
@@ -26,8 +26,10 @@
Gate.getCreoleRegister().registerDirectories(
new File("gate-home/plugins/ANNIE-tokeniser").toURI().toURL());
// load the DB plugin
+// Gate.getCreoleRegister().registerDirectories(
+// new File("../plugins/db-h2").toURI().toURL());
Gate.getCreoleRegister().registerDirectories(
- new File("../plugins/db-h2").toURI().toURL());
+ new File("../plugins/sesame").toURI().toURL());
// load the measurements plugin
Gate.getCreoleRegister().registerDirectories(
new File("../plugins/measurements").toURI().toURL());
@@ -36,7 +38,7 @@
QueryEngine qEngine = new QueryEngine(new File(args[0]));
// String query = "the";
- String query = "{Document}";
+ String query = "{Document date > 20070000}";
QueryNode qNode = QueryParser.parse(query);
long start = System.currentTimeMillis();
NumberFormat nf = NumberFormat.getNumberInstance();
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs