Class: LangExtract::Core::AnnotatedDocument

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, extractions: []) ⇒ AnnotatedDocument

Returns a new instance of AnnotatedDocument.



193
194
195
196
197
# File 'lib/langextract/core/data.rb', line 193

def initialize(document:, extractions: [])
  @document = document
  @extractions = extractions.map { |item| item.is_a?(Extraction) ? item : Extraction.from_h(item) }.freeze
  freeze
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



191
192
193
# File 'lib/langextract/core/data.rb', line 191

def document
  @document
end

#extractionsObject (readonly)

Returns the value of attribute extractions.



191
192
193
# File 'lib/langextract/core/data.rb', line 191

def extractions
  @extractions
end

Class Method Details

.from_h(hash) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/langextract/core/data.rb', line 218

def self.from_h(hash)
  document_hash = HashCoercion.read(hash, :document)
  document = Document.from_h(document_hash || hash)
  extractions = Array(HashCoercion.read(hash, :extractions)).map { |item| Extraction.from_h(item) }

  new(document: document, extractions: extractions)
end

Instance Method Details

#idObject



199
200
201
# File 'lib/langextract/core/data.rb', line 199

def id
  document.id
end

#metadataObject



207
208
209
# File 'lib/langextract/core/data.rb', line 207

def 
  document.
end

#textObject



203
204
205
# File 'lib/langextract/core/data.rb', line 203

def text
  document.text
end

#to_hObject



211
212
213
214
215
216
# File 'lib/langextract/core/data.rb', line 211

def to_h
  {
    "document" => document.to_h,
    "extractions" => extractions.map(&:to_h)
  }
end