Class: Nlg::Sentence
- Inherits:
-
Object
- Object
- Nlg::Sentence
- Defined in:
- lib/nlg/sentence.rb
Instance Attribute Summary collapse
-
#aspect ⇒ Object
Returns the value of attribute aspect.
-
#complement ⇒ Object
Returns the value of attribute complement.
-
#coordination_phrase ⇒ Object
Returns the value of attribute coordination_phrase.
-
#object ⇒ Object
Returns the value of attribute object.
-
#preposition ⇒ Object
Returns the value of attribute preposition.
-
#pronoun ⇒ Object
Returns the value of attribute pronoun.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#tense ⇒ Object
Returns the value of attribute tense.
-
#value ⇒ Object
Returns the value of attribute value.
-
#verb ⇒ Object
Returns the value of attribute verb.
-
#voice ⇒ Object
Returns the value of attribute voice.
Instance Method Summary collapse
-
#build(object_type, object_details) ⇒ Object
method to build a sentence.
-
#form ⇒ Object
method to form the sentence using the given specifications.
-
#initialize(args = {}) ⇒ Sentence
constructor
A new instance of Sentence.
- #set_predicate ⇒ Object
- #set_tense ⇒ Object
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
#aspect ⇒ Object
Returns the value of attribute aspect.
5 6 7 |
# File 'lib/nlg/sentence.rb', line 5 def aspect @aspect end |
#complement ⇒ Object
Returns the value of attribute complement.
5 6 7 |
# File 'lib/nlg/sentence.rb', line 5 def complement @complement end |
#coordination_phrase ⇒ Object
Returns the value of attribute coordination_phrase.
5 6 7 |
# File 'lib/nlg/sentence.rb', line 5 def coordination_phrase @coordination_phrase end |
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def object @object end |
#preposition ⇒ Object
Returns the value of attribute preposition.
5 6 7 |
# File 'lib/nlg/sentence.rb', line 5 def preposition @preposition end |
#pronoun ⇒ Object
Returns the value of attribute pronoun.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def pronoun @pronoun end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def subject @subject end |
#tense ⇒ Object
Returns the value of attribute tense.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def tense @tense end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def value @value end |
#verb ⇒ Object
Returns the value of attribute verb.
4 5 6 |
# File 'lib/nlg/sentence.rb', line 4 def verb @verb end |
#voice ⇒ Object
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 |
#form ⇒ Object
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_predicate ⇒ Object
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_tense ⇒ Object
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 |