com.raritantechnologies.vqlparser
Class Node

java.lang.Object
  extended bycom.raritantechnologies.vqlparser.Node
All Implemented Interfaces:
java.lang.Cloneable

public class Node
extends java.lang.Object
implements java.lang.Cloneable

This class represents an element in the parse tree resulting from breaking apart a query string. (see Lexer.java)


Developed by Raritan Technologies Inc..

Author:
Kepler Gelotte

Constructor Summary
Node(Node n)
          Constructor to clone a node Note: MUST setLeft(), setRight(), setParent() on the new node.
Node(java.lang.String nm, Lexer l, int t, int a, int p)
          Constructor which bypasses the table lookup.
Node(java.lang.String nm, Lexer l, SymbolTable st)
          Constructor which performs a symbol table lookup if the symbol is not found, assume it is a word.
Node(java.lang.String nm, Node n)
          Constructor to clone a node Note: MUST setLeft(), setRight(), setParent() on the new node.
 
Method Summary
 void adjustLevel(int adjust)
          adjusts the level (paranthetical) from this point down.
 Node applyRules(QueryRules qr, java.lang.String field)
          turns: X field into ( query rules applied ) NOTE: MUST isolate field before calling this function.....
 Node applyRules(QueryRules qr, java.lang.String field, java.lang.String defaultField)
           
 void breakOnEOSChars()
          Breaks strings on EOS characters (?, !, and .
 void breakOnEOSChars(java.lang.String eos)
           
 Node bypassPrefixOps()
          turns: ((X Y)) FT into (X Y) FT Certain prefix ops are meaningless when rules are applied.
 boolean checkPrefix()
          checks whether the prefix proximity/evidence operator is operating on a list.
 java.lang.Object clone()
          Clones a tree (or sub-tree) and returns the root of the new tree.
 Node combineFields()
          Combines the zone to the highest level.
 int findAllFields(java.util.HashSet fields)
          Looks for all fields within this subtree.
 boolean findField(java.lang.String field)
          Looks for a field within this subtree.
 void getAllValues(java.util.LinkedList a)
          Pull all values out of the query.
 void getAllValues(java.util.LinkedList a, boolean bPrint, boolean bReplace)
          Pull all values out of the query.
 java.lang.String getAmount()
          Returns the amount of this node.
 int getArity()
          Returns the arity of this node.
 java.lang.String getAttributeField()
          Returns the string for attributeField.
 Node getLeft()
          Get the left child of this node.
 boolean getLeftPrune()
          Returns the left_prune of this node.
 int getLevel()
          Returns the depth that this node is nested within parens.
 java.lang.String getName()
          Returns the string for the human readable name of the symbol.
 Node getParent()
          Get the parent of this node.
 int getPrecedence()
          Returns the precedence of this node.
 Node getRight()
          Get the right child of this node.
 boolean getRightPrune()
          Returns the right_prune of this node.
 java.lang.String getRulesValueString()
          Pull all values out of the query.
 int getType()
          Returns the type of this node.
 void getValues(java.util.HashSet a)
          Pull all values out of the query.
 void getValues(java.util.HashSet a, boolean bPrint, boolean bReplace)
          Pull all values out of the query.
 java.util.HashSet getWords()
          Returns a HashSet containing all (unidentified) field nodes
 boolean hasBoolOp()
          Does this tree contain a boolean operator?
 boolean hasIN()
          Sees if the subtree contains an , or
 boolean hasPrefixOps()
          Checks whether prefix ops are used.
 boolean identifyFields(java.util.HashMap fields)
          Scans the tree from this point to lookup field names.
 boolean identifyFields(java.util.HashMap fields, java.util.HashMap isAttributeOf)
          This version also sets the isAttributeOf field.
 Node insertNode(Node newNode, Node current)
          Inserts a node starting at current level, then bubbles up to the proper precedence level.
 boolean isBoolOp()
          Is this a boolean operator?
 Node isolateField(java.lang.String field, java.util.HashMap fields)
          turns: XX (zone1, zone2, su) into ( XX (zone1, zone2) XX su ) It performs the same function for the REL_OP's as well
 boolean isPrefix()
          Is this a prefix operator?
 int isSubtreeWrapped(java.lang.String field)
          Scans the tree from this point to find a "parent" field.
 boolean markFields(java.util.HashMap fields)
          internal method.
 boolean markFields(java.util.HashMap fields, java.util.HashMap isAttributeOf)
          This version also sets the isAttributeOf field.
 void print_debug()
           
 java.lang.String probeParentField()
          Scans the tree from this point to find a "parent" field.
 Node reduceField(java.lang.String field)
           
 Node reduceField(java.lang.String field, Node subTree)
          turns: (X Y) FT into ( X FT Y FT ) NOTE: MUST isolate FT before calling this function.....
 void reduceParens()
          reduces any extraneous parenthesis around single fields, values.
 Node reducePrefixBools()
          reduces any AND/OR prefix ops with a single clause.
 void removeCharacter(char c)
          ONLY do this after identifyFields()
 void removeCharacters(java.lang.String remove)
          ONLY do this after identifyFields()
 Node removeField(java.lang.String field)
          Removes a field from a list.
 Node replaceField(java.lang.String field, Node newFields)
          Replaces a field with either another field or a (sub)list of fields.
 void setAmount(java.lang.String a)
          Sets the amount of this node.
 void setArity(int a)
          Set the arity of this node.
 void setAttributeField(java.lang.String n)
          Sets the attributeField string.
 void setLeft(Node n)
          Set the left child of this node.
 void setLevel(int l)
          Sets the level or parenthesis depth .
 void setName(java.lang.String n)
          Sets the name string.
 void setParent(Node n)
          Set the parent of this node.
 void setPrecedence(int p)
          Sets the precedence of this node.
 void setPrefix(boolean p)
          Set the prefix status of this node.
 void setRight(Node n)
          Set the right child of this node.
 void setType(int t)
          Set the type of this node.
 java.lang.String toEnglishString()
           
 java.lang.String toEnglishString(java.util.HashMap fields)
          if the fields HashMap is not null it contains the fieldId -> fieldName mapping.
 java.lang.String toHighlightString(java.util.HashMap replace, java.lang.String ignore)
          Same as toString except removes all ignore characters from values.
 java.lang.String toString()
          Convert to a string using a preorder scan of the tree.
 java.lang.String toString(java.util.HashMap replace)
          Convert to a string using a preorder scan of the tree.
 java.lang.String toString(java.util.HashMap replace, java.util.HashMap pre_wrap, java.util.HashMap post_wrap)
          Convert to a string using a preorder scan of the tree.
 java.lang.String toTreeString()
           
 java.lang.String toTreeString(int level)
           
 Node wrapFields(java.lang.String field, java.util.HashMap fields)
          Wraps fields not in zone or field ops with zone.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(java.lang.String nm,
            Lexer l,
            int t,
            int a,
            int p)
Constructor which bypasses the table lookup.

Parameters:
nm - the name of the symbol.
l - the level of the symbol.
t - the type of the symbol.
p - the precedence of the symbol.

Node

public Node(java.lang.String nm,
            Lexer l,
            SymbolTable st)
Constructor which performs a symbol table lookup if the symbol is not found, assume it is a word.

Parameters:
l - the instance of the lexer.
nm - the name of the symbol.

Node

public Node(java.lang.String nm,
            Node n)
Constructor to clone a node Note: MUST setLeft(), setRight(), setParent() on the new node.

Parameters:
n - the node to be cloned

Node

public Node(Node n)
Constructor to clone a node Note: MUST setLeft(), setRight(), setParent() on the new node.

Parameters:
n - the node to be cloned
Method Detail

getName

public java.lang.String getName()
Returns the string for the human readable name of the symbol.


setAttributeField

public void setAttributeField(java.lang.String n)
Sets the attributeField string.


getAttributeField

public java.lang.String getAttributeField()
Returns the string for attributeField. Note: can be null


setName

public void setName(java.lang.String n)
Sets the name string.


getLevel

public int getLevel()
Returns the depth that this node is nested within parens.


setLevel

public void setLevel(int l)
Sets the level or parenthesis depth .


getAmount

public java.lang.String getAmount()
Returns the amount of this node.


setAmount

public void setAmount(java.lang.String a)
Sets the amount of this node.


getType

public int getType()
Returns the type of this node.


setType

public void setType(int t)
Set the type of this node.


getArity

public int getArity()
Returns the arity of this node.


setArity

public void setArity(int a)
Set the arity of this node.


getPrecedence

public int getPrecedence()
Returns the precedence of this node.


setPrecedence

public void setPrecedence(int p)
Sets the precedence of this node.


getLeftPrune

public boolean getLeftPrune()
Returns the left_prune of this node.


getRightPrune

public boolean getRightPrune()
Returns the right_prune of this node.


getParent

public Node getParent()
Get the parent of this node.


setParent

public void setParent(Node n)
Set the parent of this node.


getLeft

public Node getLeft()
Get the left child of this node.


setLeft

public void setLeft(Node n)
Set the left child of this node.


getRight

public Node getRight()
Get the right child of this node.


setRight

public void setRight(Node n)
Set the right child of this node.


setPrefix

public void setPrefix(boolean p)
Set the prefix status of this node.


isPrefix

public boolean isPrefix()
Is this a prefix operator?


hasBoolOp

public boolean hasBoolOp()
Does this tree contain a boolean operator?


isBoolOp

public boolean isBoolOp()
Is this a boolean operator?


insertNode

public Node insertNode(Node newNode,
                       Node current)
Inserts a node starting at current level, then bubbles up to the proper precedence level. returns the new root node or null if root hasn't changed


probeParentField

public java.lang.String probeParentField()
Scans the tree from this point to find a "parent" field.


isSubtreeWrapped

public int isSubtreeWrapped(java.lang.String field)
Scans the tree from this point to find a "parent" field.


identifyFields

public boolean identifyFields(java.util.HashMap fields)
Scans the tree from this point to lookup field names.


markFields

public boolean markFields(java.util.HashMap fields)
internal method. Descend from here to lookup fields.


identifyFields

public boolean identifyFields(java.util.HashMap fields,
                              java.util.HashMap isAttributeOf)
This version also sets the isAttributeOf field.


markFields

public boolean markFields(java.util.HashMap fields,
                          java.util.HashMap isAttributeOf)
This version also sets the isAttributeOf field.


hasIN

public boolean hasIN()
Sees if the subtree contains an , or


wrapFields

public Node wrapFields(java.lang.String field,
                       java.util.HashMap fields)
Wraps fields not in zone or field ops with zone.


getWords

public java.util.HashSet getWords()
Returns a HashSet containing all (unidentified) field nodes


replaceField

public Node replaceField(java.lang.String field,
                         Node newFields)
Replaces a field with either another field or a (sub)list of fields. WARNING: This function modifies the tree structure.


removeField

public Node removeField(java.lang.String field)
Removes a field from a list. It does not go deeper than the fields. WARNING: This function modifies the tree structure.


removeCharacters

public void removeCharacters(java.lang.String remove)
ONLY do this after identifyFields()


removeCharacter

public void removeCharacter(char c)
ONLY do this after identifyFields()


breakOnEOSChars

public void breakOnEOSChars()
Breaks strings on EOS characters (?, !, and . by default). This only appies to strings. Note: ONLY do this after identifyFields()


breakOnEOSChars

public void breakOnEOSChars(java.lang.String eos)

clone

public java.lang.Object clone()
Clones a tree (or sub-tree) and returns the root of the new tree.


isolateField

public Node isolateField(java.lang.String field,
                         java.util.HashMap fields)
turns: XX (zone1, zone2, su) into ( XX (zone1, zone2) XX su ) It performs the same function for the REL_OP's as well


reduceField

public Node reduceField(java.lang.String field)

reduceField

public Node reduceField(java.lang.String field,
                        Node subTree)
turns: (X Y) FT into ( X FT Y FT ) NOTE: MUST isolate FT before calling this function.....


combineFields

public Node combineFields()
Combines the zone to the highest level. e.g. 'x' BODY 'y' BODY
is converted to:
('x' 'y') BODY


bypassPrefixOps

public Node bypassPrefixOps()
turns: ((X Y)) FT into (X Y) FT Certain prefix ops are meaningless when rules are applied.


hasPrefixOps

public boolean hasPrefixOps()
Checks whether prefix ops are used. Suppresses rules application.


applyRules

public Node applyRules(QueryRules qr,
                       java.lang.String field)
turns: X field into ( query rules applied ) NOTE: MUST isolate field before calling this function.....


applyRules

public Node applyRules(QueryRules qr,
                       java.lang.String field,
                       java.lang.String defaultField)

checkPrefix

public boolean checkPrefix()
checks whether the prefix proximity/evidence operator is operating on a list. It is a verity syntax error if it is not.


reduceParens

public void reduceParens()
reduces any extraneous parenthesis around single fields, values.


reducePrefixBools

public Node reducePrefixBools()
reduces any AND/OR prefix ops with a single clause. E.g.: ((red SU), (white ti, blue ti)) becomes: (red SU, (white ti, blue ti))


findField

public boolean findField(java.lang.String field)
Looks for a field within this subtree.


findAllFields

public int findAllFields(java.util.HashSet fields)
Looks for all fields within this subtree.


adjustLevel

public void adjustLevel(int adjust)
adjusts the level (paranthetical) from this point down.


print_debug

public void print_debug()

getRulesValueString

public java.lang.String getRulesValueString()
Pull all values out of the query. Used for applying rules.


getAllValues

public void getAllValues(java.util.LinkedList a)
Pull all values out of the query. Used for query rules (allow dups)


getAllValues

public void getAllValues(java.util.LinkedList a,
                         boolean bPrint,
                         boolean bReplace)
Pull all values out of the query. Used for query rules (allow dups)


getValues

public void getValues(java.util.HashSet a)
Pull all values out of the query. Used for full text highlighting.


getValues

public void getValues(java.util.HashSet a,
                      boolean bPrint,
                      boolean bReplace)
Pull all values out of the query. Used for full text highlighting.


toString

public java.lang.String toString()
Convert to a string using a preorder scan of the tree.


toString

public java.lang.String toString(java.util.HashMap replace)
Convert to a string using a preorder scan of the tree.


toHighlightString

public java.lang.String toHighlightString(java.util.HashMap replace,
                                          java.lang.String ignore)
Same as toString except removes all ignore characters from values.


toString

public java.lang.String toString(java.util.HashMap replace,
                                 java.util.HashMap pre_wrap,
                                 java.util.HashMap post_wrap)
Convert to a string using a preorder scan of the tree.


toTreeString

public java.lang.String toTreeString()

toTreeString

public java.lang.String toTreeString(int level)

toEnglishString

public java.lang.String toEnglishString()

toEnglishString

public java.lang.String toEnglishString(java.util.HashMap fields)
if the fields HashMap is not null it contains the fieldId -> fieldName mapping. The English query will substitute fieldId with fieldName.