Revision: 15940
http://gate.svn.sourceforge.net/gate/?rev=15940&view=rev
Author: valyt
Date: 2012-07-16 11:21:35 +0000 (Mon, 16 Jul 2012)
Log Message:
-----------
Refactoring:
- renamed g.m.s.terms.TermQuery to g.m.s.ty.TermsQuery (to avoid confusion with
g.m.s.q.TermQuery)
- moved IndexType enum, from g.m.s.q.TermQuery to g.m.s.QueryEngine, as it will
be used in the g.m.s.terms package as well.
Some more comments.
Modified Paths:
--------------
mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
Added Paths:
-----------
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
Removed Paths:
-------------
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermQuery.java
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -101,6 +101,24 @@
/**
+ * Represents the type of index that should be searched. Mimir uses two types
+ * of indexes: token indexes (which index the text input) and annotation
+ * indexes (which index semantic annotations).
+ */
+ public static enum IndexType{
+ /**
+ * Value representing token indexes, used for the document text.
+ */
+ TOKENS,
+
+ /**
+ * Value representing annotation indexes, used for the document semantic
+ * annotations.
+ */
+ ANNOTATIONS
+ }
+
+ /**
* The various indexes in the Mimir composite index. The array contains first
* the token indexes (in the same order as listed in the index
configuration),
* followed by the mentions indexes (in the same order as listed in the index
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -19,7 +19,7 @@
import gate.mimir.ConstraintType;
import gate.mimir.SemanticAnnotationHelper;
import gate.mimir.search.QueryEngine;
-import gate.mimir.search.terms.AnnotationTermQuery;
+import gate.mimir.search.terms.AnnotationTermsQuery;
import gate.mimir.search.terms.TermsResultSet;
import it.unimi.dsi.big.mg4j.index.Index;
import it.unimi.dsi.big.mg4j.search.visitor.DocumentIteratorVisitor;
@@ -81,7 +81,7 @@
isInDocumentMode = (helper.getMode() ==
SemanticAnnotationHelper.Mode.DOCUMENT);
// get the mention URIs
- TermsResultSet trs = new AnnotationTermQuery(query, engine).execute();
+ TermsResultSet trs = new AnnotationTermsQuery(query).execute(engine);
if(trs.terms != null && trs.terms.length > 0 &&
trs.termLengths != null) {
QueryNode[] disjuncts = new QueryNode[trs.terms.length];
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -31,8 +31,8 @@
import it.unimi.dsi.big.mg4j.search.visitor.DocumentIteratorVisitor;
import java.io.IOException;
-import java.util.*;
+import static gate.mimir.search.QueryEngine.IndexType;
/**
* A {@link QueryNode} for term queries. A term query consists of an index
name
@@ -43,24 +43,6 @@
private static final long serialVersionUID = 7302348587893649887L;
/**
- * Represents the type of index that should be searched. Mimir uses two types
- * of indexes: token indexes (which index the text input) and annotation
- * indexes (which index semantic annotations).
- */
- public static enum IndexType{
- /**
- * Value representing token indexes, used for the document text.
- */
- TOKENS,
-
- /**
- * Value representing annotation indexes, used for the document semantic
- * annotations.
- */
- ANNOTATIONS
- }
-
- /**
* The query term
*/
private String term;
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -17,7 +17,7 @@
/**
* Base class for term queries.
*/
-public abstract class AbstractTermsQuery implements TermQuery {
+public abstract class AbstractTermsQuery implements TermsQuery {
protected boolean stringsEnabled;
@@ -25,13 +25,28 @@
protected boolean countsEnabled;
+
+ /**
+ * The maximum number of results to be returned.
+ */
+ protected final int limit;
+
public AbstractTermsQuery(boolean idsEnabled, boolean stringsEnabled,
- boolean countsEnabled) {
+ boolean countsEnabled, int limit) {
this.idsEnabled = idsEnabled;
this.stringsEnabled = stringsEnabled;
this.countsEnabled = countsEnabled;
+ this.limit = limit;
}
+ public AbstractTermsQuery(boolean idsEnabled, boolean stringsEnabled,
+ boolean countsEnabled) {
+ this.idsEnabled = idsEnabled;
+ this.stringsEnabled = stringsEnabled;
+ this.countsEnabled = countsEnabled;
+ this.limit = -1;
+ }
+
public AbstractTermsQuery() {
this(true, false, false);
}
Deleted:
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermQuery.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -1,106 +0,0 @@
-/*
- * AnnotationTermQuery.java
- *
- * Copyright (c) 2007-2011, The University of Sheffield.
- *
- * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
- * and is free software, licenced under the GNU Lesser General Public License,
- * Version 3, June 2007 (also included with this distribution as file
- * LICENCE-LGPL3.html).
- *
- * Valentin Tablan, 13 Jul 2012
- *
- * $Id$
- */
-package gate.mimir.search.terms;
-
-import it.unimi.dsi.big.mg4j.index.BitStreamIndex;
-import it.unimi.dsi.big.mg4j.index.Index;
-import it.unimi.dsi.big.util.StringMap;
-import it.unimi.dsi.lang.MutableString;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import gate.mimir.SemanticAnnotationHelper;
-import gate.mimir.index.Mention;
-import gate.mimir.search.QueryEngine;
-import gate.mimir.search.query.AnnotationQuery;
-import gate.mimir.search.query.OrQuery;
-import gate.mimir.search.query.QueryNode;
-import gate.mimir.search.query.TermQuery;
-
-/**
- * Given an {@link AnnotationQuery}, this finds the set of terms that satisfy
- * it.
- */
-public class AnnotationTermQuery extends AbstractTermsQuery {
-
- public AnnotationTermQuery(boolean idsEnabled, boolean stringsEnabled,
- boolean countsEnabled,
- AnnotationQuery annotationQuery) {
- super(idsEnabled, stringsEnabled, countsEnabled);
- this.annotationQuery = annotationQuery;
- }
-
- public AnnotationTermQuery(AnnotationQuery annotationQuery, QueryEngine
engine) {
- super();
- this.annotationQuery = annotationQuery;
- this.engine = engine;
- }
-
- protected AnnotationQuery annotationQuery;
-
- protected QueryEngine engine;
-
- private static final Logger logger =
Logger.getLogger(AnnotationTermQuery.class);
-
- /* (non-Javadoc)
- * @see gate.mimir.search.terms.TermQuery#execute()
- */
- @Override
- public TermsResultSet execute() {
- // find the semantic annotation helper for the right annotation type
- SemanticAnnotationHelper helper =
- engine.getAnnotationHelper(annotationQuery);
- // ask the helper for the mentions that correspond to this query
- long start = System.currentTimeMillis();
- List<Mention> mentions = helper.getMentions(
- annotationQuery.getAnnotationType(),
- annotationQuery.getConstraints(), engine);
- logger.debug(mentions.size() + " mentions obtained in " +
- (System.currentTimeMillis() - start) + " ms");
- StringMap<? extends CharSequence> termMap = null;
- Index mg4jIndex = engine.getAnnotationIndex(
- annotationQuery.getAnnotationType()).getIndex();
- if(mg4jIndex instanceof BitStreamIndex) {
- termMap = ((BitStreamIndex)mg4jIndex).termMap;
- } else {
- // this indicates major changes in the underlying MG4J implementation
- throw new IllegalStateException(
- "Underlying MG4J index is not bitstream based!");
- }
-
- if(mentions.size() > 0) {
- long[] termIds = new long[mentions.size()];
- String[] terms = new String[mentions.size()];
- int[] lengths = new int[mentions.size()];
- int index = 0;
- for(Mention m : mentions) {
- terms[index] = m.getUri();
- lengths[index] = m.getLength();
- // find the term ID
- //use the term processor for the query term
- MutableString mutableString = new MutableString(m.getUri());
- mg4jIndex.termProcessor.processTerm(mutableString);
- // TODO use toString() if not working
- termIds[index] = termMap.getLong( mutableString);
- index++;
- }
- return new TermsResultSet(termIds, terms, lengths, null);
- } else {
- return TermsResultSet.EMPTY;
- }
- }
-}
Copied:
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
(from rev 15939,
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermQuery.java)
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
(rev 0)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -0,0 +1,101 @@
+/*
+ * AnnotationTermQuery.java
+ *
+ * Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
+ * and is free software, licenced under the GNU Lesser General Public License,
+ * Version 3, June 2007 (also included with this distribution as file
+ * LICENCE-LGPL3.html).
+ *
+ * Valentin Tablan, 13 Jul 2012
+ *
+ * $Id$
+ */
+package gate.mimir.search.terms;
+
+import it.unimi.dsi.big.mg4j.index.BitStreamIndex;
+import it.unimi.dsi.big.mg4j.index.Index;
+import it.unimi.dsi.big.util.StringMap;
+import it.unimi.dsi.lang.MutableString;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import gate.mimir.SemanticAnnotationHelper;
+import gate.mimir.index.Mention;
+import gate.mimir.search.QueryEngine;
+import gate.mimir.search.query.AnnotationQuery;
+
+/**
+ * Given an {@link AnnotationQuery}, this finds the set of terms that satisfy
+ * it.
+ */
+public class AnnotationTermsQuery extends AbstractTermsQuery {
+
+ public AnnotationTermsQuery(AnnotationQuery annotationQuery,
+ boolean idsEnabled, boolean stringsEnabled, boolean countsEnabled,
+ int limit) {
+ super(idsEnabled, stringsEnabled, countsEnabled, limit);
+ this.annotationQuery = annotationQuery;
+ }
+
+ public AnnotationTermsQuery(AnnotationQuery annotationQuery) {
+ super();
+ this.annotationQuery = annotationQuery;
+ }
+
+ protected AnnotationQuery annotationQuery;
+
+// protected QueryEngine engine;
+
+ private static final Logger logger =
Logger.getLogger(AnnotationTermsQuery.class);
+
+ /* (non-Javadoc)
+ * @see gate.mimir.search.terms.TermQuery#execute()
+ */
+ @Override
+ public TermsResultSet execute(QueryEngine engine) {
+ // find the semantic annotation helper for the right annotation type
+ SemanticAnnotationHelper helper =
+ engine.getAnnotationHelper(annotationQuery);
+ // ask the helper for the mentions that correspond to this query
+ long start = System.currentTimeMillis();
+ List<Mention> mentions = helper.getMentions(
+ annotationQuery.getAnnotationType(),
+ annotationQuery.getConstraints(), engine);
+ logger.debug(mentions.size() + " mentions obtained in " +
+ (System.currentTimeMillis() - start) + " ms");
+ StringMap<? extends CharSequence> termMap = null;
+ Index mg4jIndex = engine.getAnnotationIndex(
+ annotationQuery.getAnnotationType()).getIndex();
+ if(mg4jIndex instanceof BitStreamIndex) {
+ termMap = ((BitStreamIndex)mg4jIndex).termMap;
+ } else {
+ // this indicates major changes in the underlying MG4J implementation
+ throw new IllegalStateException(
+ "Underlying MG4J index is not a bitstream index.");
+ }
+
+ if(mentions.size() > 0) {
+ long[] termIds = new long[mentions.size()];
+ String[] terms = new String[mentions.size()];
+ int[] lengths = new int[mentions.size()];
+ int index = 0;
+ for(Mention m : mentions) {
+ terms[index] = m.getUri();
+ lengths[index] = m.getLength();
+ // find the term ID
+ //use the term processor for the query term
+ MutableString mutableString = new MutableString(m.getUri());
+ mg4jIndex.termProcessor.processTerm(mutableString);
+ termIds[index] = termMap.getLong( mutableString);
+ index++;
+ }
+ return new TermsResultSet(termIds, terms, lengths, null);
+ } else {
+ return TermsResultSet.EMPTY;
+ }
+ }
+}
Deleted: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermQuery.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -1,28 +0,0 @@
-/*
- * TermQuery.java
- *
- * Copyright (c) 2007-2011, The University of Sheffield.
- *
- * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
- * and is free software, licenced under the GNU Lesser General Public License,
- * Version 3, June 2007 (also included with this distribution as file
- * LICENCE-LGPL3.html).
- *
- * Valentin Tablan, 13 Jul 2012
- *
- * $Id$
- */
-package gate.mimir.search.terms;
-
-/**
- * A query that returns terms.
- * Term queries are fast, so they run synchronously.
- */
-public interface TermQuery {
- /**
- * Runs the term query (in the calling thread) and returns the matched terms.
- * @return a {@link TermsResultSet} containing the matched terms.
- */
- public TermsResultSet execute();
-
-}
Copied: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
(from rev 15939,
mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermQuery.java)
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
(rev 0)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -0,0 +1,31 @@
+/*
+ * TermQuery.java
+ *
+ * Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
+ * and is free software, licenced under the GNU Lesser General Public License,
+ * Version 3, June 2007 (also included with this distribution as file
+ * LICENCE-LGPL3.html).
+ *
+ * Valentin Tablan, 13 Jul 2012
+ *
+ * $Id$
+ */
+package gate.mimir.search.terms;
+
+import gate.mimir.search.QueryEngine;
+
+/**
+ * A query that returns terms.
+ * Term queries are fast, so they run synchronously.
+ */
+public interface TermsQuery {
+ /**
+ * Runs the term query (in the calling thread) and returns the matched terms.
+ * @return a {@link TermsResultSet} containing the matched terms.
+ * @param engine the {@link QueryEngine} used to execute the search.
+ */
+ public TermsResultSet execute(QueryEngine engine);
+
+}
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
2012-07-16 01:18:56 UTC (rev 15939)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
2012-07-16 11:21:35 UTC (rev 15940)
@@ -15,7 +15,7 @@
package gate.mimir.search.terms;
/**
- * Class representing the results of a {@link TermQuery}.
+ * Class representing the results of a {@link TermsQuery}.
*/
public class TermsResultSet {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs