Class: ActiveGenie::Extractor::Litote

Inherits:
BaseModule
  • Object
show all
Defined in:
lib/active_genie/extractor/litote.rb

Instance Method Summary collapse

Methods inherited from BaseModule

call, #config

Constructor Details

#initialize(text, data_to_extract, config: {}) ⇒ Hash

Extracts data from informal text while also detecting litotes and their meanings. This method extends the basic extraction by analyzing rhetorical devices.

Examples:

Analyze text with litote

text = "The weather isn't bad today"
schema = { mood: { type: 'string', description: 'The mood of the message' } }
Extractor.with_litote(text, schema)
# => { mood: "positive", mood_explanation: "Speaker views weather favorably",
#      message_litote: true,
#      litote_rephrased: "The weather is good today" }

Parameters:

  • text (String)

    The informal text to analyze

  • data_to_extract (Hash)

    Schema defining the data structure to extract

  • config (Hash) (defaults to: {})

    Additional config for the extraction process



27
28
29
30
31
# File 'lib/active_genie/extractor/litote.rb', line 27

def initialize(text, data_to_extract, config: {})
  @text = text
  @data_to_extract = data_to_extract
  super(config:)
end

Instance Method Details

#callObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/active_genie/extractor/litote.rb', line 33

def call
  response = Explanation.call(@text, extract_with_litote, config:)

  if response.data[:message_litote]
    response = Explanation.call(response.data[:litote_rephrased], @data_to_extract,
                                config:)
  end

  response
end