Class: LangExtract::Core::FuzzyAlignmentPlanner

Inherits:
Object
  • Object
show all
Defined in:
lib/langextract/core/fuzzy_alignment_planner.rb

Overview

Plans ordered fuzzy token alignments with coverage, density, score, and semantic-barrier constraints. The suffix table is shared by all starts.

Defined Under Namespace

Classes: AlignmentPath, SubsequenceAlignment

Constant Summary collapse

MAX_PATH_ALTERNATIVES_PER_MATCH_COUNT =
2
SENTENCE_BOUNDARY_PUNCTUATION =
/[.!?\u2026\u3002\uff01\uff1f]/u

Instance Method Summary collapse

Constructor Details

#initialize(source_tokens:, alignment_index:, fuzzy_threshold:, min_coverage:, min_density:) ⇒ FuzzyAlignmentPlanner

Returns a new instance of FuzzyAlignmentPlanner.



17
18
19
20
21
22
23
# File 'lib/langextract/core/fuzzy_alignment_planner.rb', line 17

def initialize(source_tokens:, alignment_index:, fuzzy_threshold:, min_coverage:, min_density:)
  @source_tokens = source_tokens
  @alignment_index = alignment_index
  @fuzzy_threshold = fuzzy_threshold
  @min_coverage = min_coverage
  @min_density = min_density
end

Instance Method Details

#alignment_for(target_tokens, source_start) ⇒ Object



25
26
27
28
# File 'lib/langextract/core/fuzzy_alignment_planner.rb', line 25

def alignment_for(target_tokens, source_start)
  paths = alignment_table(target_tokens)[source_start]
  preferred_path(paths, target_tokens.length)
end

#feasible?(alignment, target_count) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/langextract/core/fuzzy_alignment_planner.rb', line 30

def feasible?(alignment, target_count)
  return false if target_count.zero?

  coverage = alignment.matched.to_f / target_count
  density = alignment.matched.to_f / alignment.window_size

  coverage >= min_coverage &&
    density >= min_density &&
    alignment.score >= fuzzy_threshold &&
    safe_source_gap?(alignment.token_indices)
end