Class: Markdown::Merge::TableMatchRefiner
- Inherits:
-
Ast::Merge::MatchRefinerBase
- Object
- Ast::Merge::MatchRefinerBase
- Markdown::Merge::TableMatchRefiner
- Defined in:
- lib/markdown/merge/table_match_refiner.rb
Overview
Match refiner for Markdown tables that didn’t match by exact signature.
This refiner uses the TableMatchAlgorithm to pair tables that have:
-
Similar but not identical headers
-
Similar structure (row/column counts)
-
Similar content in key columns
Tables are matched using a multi-factor scoring algorithm that considers:
-
Header cell similarity
-
First column (row label) similarity
-
Overall content overlap
-
Position in document
Instance Attribute Summary collapse
-
#algorithm_options ⇒ Hash
readonly
Options passed to TableMatchAlgorithm.
-
#backend ⇒ Symbol
readonly
The markdown backend being used.
Instance Method Summary collapse
-
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Find matches between unmatched table nodes.
-
#initialize(threshold: DEFAULT_THRESHOLD, algorithm_options: {}, backend: :commonmarker, **options) ⇒ TableMatchRefiner
constructor
Initialize a table match refiner.
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD, algorithm_options: {}, backend: :commonmarker, **options) ⇒ TableMatchRefiner
Initialize a table match refiner.
44 45 46 47 48 |
# File 'lib/markdown/merge/table_match_refiner.rb', line 44 def initialize(threshold: DEFAULT_THRESHOLD, algorithm_options: {}, backend: :commonmarker, **) super(threshold: threshold, node_types: [:table], **) = @backend = backend end |
Instance Attribute Details
#algorithm_options ⇒ Hash (readonly)
Returns Options passed to TableMatchAlgorithm.
34 35 36 |
# File 'lib/markdown/merge/table_match_refiner.rb', line 34 def end |
#backend ⇒ Symbol (readonly)
Returns The markdown backend being used.
37 38 39 |
# File 'lib/markdown/merge/table_match_refiner.rb', line 37 def backend @backend end |
Instance Method Details
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Find matches between unmatched table nodes.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/markdown/merge/table_match_refiner.rb', line 56 def call(template_nodes, dest_nodes, context = {}) template_tables = extract_tables(template_nodes) dest_tables = extract_tables(dest_nodes) return [] if template_tables.empty? || dest_tables.empty? # Build position information for better matching total_template = template_tables.size total_dest = dest_tables.size greedy_match(template_tables, dest_tables) do |t_node, d_node| t_idx = template_tables.index(t_node) || 0 d_idx = dest_tables.index(d_node) || 0 compute_table_similarity(t_node, d_node, t_idx, d_idx, total_template, total_dest) end end |