Class TextNode


  • public class TextNode
    extends TreeNode
    The Class TextNode representing text content inside a document.
    Author:
    Martin Scharm
    • Constructor Detail

      • TextNode

        public TextNode​(TextNode toCopy,
                        DocumentNode parent,
                        int numChild)
        Copies a text node.
        Parameters:
        toCopy - the node to copy
        parent - the new parent or null if this is going to be root
        numChild - the number of that child among its siblings
      • TextNode

        public TextNode​(String text,
                        DocumentNode parent,
                        TreeDocument doc,
                        int numChild,
                        Weighter w,
                        int level)
        Instantiates a new text node.
        Parameters:
        text - the text stored in this node
        parent - the parent node in the tree
        doc - the document
        numChild - the number of that child among its siblings
        w - the weighter
        level - the level in the tree
    • Method Detail

      • getText

        public String getText()
        Gets the text content of this node.
        Returns:
        the text
      • setText

        public void setText​(String newText)
        Sets the text content of this node. Be Careful: since we have to recalculate all hashes this operation is quite expensive!
        Parameters:
        newText - the text to be stored in this node
      • evaluate

        public boolean evaluate​(ConnectionManager conMgmr)
        Description copied from class: TreeNode
        Evaluate the modifications of this node. Just useful for tree comparisons.
        Specified by:
        evaluate in class TreeNode
        Parameters:
        conMgmr - the connection manager
        Returns:
        true, if node was changed
      • dump

        public String dump​(String prefix)
        Description copied from class: TreeNode
        Dump this node. Just for debugging purposes..
        Specified by:
        dump in class TreeNode
        Parameters:
        prefix - the prefix for a line (indention)
        Returns:
        the produced dump
      • getSubDoc

        public org.jdom2.Element getSubDoc​(org.jdom2.Element parent)
        Description copied from class: TreeNode
        Attaches the subtree rooted in this node to the node parent. Recursively attaches its children. Will fail for parent == null && this.getType () == TreeNode.TEXT_NODE That means a text node cannot become root.
        Specified by:
        getSubDoc in class TreeNode
        Parameters:
        parent - the parent element which will root this node. If null, this node will be root in the document
        Returns:
        the sub doc
      • reSetupStructureDown

        protected void reSetupStructureDown​(TreeDocument doc,
                                            int numChild)
        Description copied from class: TreeNode
        Re-setup the document structure downwards. (e.g. recompute XPaths etc.)
        Specified by:
        reSetupStructureDown in class TreeNode
        Parameters:
        doc - the document this node corresponds to
        numChild - the child number of this node
      • reSetupStructureUp

        protected void reSetupStructureUp()
        Description copied from class: TreeNode
        Re-setup the document structure upwards. (e.g. recompute hashes etc.)
        Specified by:
        reSetupStructureUp in class TreeNode
      • getNodeStats

        public void getNodeStats​(HashMap<String,​Integer> map)
        Description copied from class: TreeNode
        Gets the node statistics of the subtree rooted in this node: tagname => number nodes having this tag name.
        Specified by:
        getNodeStats in class TreeNode
        Parameters:
        map - the map to write our statistics to
      • getWeight

        public double getWeight()
        Description copied from class: TreeNode
        Gets the weight of this node.
        Specified by:
        getWeight in class TreeNode
        Returns:
        the weight
      • getOwnHash

        public String getOwnHash()
        Description copied from class: TreeNode
        Gets the hash of this single node (w/o its subtree).
        Specified by:
        getOwnHash in class TreeNode
        Returns:
        the hash of the node
      • getSubTreeHash

        public String getSubTreeHash()
        Description copied from class: TreeNode
        Gets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.
        Specified by:
        getSubTreeHash in class TreeNode
        Returns:
        the hash of the current subtree
      • getTagName

        public String getTagName()
        Description copied from class: TreeNode
        Gets the tag name. For document nodes it's the actual tag name, in case of text nodes you'll receive TreeNode.TEXT_TAG.
        Specified by:
        getTagName in class TreeNode
        Returns:
        the tag name
      • getTextDistance

        public double getTextDistance​(TextNode cmp)
        Gets the distance between the texts of two nodes. Here it is defined as the Levenshtein distance / max Levenshtein distance.
        Parameters:
        cmp - the node to compare
        Returns:
        the text distance