| @@ 7-85 (lines=79) @@ | ||
| 4 | ||
| 5 | use IBM\Watson\Common\Model\ApiResponseInterface; |
|
| 6 | ||
| 7 | class Sentence implements ApiResponseInterface |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @var int |
|
| 11 | */ |
|
| 12 | private $sentenceId; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | private $text; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @var array |
|
| 21 | */ |
|
| 22 | private $tones; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Sentence constructor. |
|
| 26 | * |
|
| 27 | * @param int $sentenceId |
|
| 28 | * @param string $text |
|
| 29 | * @param array $tones |
|
| 30 | */ |
|
| 31 | public function __construct($sentenceId, $text, array $tones) |
|
| 32 | { |
|
| 33 | $this->sentenceId = $sentenceId; |
|
| 34 | $this->text = $text; |
|
| 35 | $this->tones = $tones; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Create sentence |
|
| 40 | * |
|
| 41 | * @param array $data |
|
| 42 | * |
|
| 43 | * @return \IBM\Watson\ToneAnalyzer\Model\Sentence |
|
| 44 | */ |
|
| 45 | public static function create(array $data) |
|
| 46 | { |
|
| 47 | $tones = []; |
|
| 48 | ||
| 49 | foreach ($data['tones'] as $tone) { |
|
| 50 | $tones[] = Tone::create($tone); |
|
| 51 | } |
|
| 52 | ||
| 53 | return new self($data['sentence_id'], $data['text'], $tones); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Get sentence id |
|
| 58 | * |
|
| 59 | * @return int |
|
| 60 | */ |
|
| 61 | public function getId() |
|
| 62 | { |
|
| 63 | return $this->sentenceId; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Get sentence text |
|
| 68 | * |
|
| 69 | * @return string |
|
| 70 | */ |
|
| 71 | public function getText() |
|
| 72 | { |
|
| 73 | return $this->text; |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Get sentence tones |
|
| 78 | * |
|
| 79 | * @return array |
|
| 80 | */ |
|
| 81 | public function getTones() |
|
| 82 | { |
|
| 83 | return $this->tones; |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||
| @@ 7-85 (lines=79) @@ | ||
| 4 | ||
| 5 | use IBM\Watson\Common\Model\ApiResponseInterface; |
|
| 6 | ||
| 7 | class Utterance implements ApiResponseInterface |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @var int |
|
| 11 | */ |
|
| 12 | private $utteranceId; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | private $text; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @var array |
|
| 21 | */ |
|
| 22 | private $tones; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Utterance constructor. |
|
| 26 | * |
|
| 27 | * @param int $utteranceId |
|
| 28 | * @param string $text |
|
| 29 | * @param array $tones |
|
| 30 | */ |
|
| 31 | public function __construct($utteranceId, $text, array $tones) |
|
| 32 | { |
|
| 33 | $this->utteranceId = $utteranceId; |
|
| 34 | $this->text = $text; |
|
| 35 | $this->tones = $tones; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Create individual utterance |
|
| 40 | * |
|
| 41 | * @param array $data |
|
| 42 | * |
|
| 43 | * @return \IBM\Watson\ToneAnalyzer\Model\Utterance |
|
| 44 | */ |
|
| 45 | public static function create(array $data) |
|
| 46 | { |
|
| 47 | $tones = []; |
|
| 48 | ||
| 49 | foreach ($data['tones'] as $tone) { |
|
| 50 | $tones[] = Tone::create($tone); |
|
| 51 | } |
|
| 52 | ||
| 53 | return new self($data['utterance_id'], $data['utterance_text'], $tones); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Get utterance id |
|
| 58 | * |
|
| 59 | * @return int |
|
| 60 | */ |
|
| 61 | public function getId() |
|
| 62 | { |
|
| 63 | return $this->utteranceId; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Get utterance text |
|
| 68 | * |
|
| 69 | * @return string |
|
| 70 | */ |
|
| 71 | public function getText() |
|
| 72 | { |
|
| 73 | return $this->text; |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Get utterance tones |
|
| 78 | * |
|
| 79 | * @return array |
|
| 80 | */ |
|
| 81 | public function getTones() |
|
| 82 | { |
|
| 83 | return $this->tones; |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||