Class: Google::Cloud::Vision::Annotation::Text::Page::Symbol
- Inherits:
-
Object
- Object
- Google::Cloud::Vision::Annotation::Text::Page::Symbol
- Defined in:
- lib/google/cloud/vision/annotation/text.rb
Overview
Symbol
A word representation. See Paragraph.
Instance Method Summary collapse
-
#bounds ⇒ Array<Vertex>
The bounding box for the symbol.
-
#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.
-
#prefix_break? ⇒ Boolean
True if a detected break prepends the page.
-
#text ⇒ String
The actual UTF-8 representation of the symbol.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
Instance Method Details
#bounds ⇒ Array<Vertex>
The bounding box for the symbol. 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).
888 889 890 891 892 893 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 888 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.
850 851 852 853 854 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 850 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.
837 838 839 840 841 842 843 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 837 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 |
#prefix_break? ⇒ Boolean
True if a detected break prepends the page.
861 862 863 864 865 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 861 def prefix_break? return nil if @grpc.property.nil? @grpc.property.detected_break && @grpc.property.detected_break.is_prefix end |
#text ⇒ String
The actual UTF-8 representation of the symbol.
900 901 902 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 900 def text @grpc.text end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
909 910 911 912 913 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 909 def to_h { languages: languages.map(&:to_h), break_type: break_type, prefix_break: prefix_break?, bounds: bounds.map(&:to_h), text: text } end |