Class: LangExtract::Core::AnnotatedDocument
- Inherits:
-
Object
- Object
- LangExtract::Core::AnnotatedDocument
- Defined in:
- lib/langextract/core/data.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#extractions ⇒ Object
readonly
Returns the value of attribute extractions.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(document:, extractions: []) ⇒ AnnotatedDocument
constructor
A new instance of AnnotatedDocument.
- #metadata ⇒ Object
- #text ⇒ Object
- #to_h ⇒ Object
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
#document ⇒ Object (readonly)
Returns the value of attribute document.
191 192 193 |
# File 'lib/langextract/core/data.rb', line 191 def document @document end |
#extractions ⇒ Object (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
#id ⇒ Object
199 200 201 |
# File 'lib/langextract/core/data.rb', line 199 def id document.id end |
#metadata ⇒ Object
207 208 209 |
# File 'lib/langextract/core/data.rb', line 207 def document. end |
#text ⇒ Object
203 204 205 |
# File 'lib/langextract/core/data.rb', line 203 def text document.text end |
#to_h ⇒ Object
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 |