net.sourceforge.nite.search.rewriter
Class DefaultQueryRewriter

java.lang.Object
  extended by net.sourceforge.nite.search.rewriter.DefaultQueryRewriter
All Implemented Interfaces:
ParserTreeConstants, QueryRewriter, RewriterConstants

public class DefaultQueryRewriter
extends java.lang.Object
implements QueryRewriter, ParserTreeConstants, RewriterConstants

The default implementation of the QueryRewriter, implementing our first guess at a set of rewriting rules.

We implement the ParserTreeConstants so we can use them in creating Nodes, and RewriterConstants so we can use the sample queries in testing via the main method.

Author:
nmayo@inf.ed.ac.uk

Field Summary
 
Fields inherited from interface net.sourceforge.nite.search.ParserTreeConstants
JJTCONDITION, JJTLOGICAL, jjtNodeName, JJTQUERY, JJTSIMPLEQUERY
 
Fields inherited from interface net.sourceforge.nite.search.rewriter.RewriterConstants
BREAK_LINE, TEST_QUERIES
 
Constructor Summary
DefaultQueryRewriter()
          Create a DefaultQueryRewriter with (optionally) a SearchableCorpus attached.
DefaultQueryRewriter(SearchableCorpus sc)
           
 
Method Summary
static void main(java.lang.String[] args)
          Main test method.
 NodeQuery rewrite(NodeQuery query)
          Rewrite the query plan according to the rules of our algorithm.
 java.util.List rewriteResult(java.util.List result)
          Take the result tree and rewrite it to the form expected given the original input query.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultQueryRewriter

public DefaultQueryRewriter()
Create a DefaultQueryRewriter with (optionally) a SearchableCorpus attached.


DefaultQueryRewriter

public DefaultQueryRewriter(SearchableCorpus sc)
Method Detail

main

public static void main(java.lang.String[] args)
Main test method. Instantiates the class without a SearchableCorpus, just running the rewrite() method on a parsed query string. The NodeQuery query plan is rewritten according to the algorithm.


rewrite

public NodeQuery rewrite(NodeQuery query)
Rewrite the query plan according to the rules of our algorithm. Ignore exists quantifier, and split query into complex composition of more concise simple queries with, where possible:

In terms of the dnf vector containing the query plan: Redistribute sets of ANDed NodeConditions to single variables where possible, joining them with NodeLogicals. Keep conditions which are joined by implication or OR together. Make all exists booleans false.

TO DO: Meanwhile record a mapping for the results output. TO DO: We may need to reorder forall booleans?

Specified by:
rewrite in interface QueryRewriter
Parameters:
query - the NodeQuery which is to be rewritten
Returns:
the rewritten query

rewriteResult

public java.util.List rewriteResult(java.util.List result)
Take the result tree and rewrite it to the form expected given the original input query.

Specified by:
rewriteResult in interface QueryRewriter
Parameters:
result - the results of the query