Package de.unirostock.sems.xmlutils.ds
Class TextNode
- java.lang.Object
-
- de.unirostock.sems.xmlutils.ds.TreeNode
-
- de.unirostock.sems.xmlutils.ds.TextNode
-
public class TextNode extends TreeNode
The Class TextNode representing text content inside a document.- Author:
- Martin Scharm
-
-
Constructor Summary
Constructors Constructor Description TextNode(TextNode toCopy, DocumentNode parent, int numChild)Copies a text node.TextNode(String text, DocumentNode parent, TreeDocument doc, int numChild, Weighter w, int level)Instantiates a new text node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringdump(String prefix)Dump this node.booleanevaluate(ConnectionManager conMgmr)Evaluate the modifications of this node.voidgetNodeStats(HashMap<String,Integer> map)Gets the node statistics of the subtree rooted in this node: tagname => number nodes having this tag name.StringgetOwnHash()Gets the hash of this single node (w/o its subtree).org.jdom2.ElementgetSubDoc(org.jdom2.Element parent)Attaches the subtree rooted in this node to the node parent.StringgetSubTreeHash()Gets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.StringgetTagName()Gets the tag name.StringgetText()Gets the text content of this node.doublegetTextDistance(TextNode cmp)Gets the distance between the texts of two nodes.doublegetWeight()Gets the weight of this node.protected voidreSetupStructureDown(TreeDocument doc, int numChild)Re-setup the document structure downwards.protected voidreSetupStructureUp()Re-setup the document structure upwards.voidsetText(String newText)Sets the text content of this node.StringtoString()-
Methods inherited from class de.unirostock.sems.xmlutils.ds.TreeNode
addModification, contentDiffers, getDocument, getLevel, getModification, getParent, getType, getXPath, hasModification, isRoot, networkDiffers, resetModifications, rmModification, setModification
-
-
-
-
Constructor Detail
-
TextNode
public TextNode(TextNode toCopy, DocumentNode parent, int numChild)
Copies a text node.- Parameters:
toCopy- the node to copyparent- the new parent or null if this is going to be rootnumChild- 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 nodeparent- the parent node in the treedoc- the documentnumChild- the number of that child among its siblingsw- the weighterlevel- 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:TreeNodeEvaluate the modifications of this node. Just useful for tree comparisons.
-
dump
public String dump(String prefix)
Description copied from class:TreeNodeDump this node. Just for debugging purposes..
-
getSubDoc
public org.jdom2.Element getSubDoc(org.jdom2.Element parent)
Description copied from class:TreeNodeAttaches the subtree rooted in this node to the node parent. Recursively attaches its children. Will fail forparent == null && this.getType () == TreeNode.TEXT_NODEThat means a text node cannot become root.
-
reSetupStructureDown
protected void reSetupStructureDown(TreeDocument doc, int numChild)
Description copied from class:TreeNodeRe-setup the document structure downwards. (e.g. recompute XPaths etc.)- Specified by:
reSetupStructureDownin classTreeNode- Parameters:
doc- the document this node corresponds tonumChild- the child number of this node
-
reSetupStructureUp
protected void reSetupStructureUp()
Description copied from class:TreeNodeRe-setup the document structure upwards. (e.g. recompute hashes etc.)- Specified by:
reSetupStructureUpin classTreeNode
-
getNodeStats
public void getNodeStats(HashMap<String,Integer> map)
Description copied from class:TreeNodeGets the node statistics of the subtree rooted in this node: tagname => number nodes having this tag name.- Specified by:
getNodeStatsin classTreeNode- Parameters:
map- the map to write our statistics to
-
getWeight
public double getWeight()
Description copied from class:TreeNodeGets the weight of this node.
-
getOwnHash
public String getOwnHash()
Description copied from class:TreeNodeGets the hash of this single node (w/o its subtree).- Specified by:
getOwnHashin classTreeNode- Returns:
- the hash of the node
-
getSubTreeHash
public String getSubTreeHash()
Description copied from class:TreeNodeGets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.- Specified by:
getSubTreeHashin classTreeNode- Returns:
- the hash of the current subtree
-
getTagName
public String getTagName()
Description copied from class:TreeNodeGets the tag name. For document nodes it's the actual tag name, in case of text nodes you'll receiveTreeNode.TEXT_TAG.- Specified by:
getTagNamein classTreeNode- 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
-
-