Class: Tabula::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tabula/configuration.rb

Overview

Configuration class for customizable extraction parameters. All thresholds can be adjusted to tune extraction behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Configuration

Returns a new instance of Configuration.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tabula/configuration.rb', line 61

def initialize
  # Ruling detection
  @orientation_tolerance = 1.0
  @intersection_tolerance = 1.0
  @ruling_thickness_threshold = 8.0

  # Text element merging
  @word_gap_multiplier = 0.5
  @line_gap_multiplier = 0.5

  # Cell detection
  @min_cells = 4
  @min_table_dimension = 10.0
  @cell_tolerance = 2.0

  # Table detection
  @min_rows = 2
  @overlap_threshold = 0.9
  @tabular_ratio_threshold = 0.65
  @edge_clustering_tolerance = 8.0
  @detection_padding = 2.0

  # Rectangle comparison
  @vertical_comparison_threshold = 0.4
end

Instance Attribute Details

#cell_tolerance ⇒ Object

Tolerance for cell corner detection (in points)



37
38
39
# File 'lib/tabula/configuration.rb', line 37

def cell_tolerance
  @cell_tolerance
end

#detection_padding ⇒ Object

Padding around detected table areas (in points)



54
55
56
# File 'lib/tabula/configuration.rb', line 54

def detection_padding
  @detection_padding
end

#edge_clustering_tolerance ⇒ Object

Tolerance for clustering text edges during detection (in points)



51
52
53
# File 'lib/tabula/configuration.rb', line 51

def edge_clustering_tolerance
  @edge_clustering_tolerance
end

#intersection_tolerance ⇒ Object

Tolerance for ruling intersection detection (in points)



14
15
16
# File 'lib/tabula/configuration.rb', line 14

def intersection_tolerance
  @intersection_tolerance
end

#line_gap_multiplier ⇒ Object

Multiplier for determining line boundaries



26
27
28
# File 'lib/tabula/configuration.rb', line 26

def line_gap_multiplier
  @line_gap_multiplier
end

#min_cells ⇒ Object

Minimum number of cells required for a valid table



31
32
33
# File 'lib/tabula/configuration.rb', line 31

def min_cells
  @min_cells
end

#min_rows ⇒ Object

Minimum number of rows required for table detection



42
43
44
# File 'lib/tabula/configuration.rb', line 42

def min_rows
  @min_rows
end

#min_table_dimension ⇒ Object

Minimum dimension (width or height) for a valid table region (in points)



34
35
36
# File 'lib/tabula/configuration.rb', line 34

def min_table_dimension
  @min_table_dimension
end

#orientation_tolerance ⇒ Object

Tolerance for determining if a ruling is horizontal or vertical (in points) Lines with less than this difference in position are considered aligned



11
12
13
# File 'lib/tabula/configuration.rb', line 11

def orientation_tolerance
  @orientation_tolerance
end

#overlap_threshold ⇒ Object

Overlap threshold for merging duplicate table detections



45
46
47
# File 'lib/tabula/configuration.rb', line 45

def overlap_threshold
  @overlap_threshold
end

#ruling_thickness_threshold ⇒ Object

Maximum thickness of a filled rectangle to be treated as a ruling line (in points)



17
18
19
# File 'lib/tabula/configuration.rb', line 17

def ruling_thickness_threshold
  @ruling_thickness_threshold
end

#tabular_ratio_threshold ⇒ Object

Threshold for determining if a table has valid row/column ratio



48
49
50
# File 'lib/tabula/configuration.rb', line 48

def tabular_ratio_threshold
  @tabular_ratio_threshold
end

#vertical_comparison_threshold ⇒ Object

Threshold for vertical overlap comparison



59
60
61
# File 'lib/tabula/configuration.rb', line 59

def vertical_comparison_threshold
  @vertical_comparison_threshold
end

#word_gap_multiplier ⇒ Object

Multiplier for space width when determining word boundaries Lower values = more aggressive word merging



23
24
25
# File 'lib/tabula/configuration.rb', line 23

def word_gap_multiplier
  @word_gap_multiplier
end

Instance Method Details

#with(**overrides) ⇒ Configuration

Create a copy with overrides

Parameters:

  • overrides (Hash) —

    values to override

Returns:



90
91
92
93
94
# File 'lib/tabula/configuration.rb', line 90

def with(**overrides)
  dup.tap do |config|
    overrides.each { |key, value| config.send("#{key}=", value) }
  end
end