com.raritantechnologies.dieselpoint.parser
Class Node

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

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

  COPYRIGHT NOTICE
  SOFTWARE CONTAINING TRADE SECRETS

  Copyright 2003 Raritan Technologies Inc. [RTI] All rights reserved.

  This software and documentation constitute an unpublished work and contain
  valuable trade secrets and proprietary information belonging to RTI. None
  of the foregoing material may be copied, duplicated or disclosed without
  the express written permission of RTI. RTI EXPRESSLY DISCLAIMS ANY AND ALL
  WARRANTIES CONCERNING THIS SOFTWARE AND DOCUMENTATION, INCLUDING ANY
  WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR ANY PARTICULAR PURPOSE,
  AND WARRANTIES OF PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE
  FROM COURSE OF DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR
  IMPLIED WITH RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION.
  Under no circumstances shall RTI be liable for incidental, special,
  indirect, direct or consequential damages or loss of profits, interruption
  of business, or related expenses which may arise from use of software or
  documentation, including but not limited to those resulting from defects
  in software and/or documentation, or loss or inaccuracy of data of any kind.
  


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)
           
 java.lang.Object clone()
          Clones a tree (or sub-tree) and returns the root of the new tree.
 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.
 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 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?
 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.
 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.
 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.
 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 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 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 toTreeString()
          Convert to a string using a preorder scan of the tree.
 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 .


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.


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


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()


clone

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


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.....


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)

reduceParens

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


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.


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.


toTreeString

public java.lang.String toTreeString()
Convert to a string using a preorder scan of the tree. public String toString(HashMap replace, HashMap pre_wrap, HashMap post_wrap) { StringBuffer sb = new StringBuffer(); int wrap_level = 0; String key; // Does this entire subtree need to be pruned? if ((this.getType() != SymbolTable.OR_OP && this.getType() != SymbolTable.ANY_OP && this.getType() != SymbolTable.COMMA_OP && this.getType() != SymbolTable.ACCRUE_OP && this.getType() != SymbolTable.SUM_OP) && (this.left_prune || this.right_prune)) { return ""; } // see if we need to wrap the entire subtree (with AND as the root) if (pre_wrap != null && post_wrap != null && (this.getType() == SymbolTable.AND_OP || this.getType() == SymbolTable.ALL_OP || this.getType() == SymbolTable.PRODUCT_OP)) { // do an initial probe to get the "parent" field // i.e. a field with no isAttributeOf in PDD String parentField = this.probeParentField(); if (parentField != null && pre_wrap.containsKey(parentField.toUpperCase()) && post_wrap.containsKey(parentField.toUpperCase())) { parentField = parentField.toUpperCase(); // now see if all fields in this subtree are either the // field itself or are attributes of the field. if (this.isSubtreeWrapped(parentField) > 1) { String pre = (String)pre_wrap.get(parentField); String post = (String)post_wrap.get(parentField); sb.append("("); sb.append((String)pre_wrap.get(parentField)); // note: the wrapping is turned off in this subtree sb.append(this.toString(replace, null, null)); sb.append((String)post_wrap.get(parentField)); sb.append(")"); return sb.toString(); } } } // see if we need to wrap this clause if (this.getType() == SymbolTable.REL_OP || this.getType() == SymbolTable.IN_OP) { // see if we need to wrap the left or right subtree if (pre_wrap != null && this.getLeft() != null && this.getRight() != null) { Iterator wrapKeys = pre_wrap.keySet().iterator(); while (wrapKeys.hasNext()) { key = (String)wrapKeys.next(); if (this.getType() == SymbolTable.REL_OP && this.getLeft().findField(key) || this.getType() == SymbolTable.IN_OP && this.getRight().findField(key)) { wrap_level++; sb.append("("); sb.append((String)pre_wrap.get(key)); } } } } if (parent != null && parent.getLevel() < this.getLevel()) { sb.append("("); } if (this.getLeft() != null && ! left_prune) { sb.append(this.getLeft().toString(replace, pre_wrap, post_wrap)); } // Collapse out the boolean op if we've got a bum leg if (((this.getType() == SymbolTable.OR_OP || this.getType() == SymbolTable.ANY_OP || this.getType() == SymbolTable.COMMA_OP || this.getType() == SymbolTable.ACCRUE_OP || this.getType() == SymbolTable.SUM_OP) && ! (left_prune || right_prune)) || ((this.getType() != SymbolTable.OR_OP && this.getType() != SymbolTable.ANY_OP && this.getType() != SymbolTable.COMMA_OP && this.getType() != SymbolTable.ACCRUE_OP && this.getType() != SymbolTable.SUM_OP) && ! (left_prune && right_prune))) { // sb.append(" "); String s = this.getName(); if (this.getType() == SymbolTable.FIELD) { if (replace != null) { String replacement = (String) replace.get(s.toUpperCase()); if (replacement != null) { // Only wrap the replaced value if it is // not already in a list. if (this.getParent() == null || this.getParent().getType() != SymbolTable.COMMA_OP) { sb.append("("); } sb.append(replacement); if (this.getParent() == null || this.getParent().getType() != SymbolTable.COMMA_OP) { sb.append(")"); } } else { sb.append(s); } } else { sb.append(s); } } else if (this.getType() == SymbolTable.WORD) { if (s.indexOf(" ") > 0) { sb.append("("); sb.append(s); sb.append(")"); } else { sb.append(s); } } else { sb.append(s); } } if (DEBUG) { print_debug(this); } // sb.append(" "); if (this.getRight() != null && ! right_prune) { sb.append(this.getRight().toString(replace, pre_wrap, post_wrap)); } if (parent != null && parent.getLevel() < this.getLevel()) { sb.append(")"); } // see if we need to wrap this clause if (this.getType() == SymbolTable.REL_OP || this.getType() == SymbolTable.IN_OP) { // see if we need to wrap the left or right subtree if (post_wrap != null && this.getLeft() != null && this.getRight() != null) { Iterator wrapKeys = post_wrap.keySet().iterator(); while (wrapKeys.hasNext()) { key = (String)wrapKeys.next(); if (this.getType() == SymbolTable.REL_OP && this.getLeft().findField(key) || this.getType() == SymbolTable.IN_OP && this.getRight().findField(key)) { wrap_level--; sb.append((String)post_wrap.get(key)); sb.append(")"); } } } } if (wrap_level != 0) { System.err.println("Warning: Unbalanced wrapping of "+sb.toString()); } return sb.toString(); }


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.