Class: Gliner::Runners::ClassificationRunner

Inherits:
Object
  • Object
show all
Includes:
Inspectable
Defined in:
lib/gliner/runners/classification_runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspectable

#inspect

Constructor Details

#initialize(model, tasks_config) ⇒ ClassificationRunner

Returns a new instance of ClassificationRunner.

Raises:



12
13
14
15
16
17
18
19
# File 'lib/gliner/runners/classification_runner.rb', line 12

def initialize(model, tasks_config)
  raise Error, 'tasks must be a Hash' unless tasks_config.is_a?(Hash)

  @tasks = tasks_config.to_h do |name, config|
    parsed = model.classification_task.parse_config(name: name, config: config)
    [name.to_s, PreparedTask.new(model.classification_task, parsed)]
  end
end

Class Method Details

.[](tasks) ⇒ Object



8
9
10
# File 'lib/gliner/runners/classification_runner.rb', line 8

def self.[](tasks)
  new(Gliner.model!, tasks)
end

Instance Method Details

#[](text, **options) ⇒ Object Also known as: call



21
22
23
# File 'lib/gliner/runners/classification_runner.rb', line 21

def [](text, **options)
  @tasks.transform_values { |task| task.call(text, **options) }
end