Class: Tabula::Detectors::Nurminen

Inherits:
DetectionAlgorithm show all
Defined in:
lib/tabula/detectors/nurminen_detection_algorithm.rb

Overview

Nurminen's table detection algorithm. Based on Anssi Nurminen's master's thesis approach. Detects tables using text alignment and edge analysis.

Defined Under Namespace

Classes: TextEdge

Constant Summary collapse

EDGE_LEFT =

Text edge types

0
EDGE_MID =
1
EDGE_RIGHT =
2
MIN_ROWS =

Minimum rows for a valid table

2
OVERLAP_THRESHOLD =

Overlap threshold for duplicate detection

0.9

Instance Method Summary collapse

Methods inherited from DetectionAlgorithm

detect, #initialize, #name

Constructor Details

This class inherits a constructor from Tabula::Detectors::DetectionAlgorithm

Instance Method Details

#detect(page) ⇒ Array<Rectangle>

Detect table areas on a page

Parameters:

  • page (Page) —

    page to detect tables on

Returns:

  • (Array<Rectangle>) —

    detected table areas



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tabula/detectors/nurminen_detection_algorithm.rb', line 23

def detect(page)
  tables = []

  # First, try ruling-based detection
  ruling_tables = detect_from_rulings(page)
  tables.concat(ruling_tables)

  # Then, try text-based detection
  text_tables = detect_from_text(page)

  # Merge results, removing duplicates
  text_tables.each do |text_table|
    tables << text_table unless overlaps_existing?(text_table, tables)
  end

  tables
end