Class: Google::Cloud::Language::Annotation::Entities

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

Overview

The entities returned by entity analysis.

Examples:

require "google/cloud/language"

language = Google::Cloud::Language.new

content = "Darth Vader is the best villain in Star Wars."
document = language.document content
annotation = document.annotate

entities = annotation.entities
entities.count #=> 2
entities.people.count #=> 1
entities.artwork.count #=> 1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities = [], language = nil) ⇒ Entities

Returns a new instance of Entities.



338
339
340
341
# File 'lib/google/cloud/language/annotation.rb', line 338

def initialize entities = [], language = nil
  super entities
  @language = language
end

Instance Attribute Details

#languageString

The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are supported.

Returns:

  • (String)

    the current value of language



333
334
335
# File 'lib/google/cloud/language/annotation.rb', line 333

def language
  @language
end

Class Method Details

.from_grpc(grpc) ⇒ Object

V1beta1::AnalyzeEntitiesResponse object.



419
420
421
422
# File 'lib/google/cloud/language/annotation.rb', line 419

def self.from_grpc grpc
  entities = Array(grpc.entities).map { |g| Entity.from_grpc g }
  new entities, grpc.language
end

Instance Method Details

#artworkArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:WORK_OF_ART`.

Returns:



394
395
396
# File 'lib/google/cloud/language/annotation.rb', line 394

def artwork
  select(&:artwork?)
end

#eventsArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:EVENT`.

Returns:



385
386
387
# File 'lib/google/cloud/language/annotation.rb', line 385

def events
  select(&:event?)
end

#goodsArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:CONSUMER_GOOD`.

Returns:



403
404
405
# File 'lib/google/cloud/language/annotation.rb', line 403

def goods
  select(&:good?)
end

#locationsArray<Entity> Also known as: places

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:LOCATION`.

Returns:



366
367
368
# File 'lib/google/cloud/language/annotation.rb', line 366

def locations
  select(&:location?)
end

#organizationsArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:ORGANIZATION`.

Returns:



376
377
378
# File 'lib/google/cloud/language/annotation.rb', line 376

def organizations
  select(&:organization?)
end

#otherArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:OTHER`.

Returns:



412
413
414
# File 'lib/google/cloud/language/annotation.rb', line 412

def other
  select(&:other?)
end

#peopleArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:PERSON`.

Returns:



357
358
359
# File 'lib/google/cloud/language/annotation.rb', line 357

def people
  select(&:person?)
end

#unknownArray<Entity>

Returns the entities for which Google::Cloud::Language::Annotation::Entity#type is ‘:UNKNOWN`.

Returns:



348
349
350
# File 'lib/google/cloud/language/annotation.rb', line 348

def unknown
  select(&:unknown?)
end