Class: Google::Cloud::Language::Annotation::Entity::Mention

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/language/annotation.rb

Overview

Represents a piece of text including relative location.

Examples:

require "google/cloud/language"

language = Google::Cloud::Language.new

content = "Star Wars is a great movie. \
           The Death Star is fearsome."
document = language.document content
annotation = document.annotate

entities = annotation.entities
entities.count #=> 3
entity = entities.first

entity.mentions.count #=> 1
mention = entity.mentions.first
mention.text # => "Star Wars"
mention.offset # => 0
mention.proper? # => true
mention.type # => :PROPER

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#text_spanTextSpan (readonly)

The entity mention text.

Returns:

  • (TextSpan)

    the current value of text_span



958
959
960
# File 'lib/google/cloud/language/annotation.rb', line 958

def text_span
  @text_span
end

#typeSymbol (readonly)

The type of the entity mention. The possible return values are :TYPE_UNKNOWN, :PROPER (proper name), and :COMMON (Common noun or noun compound).

Returns:

  • (Symbol)

    the current value of type



958
959
960
# File 'lib/google/cloud/language/annotation.rb', line 958

def type
  @type
end

Instance Method Details

#common?Boolean

Returns true if #type is :COMMON.

Returns:

  • (Boolean)


1013
1014
1015
# File 'lib/google/cloud/language/annotation.rb', line 1013

def common?
  type == :COMMON
end

#offsetInteger Also known as: begin_offset

The beginning offset of the content in the original document. See TextSpan#offset.

The API calculates the beginning offset according to the client system's default encoding. In Ruby this defaults to UTF-8. To change the offset calculation you will need to change Ruby's default encoding. This is commonly done by setting Encoding.default_internal to Encoding::UTF_16 or Encoding::UTF_32. If the system is configured to use an encoding other than UTF-16 or UTF-32 the offset will be calculated using UTF-8.

Returns:

  • (Integer)


994
995
996
# File 'lib/google/cloud/language/annotation.rb', line 994

def offset
  text_span.offset
end

#proper?Boolean

Returns true if #type is :PROPER.

Returns:

  • (Boolean)


1004
1005
1006
# File 'lib/google/cloud/language/annotation.rb', line 1004

def proper?
  type == :PROPER
end

#textString Also known as: content

The content of the output text. See TextSpan#text.

Returns:

  • (String)


973
974
975
# File 'lib/google/cloud/language/annotation.rb', line 973

def text
  text_span.text
end