Class: Google::Cloud::Vision::Annotation::Text::Page::Block
- Inherits:
-
Object
- Object
- Google::Cloud::Vision::Annotation::Text::Page::Block
- Defined in:
- lib/google/cloud/vision/annotation/text.rb
Overview
Block
A logical element on the page. See Google::Cloud::Vision::Annotation::Text::Page.
Instance Method Summary collapse
-
#block_type ⇒ ::Symbol
Detected block type (text, image etc) for the block.
-
#bounds ⇒ Array<Vertex>
The bounding box for the block.
-
#break_type ⇒ ::Symbol
The type of a detected break at the start or end of the page.
-
#languages ⇒ Array<Language>
A list of detected languages together with confidence.
-
#paragraphs ⇒ Array<Paragraph>
List of paragraphs in this block (if this block is of type text).
-
#prefix_break? ⇒ Boolean
True if a detected break prepends the page.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
Instance Method Details
#block_type ⇒ ::Symbol
Detected block type (text, image etc) for the block.
491 492 493 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 491 def block_type @grpc.block_type.to_sym end |
#bounds ⇒ Array<Vertex>
The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example:
- when the text is horizontal it might look like: 0----1 | | 3----2
- when rotated 180 degrees around the top-left corner it becomes: 2----3 | | 1----0 and the vertice order will still be (0, 1, 2, 3).
467 468 469 470 471 472 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 467 def bounds return [] unless @grpc.bounding_box @bounds ||= Array(@grpc.bounding_box.vertices).map do |v| Vertex.from_grpc v end end |
#break_type ⇒ ::Symbol
The type of a detected break at the start or end of the page.
429 430 431 432 433 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 429 def break_type return nil if @grpc.property.nil? @grpc.property.detected_break && @grpc.property.detected_break.type.to_sym end |
#languages ⇒ Array<Language>
A list of detected languages together with confidence.
416 417 418 419 420 421 422 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 416 def languages return [] if @grpc.property.nil? detected_languages = @grpc.property.detected_languages @languages ||= Array(detected_languages).map do |l| Language.from_grpc l end end |
#paragraphs ⇒ Array<Paragraph>
List of paragraphs in this block (if this block is of type text).
480 481 482 483 484 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 480 def paragraphs @paragraphs ||= Array(@grpc.paragraphs).map do |b| Paragraph.from_grpc b end end |
#prefix_break? ⇒ Boolean
True if a detected break prepends the page.
440 441 442 443 444 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 440 def prefix_break? return nil if @grpc.property.nil? @grpc.property.detected_break && @grpc.property.detected_break.is_prefix end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
500 501 502 503 504 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 500 def to_h { languages: languages.map(&:to_h), break_type: break_type, prefix_break: prefix_break?, bounds: bounds.map(&:to_h), paragraphs: paragraphs.map(&:to_h), block_type: block_type } end |