Class: Markdown::Merge::TableMatchRefiner

Inherits:
Ast::Merge::MatchRefinerBase
  • Object
show all
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

Examples:

Basic usage

refiner = TableMatchRefiner.new(threshold: 0.5)
matches = refiner.call(template_nodes, dest_nodes)

With custom algorithm options

refiner = TableMatchRefiner.new(
  threshold: 0.6,
  algorithm_options: {
    weights: { header_match: 0.4, position: 0.1 }
  }
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threshold: DEFAULT_THRESHOLD, algorithm_options: {}, backend: :commonmarker, **options) ⇒ TableMatchRefiner

Initialize a table match refiner.

Parameters:

  • threshold (Float) (defaults to: DEFAULT_THRESHOLD)

    Minimum score to accept a match (default: 0.5)

  • algorithm_options (Hash) (defaults to: {})

    Options for TableMatchAlgorithm

  • backend (Symbol) (defaults to: :commonmarker)

    Markdown backend for type normalization (default: :commonmarker)



44
45
46
47
48
# File 'lib/markdown/merge/table_match_refiner.rb', line 44

def initialize(threshold: DEFAULT_THRESHOLD, algorithm_options: {}, backend: :commonmarker, **options)
  super(threshold: threshold, node_types: [:table], **options)
  @algorithm_options = algorithm_options
  @backend = backend
end

Instance Attribute Details

#algorithm_optionsHash (readonly)

Returns Options passed to TableMatchAlgorithm.

Returns:

  • (Hash)

    Options passed to TableMatchAlgorithm



34
35
36
# File 'lib/markdown/merge/table_match_refiner.rb', line 34

def algorithm_options
  @algorithm_options
end

#backendSymbol (readonly)

Returns The markdown backend being used.

Returns:

  • (Symbol)

    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.

Parameters:

  • template_nodes (Array)

    Unmatched nodes from template

  • dest_nodes (Array)

    Unmatched nodes from destination

  • context (Hash) (defaults to: {})

    Additional context (may contain :template_analysis, :dest_analysis)

Returns:

  • (Array<MatchResult>)

    Array of table matches



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