/** * Accord the different parts of a message between them * * @param Message $message The message to accord * @return Message Accorded message */ public static function accord(Message $message) { // Set as current the message given Message::message($message); // Look for common sentences patterns $pattern = $message->pattern; if (Sentence::contains('^nouns$')) { $message->noun = Accord::noun($message->noun); } if ($contains = Sentence::contains('numbers nouns( verbs)?')) { if (sizeof($contains) == 2) { list($number, $noun) = $contains; } else { list($number, $noun, $verb) = $contains; } $message->setWord($number, Accord::number($message->numbers[$number])); $message->setWord($noun, Accord::noun($message->nouns[$noun])); } if (list($article, $noun) = Sentence::contains('articles nouns')) { $message->article = Accord::article($message->article); $message->setWord($noun, Accord::noun($message->nouns[$noun])); } if (Sentence::contains('verbs nouns')) { $message = Verb::past($message); } if (Sentence::contains('nouns verbs')) { $message->pattern = str_replace('verbs0', 'states0 verbs0', $message->pattern); $message->state = 'normal'; $tense = $message->number ? 'present' : 'past'; $message = Verb::$tense($message); } elseif (Sentence::contains('nouns( objects)? states verbs')) { $message = Verb::past($message); } // Conjugate remaining state if ($message->state == 'normal') { $message->state = Babel::state('past.normal'); } return $message; }
/** * Renders the complete sentence * * @return string A sentence */ public function speak() { // Apply all rules to found words $message = Accord::accord($this); // Replace patterns with their value $sentence = Sentence::createFrom($message->pattern, $message->sentence); // Destroy message instance static::$message = null; return $sentence; }