cz.cuni.mff.mirovsky.trees
Class NGTree

java.lang.Object
  extended by cz.cuni.mff.mirovsky.trees.NGTree

public class NGTree
extends java.lang.Object

A class containing a single tree


Field Summary
static char MATCHING_NODES_DELIMITER
          a delimiter of pairs of numbers of matching query nodes and result tree nodes.
static char MATCHING_NODES_QUERY_DELIMITER
          a delimiter of a number of a query node and a number of its matching result tree node.
static char MATCHING_NODES_TREES_DELIMITER
          a delimiter of query trees in lists of matching nodes.
 
Constructor Summary
NGTree(ShowMessagesAble p_mess)
          Creates an empty tree
 
Method Summary
 void addAttributes(int number)
          It increases number of attributes at all nodes by number.
 TNode findNodeById(int id_index, java.lang.String value)
          Searches for a node in the tree that has a given id.
 NGTree getClone()
          Returns a deep copy of the tree
 int getDepth(TNode node)
          Returns the distance between the node and the root of the tree.
 int getFirstMatchingNodeDepthOrder(boolean count_hidden)
          Searches for the depth-first order of the node in the tree that matches the root of the first tree of the query, counted from 1.
 boolean getFlagTreeChanged()
          Says whether the tree has changed and coordinates of its nodes must be calculated.
 int getHeight()
          Returns the height of the tree in pixels.
 TNode getChosenNode()
          Returns the actually selected node.
 int getChosenNodeDepthOrder(boolean count_hidden)
          Returns depth-first order of the chosen node, counted from 1.
 java.lang.String getId(NGTreeHead head)
          Returns an id of the tree.
 TNode[] getNodesArray()
          Returns a new array of all nodes in the tree.
 int getNumberOfHiddenNodes()
          Returns the number of hidden nodes in the tree.
 int getNumberOfNodes()
          Returns the total number of nodes in the tree.
 TNode getRoot()
          Returns the root of the tree.
 java.lang.String getSentenceString(NGTreeHead head)
          Assembles and returns the sentence belonging to the tree.
 int getWidth()
          Returns the width of the tree in pixels.
 int getXStart()
          Returns the x-coordinate of the top-left corner of the tree in a forest.
 int getYStart()
          Returns the y-coordinate of the top-left corner of the tree in a forest.
 boolean isEmpty()
          Signals whether the tree is empty
 int readTree(NGTreeHead head, char[] p_source, int start_position, int p_number_of_attributes)
          Reads a whole tree from p_source in FS format (without a head).
 void setFlagTreeChanged(boolean new_flag)
          Signals whether the tree has changed and coordinates of its nodes must be calculated.
 void setHeight(int tree_height)
          Sets the height of the tree in pixels.
 int setChosenByPosition(int x, int y, int dosah_mysi, boolean allow_hidden)
          Marks a node at given coordinates as selected.
 void setChosenNodeByDepthOrder(int order)
          Marks a node with given order as selected.
 void setMatchingMetaTags(NGTreeHead head)
          It sets the matching meta tag at the matching nodes of the tree.
 void setMatchingNodes(java.lang.String s)
          Sets nodes matching a query according to a given list of matching nodes.
 void setWidth(int tree_width)
          Sets the width of the tree in pixels.
 void setXStart(int x_start)
          Sets the x-coordinate of the top-left corner of the tree in a forest.
 void setYStart(int y_start)
          Sets the y-coordinate of the top-left corner of the tree in a forest.
 java.lang.String toFSString(boolean with_head, NGTreeHead head)
          Returns FS representation of the tree (with or without the head).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATCHING_NODES_DELIMITER

public static final char MATCHING_NODES_DELIMITER
a delimiter of pairs of numbers of matching query nodes and result tree nodes. It is used in messages from the server.

See Also:
Constant Field Values

MATCHING_NODES_QUERY_DELIMITER

