com.sun.labs.minion.retrieval.parser
Class StrictTransformer

java.lang.Object
  extended by com.sun.labs.minion.retrieval.parser.Transformer
      extended by com.sun.labs.minion.retrieval.parser.StrictTransformer

public class StrictTransformer
extends Transformer

This class transforms the output of JavaCC into a tree of query elements that the query evaluator can understand. It's more than meets the eye.


Constructor Summary
StrictTransformer()
           
 
Method Summary
protected static java.util.ArrayList collapseAnds(SimpleNode node, boolean passChildrenUp, int andType, int nearVal)
          Collapse any AND nodes that are just a chain or similar ANDSs into a single AND node with many children.
protected static java.util.ArrayList collapseOrs(SimpleNode node, boolean passChildrenUp)
          Collapse any OR nodes that are just a chain or ORs into a single OR node with many children.
protected static java.util.ArrayList collapsePassages(SimpleNode node, boolean passChildrenUp)
          Collapse any PASSAGE nodes that have a set of terms in an undefined node down into a single PASSAGE node.
protected static void collapsePhrases(SimpleNode node, TokenCollectorStage tcs)
          Creates phrases for terms that would have been tokenized by the tokenizer upon indexing.
static java.lang.String getFieldName(SimpleNode field)
           
static java.lang.String getFieldValue(SimpleNode field)
           
static int getOp(SimpleNode field)
           
protected static boolean isPassThrough(SimpleNode node)
          Determines if the node has any significance or if it is just a passthrough that can be skipped.
static void main(java.lang.String[] args)
           
protected static QueryElement makeQueryElements(SimpleNode node, int defaultOperator)
          This recursive method creates the tree of query elements based on the root node passed in.
static boolean opIsAnd(int op)
           
static boolean opIsOr(int op)
           
protected static java.util.ArrayList removeClutter(SimpleNode node)
          Removes clutter nodes -- the nodes that have only a single child and provide no additional context
 QueryElement transformTree(SimpleNode root)
          Transforms an abstract syntax tree provided by JJTree+JavaCC into a tree of QueryElements that can be used by the query evaluator.
 QueryElement transformTree(SimpleNode root, int defaultOperator)
          Transforms an abstract syntax tree provided by JJTree+JavaCC into a tree of QueryElements that can be used by the query evaluator.
protected static boolean validateTors(SimpleNode node)
          Checks to make sure that any TOR nodes have only plain terms associated with them.
 
Methods inherited from class com.sun.labs.minion.retrieval.parser.Transformer
isDoubleQuoted, isQuoted, isSingleQuoted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrictTransformer

public StrictTransformer()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

transformTree

public QueryElement transformTree(SimpleNode root)
                           throws java.text.ParseException
Transforms an abstract syntax tree provided by JJTree+JavaCC into a tree of QueryElements that can be used by the query evaluator.

Specified by:
transformTree in class Transformer
Parameters:
root - the root node of the tree returned from the Parser
Returns:
the root node of a tree describing a query
Throws:
java.text.ParseException

transformTree

public QueryElement transformTree(SimpleNode root,
                                  int defaultOperator)
                           throws java.text.ParseException
Transforms an abstract syntax tree provided by JJTree+JavaCC into a tree of QueryElements that can be used by the query evaluator.

Specified by:
transformTree in class Transformer
Parameters:
root - the root node of the tree returned from the Parser
defaultOperator - specified the default operator to use when no other operator is provided between terms in the query. Valid values are defined in the Searcher interface
Returns:
the root node of a tree describing a query
Throws:
java.text.ParseException

makeQueryElements

protected static QueryElement makeQueryElements(SimpleNode node,
                                                int defaultOperator)
                                         throws java.text.ParseException
This recursive method creates the tree of query elements based on the root node passed in. The tree passed in should already have been pruned as appropriate by the various methods in this class.

Parameters:
node -
defaultOperator - specified the default operator to use when no other operator is provided between terms in the query. Valid values are defined in the Searcher interface
Returns:
the top-level query element.
Throws:
java.text.ParseException

isPassThrough

protected static boolean isPassThrough(SimpleNode node)
Determines if the node has any significance or if it is just a passthrough that can be skipped.

Parameters:
node - the node to check
Returns:
true if the node is insignficant (semantically speaking)

removeClutter

protected static java.util.ArrayList removeClutter(SimpleNode node)
Removes clutter nodes -- the nodes that have only a single child and provide no additional context

Parameters:
node - the node to clean, pass in the root when calling externally
Returns:
the nodes children if the node is clutter and not the root

validateTors

protected static boolean validateTors(SimpleNode node)
Checks to make sure that any TOR nodes have only plain terms associated with them.

Parameters:
node - the node to check
Returns:
true if all TORs are valid

collapseOrs

protected static java.util.ArrayList collapseOrs(SimpleNode node,
                                                 boolean passChildrenUp)
Collapse any OR nodes that are just a chain or ORs into a single OR node with many children. Also checks to make sure that any TOR nodes have only plain terms associated with them.

Parameters:
node -

collapseAnds

protected static java.util.ArrayList collapseAnds(SimpleNode node,
                                                  boolean passChildrenUp,
                                                  int andType,
                                                  int nearVal)
Collapse any AND nodes that are just a chain or similar ANDSs into a single AND node with many children.

Parameters:
node -

collapsePassages

protected static java.util.ArrayList collapsePassages(SimpleNode node,
                                                      boolean passChildrenUp)
Collapse any PASSAGE nodes that have a set of terms in an undefined node down into a single PASSAGE node.

Parameters:
node -

collapsePhrases

protected static void collapsePhrases(SimpleNode node,
                                      TokenCollectorStage tcs)
Creates phrases for terms that would have been tokenized by the tokenizer upon indexing. Also strips quotes from terms. This method will traverse to above the leaf Term nodes and see if any of them need to be converted into Phrase nodes with individual terms hanging off of them.

Parameters:
node -

opIsOr

public static boolean opIsOr(int op)

opIsAnd

public static boolean opIsAnd(int op)

getOp

public static int getOp(SimpleNode field)
                 throws java.text.ParseException
Throws:
java.text.ParseException

getFieldName

public static java.lang.String getFieldName(SimpleNode field)
                                     throws java.text.ParseException
Throws:
java.text.ParseException

getFieldValue

public static java.lang.String getFieldValue(SimpleNode field)
                                      throws java.text.ParseException
Throws:
java.text.ParseException