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

Inherits:
Object
  • Object
show all
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.

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.name #=> "Star Wars"
entity.type #=> :WORK_OF_ART
entity.salience #=> 0.6457656025886536
entity.mentions.count #=> 1
entity.mentions.first.text # => "Star Wars"
entity.mentions.first.offset # => 0
entity.mid #=> "/m/06mmr"
entity.wikipedia_url #=> "http://en.wikipedia.org/wiki/Star_Wars"

Defined Under Namespace

Classes: Mention

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mentionsArray<Entity::Mention> (readonly)

The mentions of this entity in the input document. The API currently supports proper noun mentions.

Returns:



806
807
808
# File 'lib/google/cloud/language/annotation.rb', line 806

def mentions
  @mentions
end

#metadataHash<String,String> (readonly)

Metadata associated with the entity. Currently, only Wikipedia URLs are provided, if available. The associated key is "wikipedia_url".

Returns:

  • (Hash<String,String>)

    the current value of metadata



806
807
808
# File 'lib/google/cloud/language/annotation.rb', line 806

def 
  @metadata
end

#nameString (readonly)

The representative name for the entity.

Returns:

  • (String)

    the current value of name



806
807
808
# File 'lib/google/cloud/language/annotation.rb', line 806

def name
  @name
end

#salienceFloat (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.

Returns:

  • (Float)

    the current value of salience



806
807
808
# File 'lib/google/cloud/language/annotation.rb', line 806

def salience
  @salience
end

#typeSymbol (readonly)

The type of the entity.

Returns:

  • (Symbol)

    the current value of type



806
807
808
# File 'lib/google/cloud/language/annotation.rb', line 806

def type
  @type
end

Instance Method Details

#artwork?Boolean

Returns true if #type is :WORK_OF_ART.

Returns:

  • (Boolean)


870
871
872
# File 'lib/google/cloud/language/annotation.rb', line 870

def artwork?
  type == :WORK_OF_ART
end

#event?Boolean

Returns true if #type is :EVENT.

Returns:

  • (Boolean)


861
862
863
# File 'lib/google/cloud/language/annotation.rb', line 861

def event?
  type == :EVENT
end

#good?Boolean

Returns true if #type is :CONSUMER_GOOD.

Returns:

  • (Boolean)


879
880
881
# File 'lib/google/cloud/language/annotation.rb', line 879

def good?
  type == :CONSUMER_GOOD
end

#location?Boolean Also known as: place?

Returns true if #type is :LOCATION.

Returns:

  • (Boolean)


842
843
844
# File 'lib/google/cloud/language/annotation.rb', line 842

def location?
  type == :LOCATION
end

#midString

Returns the mid property of the #metadata. The MID (machine-generated identifier) (MID) correspods to the entity's Google Knowledge Graph entry. Note that MID values remain unique across different languages, so you can use such values to tie entities together from different languages. For programmatically inspecting these MID values, please consult the Google Knowledge Graph Search API documentation.

Returns:

  • (String)


913
914
915
# File 'lib/google/cloud/language/annotation.rb', line 913

def mid
  ["mid"]
end

#organization?Boolean

Returns true if #type is :ORGANIZATION.

Returns:

  • (Boolean)


852
853
854
# File 'lib/google/cloud/language/annotation.rb', line 852

def organization?
  type == :ORGANIZATION
end

#other?Boolean

Returns true if #type is :OTHER.

Returns:

  • (Boolean)


888
889
890
# File 'lib/google/cloud/language/annotation.rb', line 888

def other?
  type == :OTHER
end

#person?Boolean

Returns true if #type is :PERSON.

Returns:

  • (Boolean)


833
834
835
# File 'lib/google/cloud/language/annotation.rb', line 833

def person?
  type == :PERSON
end

#unknown?Boolean

Returns true if #type is :UNKNOWN.

Returns:

  • (Boolean)


824
825
826
# File 'lib/google/cloud/language/annotation.rb', line 824

def unknown?
  type == :UNKNOWN
end

#wikipedia_urlString

Returns the wikipedia_url property of the #metadata.

Returns:

  • (String)


897
898
899
# File 'lib/google/cloud/language/annotation.rb', line 897

def wikipedia_url
  ["wikipedia_url"]
end