public static final char MATCHING_NODES_QUERY_DELIMITER
a delimiter of a number of a query node and a number of its matching result tree node. It is used in messages from the server.

See Also:
Constant Field Values

MATCHING_NODES_TREES_DELIMITER

public static final char MATCHING_NODES_TREES_DELIMITER
a delimiter of query trees in lists of matching nodes. It is used in messages from the server.

See Also:
Constant Field Values
Constructor Detail

NGTree

public NGTree(ShowMessagesAble p_mess)
Creates an empty tree

Parameters:
p_mess - an object capable of displaying messages
Method Detail

getClone

public NGTree getClone()
Returns a deep copy of the tree

Returns:
deep copy of the tree

getWidth

public int getWidth()
Returns the width of the tree in pixels.

Returns:
the width of the tree in pixels

setWidth

public void setWidth(int tree_width)
Sets the width of the tree in pixels.

Parameters:
tree_width - the width of the tree in pixels

getHeight

public int getHeight()
Returns the height of the tree in pixels.

Returns:
the height of the tree in pixels

setHeight

public void setHeight(int tree_height)
Sets the height of the tree in pixels.

Parameters:
tree_height - the height of the tree in pixels

getXStart

public int getXStart()
Returns the x-coordinate of the top-left corner of the tree in a forest.

Returns:
the x-coordinate of the top-left corner fo the tree in a forest

setXStart

public void setXStart(int x_start)
Sets the x-coordinate of the top-left corner of the tree in a forest.

Parameters:
x_start - the x-coordinate of the top-left corner fo the tree in a forest

getYStart

public int getYStart()
Returns the y-coordinate of the top-left corner of the tree in a forest.

Returns:
the y-coordinate of the top-left corner fo the tree in a forest

setYStart

public void setYStart(int y_start)
Sets the y-coordinate of the top-left corner of the tree in a forest.

Parameters:
y_start - the y-coordinate of the top-left corner fo the tree in a forest

toFSString

public java.lang.String toFSString(boolean with_head,
                                   NGTreeHead head)
Returns FS representation of the tree (with or without the head).

Parameters:
with_head - says if the head should be included in the FS representation
head - the head belonging to the tree
Returns:
the FS representation of the tree

setFlagTreeChanged

public void setFlagTreeChanged(boolean new_flag)
Signals whether the tree has changed and coordinates of its nodes must be calculated.

Parameters:
new_flag - value true signals that the coordinates need to be calculated

getFlagTreeChanged

public boolean getFlagTreeChanged()
Says whether the tree has changed and coordinates of its nodes must be calculated.

Returns:
true iff the coordinates need to be calculated

isEmpty

public boolean isEmpty()
Signals whether the tree is empty

Returns:
true iff the tree is empty

getRoot

public TNode getRoot()
Returns the root of the tree.

Returns:
the root of the tree

getNumberOfNodes

public int getNumberOfNodes()
Returns the total number of nodes in the tree.

Returns:
the total number of nodes in the tree

getNumberOfHiddenNodes

public int getNumberOfHiddenNodes()
Returns the number of hidden nodes in the tree.

Returns:
the number of hidden nodes in the tree

readTree

public int readTree(NGTreeHead head,
                    char[] p_source,
                    int start_position,
                    int p_number_of_attributes)
Reads a whole tree from p_source in FS format (without a head).

Parameters:
head - a head belonging to the tree
p_source - the source in FS format
start_position - a position in p_source of the first character to be read
p_number_of_attributes - number of attributes in the head
Returns:
the root of the tree

addAttributes

public void addAttributes(int number)
It increases number of attributes at all nodes by number. The new attributes are added at the end of the list of attributes. Values of the new attributes are set empty (""). The head of the tree is not changed (must be changed separately).

Parameters:
number - number of attributes to be added

setMatchingMetaTags

