Class TreeDetectionStrategy
java.lang.Object
com.northconcepts.datapipeline.foundations.pipeline.tree.detect.TreeDetectionStrategy
Defines the algorithms used to detect record breaks and fields in a
Tree: an ordered list
of NodeNameRules that classify dynamic element/field names while the tree is being built,
followed by an ordered list of TreeTransformer passes that run over the loaded tree.
The default configuration (standard(boolean)) reproduces the behavior of
Tree.loadXml(java.io.File, boolean) and Tree.loadJson(java.io.File, boolean).
Both lists are editable to plug in custom algorithms:
Tree tree = Tree.loadJson(file, TreeDetectionStrategy.standard(true).enableDateTimeNodeNames());
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddNodeNameRule(NodeNameRule nodeNameRule) Adds a rule that classifies node names as dynamic; a name is dynamic if any rule says so.addRegexNodeNameRule(String pattern) Adds aRegexNodeNameRuleso names matching the whole-name regular expression collapse to wildcards.addTransformer(int index, TreeTransformer transformer) Inserts a pass at the given 0-based position in the run order.addTransformer(TreeTransformer transformer) Appends a pass to run after the existing ones.voidRuns everyTreeTransformeragainst the supplied tree, in order.canonicalizeNodeName(String nodeName) Returns the node name used to key tree nodes while the tree is being built: the XPath wildcard (*) whenoptimizeTreeStructureis set and anyNodeNameRuleclassifies the name as dynamic, otherwise the name unchanged.Removes all node name rules, including the defaultStandardNodeNameRule.Removes all passes, including the standard detection passes.Adds aDateTimeNodeNameRuleso date/timestamp names collapse to wildcards.Inserts aCollapseSiblingPatternspass ahead of the detection passes so siblings with a derivable naming pattern (for exampleitem-1,item-2,item-3) collapse into one wildcard node.Ensures aCollapseSiblingPatternspass is present (inserting one ahead of the detection passes when missing) and that it includes aStructureSiblingSetRule, so structurally similar siblings collapse regardless of their names.Returns the editable list of rules that classify node names as dynamic.Returns the editable list of passes thatapply(Tree)runs, in order.booleanIndicates if dynamic names should collapse tree nodes together while the tree is being built (default false).booleanisWildcardPathSegment(String nodeName) Indicates if anyNodeNameRuleclassifies the supplied name as dynamic.setOptimizeTreeStructure(boolean optimizeTreeStructure) Indicates if dynamic names should collapse tree nodes together while the tree is being built (default false); unlikestandard(boolean), it does not add anOptimizeTreeStructurepass.static TreeDetectionStrategystandard(boolean optimizeTreeStructure) Returns the default strategy:StandardNodeNameRuleplus theDetectFieldCandidates,DetectRecordBreakCandidates,OptimizeTreeStructure(only whenoptimizeTreeStructureis set), andMakeFieldNamesUniquepasses.
-
Constructor Details
-
TreeDetectionStrategy
public TreeDetectionStrategy()Creates the same strategy asstandard(false).
-
-
Method Details
-
standard
Returns the default strategy:StandardNodeNameRuleplus theDetectFieldCandidates,DetectRecordBreakCandidates,OptimizeTreeStructure(only whenoptimizeTreeStructureis set), andMakeFieldNamesUniquepasses. -
apply
Runs everyTreeTransformeragainst the supplied tree, in order. -
canonicalizeNodeName
Returns the node name used to key tree nodes while the tree is being built: the XPath wildcard (*) whenoptimizeTreeStructureis set and anyNodeNameRuleclassifies the name as dynamic, otherwise the name unchanged. -
isWildcardPathSegment
Indicates if anyNodeNameRuleclassifies the supplied name as dynamic. UnlikecanonicalizeNodeName(String), this check is not gated byoptimizeTreeStructure; XPath expressions always collapse dynamic segments to wildcards. -
isOptimizeTreeStructure
public boolean isOptimizeTreeStructure()Indicates if dynamic names should collapse tree nodes together while the tree is being built (default false). This gates only node keying; it does not change the transformer list. -
setOptimizeTreeStructure
Indicates if dynamic names should collapse tree nodes together while the tree is being built (default false); unlikestandard(boolean), it does not add anOptimizeTreeStructurepass. -
getTransformers
Returns the editable list of passes thatapply(Tree)runs, in order. -
addTransformer
Appends a pass to run after the existing ones. -
addTransformer
Inserts a pass at the given 0-based position in the run order. -
clearTransformers
Removes all passes, including the standard detection passes. -
getNodeNameRules
Returns the editable list of rules that classify node names as dynamic. -
addNodeNameRule
Adds a rule that classifies node names as dynamic; a name is dynamic if any rule says so. -
clearNodeNameRules
Removes all node name rules, including the defaultStandardNodeNameRule. -
enableSiblingPatternCollapse
Inserts aCollapseSiblingPatternspass ahead of the detection passes so siblings with a derivable naming pattern (for exampleitem-1,item-2,item-3) collapse into one wildcard node. Does nothing if one is already present. -
enableDateTimeNodeNames
Adds aDateTimeNodeNameRuleso date/timestamp names collapse to wildcards. Does nothing if one is already present. -
addRegexNodeNameRule
Adds aRegexNodeNameRuleso names matching the whole-name regular expression collapse to wildcards. May be called multiple times with different expressions. -
enableStructureSiblingCollapse
Ensures aCollapseSiblingPatternspass is present (inserting one ahead of the detection passes when missing) and that it includes aStructureSiblingSetRule, so structurally similar siblings collapse regardless of their names. Does nothing if one is already present.
-