Class: RecastAI::Sentence

Inherits:
Object
  • Object
show all
Defined in:
lib/recastai/sentence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sentence) ⇒ Sentence

Returns a new instance of Sentence.



10
11
12
13
14
15
16
17
# File 'lib/recastai/sentence.rb', line 10

def initialize(sentence)
  @source   = sentence['source']
  @type     = sentence['type']
  @action   = sentence['action']
  @agent    = sentence['agent']
  @polarity = sentence['polarity']
  @entities = sentence['entities'].flat_map{ |n, e| e.map{ |ee| Entity.new(n, ee) } }
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/recastai/sentence.rb', line 5

def action
  @action
end

#agentObject (readonly)

Returns the value of attribute agent.



6
7
8
# File 'lib/recastai/sentence.rb', line 6

def agent
  @agent
end

#entitiesObject (readonly)

Returns the value of attribute entities.



8
9
10
# File 'lib/recastai/sentence.rb', line 8

def entities
  @entities
end

#polarityObject (readonly)

Returns the value of attribute polarity.



7
8
9
# File 'lib/recastai/sentence.rb', line 7

def polarity
  @polarity
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/recastai/sentence.rb', line 3

def source
  @source
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/recastai/sentence.rb', line 4

def type
  @type
end

Instance Method Details

#all(name) ⇒ Object

Returns all entities whose names matches the parameter

  • Args :

    • name - String, the entities’ names

  • Returns :

    • An array of instances of Entity or an empty array



41
42
43
44
45
46
47
48
49
# File 'lib/recastai/sentence.rb', line 41

def all(name)
  entities = []

  @entities.each do |entity|
    entities << entity if entity.name.casecmp(name.to_s) == 0
  end

  entities
end

#get(name) ⇒ Object

Returns the first entity whose name matches the parameter

  • Args :

    • name - String, the entity’s name

  • Returns :

    • An instance of Entity or nil



26
27
28
29
30
31
32
# File 'lib/recastai/sentence.rb', line 26

def get(name)
  @entities.each do |entity|
    return entity if entity.name.casecmp(name.to_s) == 0
  end

  nil
end