public void setMatchingMetaTags(NGTreeHead head)
It sets the matching meta tag at the matching nodes of the tree. The matching meta tag marks matching nodes after the tree is saved e.g. to local disc.

Parameters:
head - a head belonging to the tree

getChosenNode

public TNode getChosenNode()
Returns the actually selected node.

Returns:
the selected node

getChosenNodeDepthOrder

public int getChosenNodeDepthOrder(boolean count_hidden)
Returns depth-first order of the chosen node, counted from 1. If count_hidden is true, hidden nodes are counted as normal nodes. If count_hidden is false, hidden nodes are not counted; if the chosen node is hidden, the order of its nearest non-hidden predecessor is returned.

Parameters:
count_hidden - says if hidden nodes should be counted
Returns:
-1 if not found; a positive value (depth-first order counted from 1) if found; 0 if the chosen node is hidden, count_hidden is false and there is no non-hidden node is on the path from it to the root

setChosenNodeByDepthOrder

public void setChosenNodeByDepthOrder(int order)
Marks a node with given order as selected.

Parameters:
order - depth-first order of the node to be selected. The root has order 1.

setChosenByPosition

public int setChosenByPosition(int x,
                               int y,
                               int dosah_mysi,
                               boolean allow_hidden)
Marks a node at given coordinates as selected. It goes through the tree depth-first and if a node is found close enought to the given coordinates, it is marked as selected.

Parameters:
x - the x-coordinate in pixels
y - the y-coordinate in pixels
dosah_mysi - a maximum allowed distance of the node from the coordinates if the node is to be selected
allow_hidden - controls if a hidden node can be selected
Returns:
depth-first order of the selected node counted from 1; 0 if not found

setMatchingNodes

public void setMatchingNodes(java.lang.String s)
Sets nodes matching a query according to a given list of matching nodes. The whole lists consists of partial lists of nodes matching individul query trees. The partial lists are separated with MATCHING_NODES_TREES_DELIMITER. Pairs of matching nodes are separated with MATCHING_NODES_DELIMITER. Matching nodes in each pair are separated with MATCHING_NODES_QUERY_DELIMITER. In the pair, the first number is a depth-first order of a result tree node, the second number is a depth-first order of its matching query node, all counted from 1. The result tree nodes in the partial lists must be in ascending order.

Parameters:
s - list of matching nodes

getFirstMatchingNodeDepthOrder

public int getFirstMatchingNodeDepthOrder(boolean count_hidden)
Searches for the depth-first order of the node in the tree that matches the root of the first tree of the query, counted from 1. If count_hidden is true, hidden nodes are counted as normal nodes. If count_hidden is false, hidden nodes are not counted; if the matching node is hidden, the order of its nearest non-hidden predecessor is returned.

Parameters:
count_hidden - says if hidden nodes should be counted
Returns:
the depth-first order of the node (counted from 1) if found; -1 if not found; returns 0 if the matching node is hidden, count_hidden is false and there is no non-hidden node is on the path from it to the root

getSentenceString

public java.lang.String getSentenceString(NGTreeHead head)
Assembles and returns the sentence belonging to the tree.

Parameters:
head - a head belonging to the tree
Returns:
a sentence belonging to the tree

getId

public java.lang.String getId(NGTreeHead head)
Returns an id of the tree. It is a value of attribute id.

Parameters:
head - a head belonging to the tree
Returns:
id of the tree

getNodesArray

public TNode[] getNodesArray()
Returns a new array of all nodes in the tree.

Returns:
an array of all nodes in the tree

getDepth

public int getDepth(TNode node)
Returns the distance between the node and the root of the tree. The depth of the root is 0.

Parameters:
node - a node in the tree
Returns:
the depth of the node

findNodeById

public TNode findNodeById(int id_index,
                          java.lang.String value)
Searches for a node in the tree that has a given id.

Parameters:
id_index - an index of id-attribute in the head of the tree
value - a given id
Returns:
the node with the given id or null if not found