Class: Obp::Access::TableTermExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/obp/access/table_term_extractor.rb

Overview

Extracts term entries from TableMapper's generic table model.

Recognition rules, first match wins per table:

  1. Quantity/item tables (the ISO 80000 family): at least 4 columns, placed in a numbered clause (the terms clause), and a majority of body rows whose first cell is an item number (e.g. "12-1.1"). Column roles come from header text when possible ("Quantity Symbol", "Grandeur Symbole", ...), falling back to the ISO 80000 column order [item, designation, symbol, definition, unit, remarks].
  2. Equivalent-terms tables: a header row naming languages in at least 2 columns; one entry per row with designations keyed by the downcased language name.

Anything else is not a term table and yields no entries.

Constant Summary collapse

ITEM_PATTERN =

"12-1.1" or "4-1"; OBP sometimes prints U+2011 NON-BREAKING HYPHEN, normalized away by normalize_item.

/\A\d+-\d+(?:\.\d+)?\z/
MIN_QUANTITY_COLUMNS =
4
MIN_LANGUAGE_COLUMNS =
2
NUMERIC_SECTION =

Terms clauses are numbered ("3", "3.2"); foreword, intro, bibl and index sections are not.

/\A\d+(\.\d+)*\z/
COLUMN_ROLE_PATTERNS =

Checked in order against each column's joined header text; the first unassigned column matching wins, so "Quantity Symbol" becomes "symbol" and not "designation".

[
  ["symbol", /symbol|symbole/i],
  ["definition", /definition|définition/i],
  ["unit", /unit|unité/i],
  ["remarks", /remark|remarque/i],
  ["item", /item\s+no|n[°º]|numéro|no\./i],
  ["designation", /quantity|grandeur|term|terme|name|nom/i],
].freeze
POSITIONAL_ROLES =

Fallback when header-text matching cannot place item+designation.

%w[
  item designation symbol definition unit remarks
].freeze
LANGUAGES =

Language names recognized in equivalent-terms table headers.

%w[
  english french français francais anglais russian russe русский
  german deutsch allemand spanish español espagnol italian italiano
  italien chinese chinois japanese japonais arabic arabe portuguese
  portugais korean coréen
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tables:) ⇒ TableTermExtractor

Returns a new instance of TableTermExtractor.



62
63
64
# File 'lib/obp/access/table_term_extractor.rb', line 62

def initialize(tables:)
  @tables = tables
end

Instance Attribute Details

#tablesObject (readonly)

Returns the value of attribute tables.



60
61
62
# File 'lib/obp/access/table_term_extractor.rb', line 60

def tables
  @tables
end

Instance Method Details

#entriesObject



66
67
68
# File 'lib/obp/access/table_term_extractor.rb', line 66

def entries
  @entries ||= tables.flat_map { |table| table_entries(table) }
end

#to_yamlObject



70
71
72
# File 'lib/obp/access/table_term_extractor.rb', line 70

def to_yaml
  entries.to_yaml
end