Class: Google::Cloud::Language::Annotation::Entity
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Annotation::Entity
- Defined in:
- lib/google/cloud/language/annotation.rb
Overview
Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as salience and mentions, with entities.
Instance Attribute Summary collapse
-
#mentions ⇒ Array<TextSpan>
readonly
The mentions of this entity in the input document.
-
#metadata ⇒ Hash<String,String>
readonly
Metadata associated with the entity.
-
#name ⇒ String
readonly
The representative name for the entity.
-
#salience ⇒ Float
readonly
The salience score associated with the entity in the [0, 1.0] range.
-
#type ⇒ Symbol
readonly
The type of the entity.
Class Method Summary collapse
Instance Method Summary collapse
-
#artwork? ⇒ Boolean
Returns ‘true` if #type is `:WORK_OF_ART`.
-
#event? ⇒ Boolean
Returns ‘true` if #type is `:EVENT`.
-
#good? ⇒ Boolean
Returns ‘true` if #type is `:CONSUMER_GOOD`.
-
#initialize(name, type, metadata, salience, mentions) ⇒ Entity
constructor
A new instance of Entity.
-
#location? ⇒ Boolean
(also: #place?)
Returns ‘true` if #type is `:LOCATION`.
-
#organization? ⇒ Boolean
Returns ‘true` if #type is `:ORGANIZATION`.
-
#other? ⇒ Boolean
Returns ‘true` if #type is `:OTHER`.
-
#person? ⇒ Boolean
Returns ‘true` if #type is `:PERSON`.
-
#unknown? ⇒ Boolean
Returns ‘true` if #type is `:UNKNOWN`.
-
#wikipedia_url ⇒ String
Returns the ‘wikipedia_url` property of the #metadata.
Constructor Details
#initialize(name, type, metadata, salience, mentions) ⇒ Entity
Returns a new instance of Entity.
479 480 481 482 483 484 485 |
# File 'lib/google/cloud/language/annotation.rb', line 479 def initialize name, type, , salience, mentions @name = name @type = type @metadata = @salience = salience @mentions = mentions end |
Instance Attribute Details
#mentions ⇒ Array<TextSpan> (readonly)
The mentions of this entity in the input document. The API currently supports proper noun mentions.
474 475 476 |
# File 'lib/google/cloud/language/annotation.rb', line 474 def mentions @mentions end |
#metadata ⇒ Hash<String,String> (readonly)
Metadata associated with the entity. Currently, only Wikipedia URLs are provided, if available. The associated key is “wikipedia_url”.
474 475 476 |
# File 'lib/google/cloud/language/annotation.rb', line 474 def @metadata end |
#name ⇒ String (readonly)
The representative name for the entity.
474 475 476 |
# File 'lib/google/cloud/language/annotation.rb', line 474 def name @name end |
#salience ⇒ Float (readonly)
The salience score associated with the entity in the [0, 1.0] range. The salience score for an entity provides information about the importance or centrality of that entity to the entire document text. Scores closer to 0 are less salient, while scores closer to 1.0 are highly salient.
474 475 476 |
# File 'lib/google/cloud/language/annotation.rb', line 474 def salience @salience end |
#type ⇒ Symbol (readonly)
The type of the entity.
474 475 476 |
# File 'lib/google/cloud/language/annotation.rb', line 474 def type @type end |
Class Method Details
.from_grpc(grpc) ⇒ Object
571 572 573 574 575 576 577 |
# File 'lib/google/cloud/language/annotation.rb', line 571 def self.from_grpc grpc = Core::GRPCUtils.map_to_hash grpc. mentions = Array(grpc.mentions).map do |g| TextSpan.from_grpc g.text end new grpc.name, grpc.type, , grpc.salience, mentions end |
Instance Method Details
#artwork? ⇒ Boolean
Returns ‘true` if #type is `:WORK_OF_ART`.
538 539 540 |
# File 'lib/google/cloud/language/annotation.rb', line 538 def artwork? type == :WORK_OF_ART end |
#event? ⇒ Boolean
Returns ‘true` if #type is `:EVENT`.
529 530 531 |
# File 'lib/google/cloud/language/annotation.rb', line 529 def event? type == :EVENT end |
#good? ⇒ Boolean
Returns ‘true` if #type is `:CONSUMER_GOOD`.
547 548 549 |
# File 'lib/google/cloud/language/annotation.rb', line 547 def good? type == :CONSUMER_GOOD end |
#location? ⇒ Boolean Also known as: place?
Returns ‘true` if #type is `:LOCATION`.
510 511 512 |
# File 'lib/google/cloud/language/annotation.rb', line 510 def location? type == :LOCATION end |
#organization? ⇒ Boolean
Returns ‘true` if #type is `:ORGANIZATION`.
520 521 522 |
# File 'lib/google/cloud/language/annotation.rb', line 520 def organization? type == :ORGANIZATION end |
#other? ⇒ Boolean
Returns ‘true` if #type is `:OTHER`.
556 557 558 |
# File 'lib/google/cloud/language/annotation.rb', line 556 def other? type == :OTHER end |
#person? ⇒ Boolean
Returns ‘true` if #type is `:PERSON`.
501 502 503 |
# File 'lib/google/cloud/language/annotation.rb', line 501 def person? type == :PERSON end |
#unknown? ⇒ Boolean
Returns ‘true` if #type is `:UNKNOWN`.
492 493 494 |
# File 'lib/google/cloud/language/annotation.rb', line 492 def unknown? type == :UNKNOWN end |
#wikipedia_url ⇒ String
Returns the ‘wikipedia_url` property of the #metadata.
565 566 567 |
# File 'lib/google/cloud/language/annotation.rb', line 565 def wikipedia_url ["wikipedia_url"] end |