Class: Nlg::Sentence

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Sentence

Returns a new instance of Sentence.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nlg/sentence.rb', line 7

def initialize(args = {})
	specifications = args[:specifications]
   @verb = specifications["verb"] || (raise NlgException.new "Verb is nil") 
   @tense = specifications["tense"] || (raise NlgException.new "tense is nil")
   @pronoun = specifications["pronoun"] || (raise NlgException.new "pronoun is nil")
   @complement = specifications["complement"]  
   @coordination_phrase = specifications["coordination_phrase"]  
   @voice = specifications["voice"]  
   @aspect = specifications["aspect"] || (raise NlgException.new "aspect is nil")
   @preposition = specifications["preposition"]  
	@subject = args[:subject] || true
end

Instance Attribute Details

#aspectObject

Returns the value of attribute aspect.



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

def aspect
  @aspect
end

#complementObject

Returns the value of attribute complement.



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

def complement
  @complement
end

#coordination_phraseObject

Returns the value of attribute coordination_phrase.



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

def coordination_phrase
  @coordination_phrase
end

#objectObject

Returns the value of attribute object.



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

def object
  @object
end

#prepositionObject

Returns the value of attribute preposition.



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

def preposition
  @preposition
end

#pronounObject

Returns the value of attribute pronoun.



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

def pronoun
  @pronoun
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#tenseObject

Returns the value of attribute tense.



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

def tense
  @tense
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

#verbObject

Returns the value of attribute verb.



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

def verb
  @verb
end

#voiceObject

Returns the value of attribute voice.



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

def voice
  @voice
end

Instance Method Details

#build(object_type, object_details) ⇒ Object

method to build a sentence. Returns the formed sentece to build_paragraph



21
22
23
24
25
26
27
# File 'lib/nlg/sentence.rb', line 21

def build(object_type, object_details)
  self.value = object_details.value
  self.value = value.join(',') if value.is_a?(Array)
  self.object = object_type
  formed_sentence = self.form
  return formed_sentence
end

#formObject

method to form the sentence using the given specifications



30
31
32
33
34
35
# File 'lib/nlg/sentence.rb', line 30

def form
  set_tense
  predicate = set_predicate
  formed_sentence = "#{verb} #{predicate}".verb.conjugate :subject => subject, :tense => tense.to_sym, :aspect => aspect.to_sym
  return  "#{formed_sentence} #{complement}" 
end

#set_predicateObject



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

def set_predicate
  predicate = "#{preposition} #{value}"
  if verb == "have"
    predicate = "#{object} #{preposition} #{value}" 
  end
  return predicate
end

#set_tenseObject



37
38
39
40
41
# File 'lib/nlg/sentence.rb', line 37

def set_tense
  if tense == "past" and aspect == "habitual" 
    self.aspect = "perfective"
  end
end