@@ 10-78 (lines=69) @@ | ||
7 | /** |
|
8 | * Class ToneAnalysis |
|
9 | */ |
|
10 | class ToneAnalysis implements CreateableFromArray |
|
11 | { |
|
12 | /** |
|
13 | * @var string |
|
14 | */ |
|
15 | const KEY_DOCUMENT_TONE = 'document_tone'; |
|
16 | ||
17 | /** |
|
18 | * @var string |
|
19 | */ |
|
20 | const KEY_SENTENCE_TONE = 'sentences_tone'; |
|
21 | ||
22 | /** |
|
23 | * @var \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis |
|
24 | */ |
|
25 | private $documentAnalysis; |
|
26 | ||
27 | /** |
|
28 | * @var array |
|
29 | */ |
|
30 | private $sentenceAnalysis; |
|
31 | ||
32 | /** |
|
33 | * @param \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis $documentAnalysis |
|
34 | * @param array $sentenceAnalysis |
|
35 | */ |
|
36 | public function __construct(DocumentAnalysis $documentAnalysis, array $sentenceAnalysis = []) |
|
37 | { |
|
38 | $this->documentAnalysis = $documentAnalysis; |
|
39 | $this->sentenceAnalysis = $sentenceAnalysis; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @param array $data |
|
44 | * |
|
45 | * @return \IBM\Watson\ToneAnalyzer\Model\ToneAnalysis |
|
46 | */ |
|
47 | public static function create(array $data) |
|
48 | { |
|
49 | $sentenceTone = []; |
|
50 | ||
51 | if (isset($data[static::KEY_SENTENCE_TONE])) { |
|
52 | foreach ($data[static::KEY_SENTENCE_TONE] as $sentence) { |
|
53 | $sentenceTone[] = SentenceAnalysis::create($sentence); |
|
54 | } |
|
55 | } |
|
56 | ||
57 | return new self( |
|
58 | DocumentAnalysis::create($data[static::KEY_DOCUMENT_TONE]), |
|
59 | $sentenceTone |
|
60 | ); |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * @return \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis |
|
65 | */ |
|
66 | public function getDocumentAnalysis() |
|
67 | { |
|
68 | return $this->documentAnalysis; |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * @return array |
|
73 | */ |
|
74 | public function getSentenceAnalysis() |
|
75 | { |
|
76 | return $this->sentenceAnalysis; |
|
77 | } |
|
78 | } |
|
79 |
@@ 11-73 (lines=63) @@ | ||
8 | /** |
|
9 | * Class UtteranceAnalyses |
|
10 | */ |
|
11 | class UtteranceAnalyses implements CreateableFromArray |
|
12 | { |
|
13 | /** |
|
14 | * @var string |
|
15 | */ |
|
16 | const KEY_TONE = 'utterances_tone'; |
|
17 | ||
18 | /** |
|
19 | * @var string |
|
20 | */ |
|
21 | const KEY_WARNING = 'warning'; |
|
22 | ||
23 | /** |
|
24 | * @var array |
|
25 | */ |
|
26 | private $tones; |
|
27 | ||
28 | /** |
|
29 | * @var null|string |
|
30 | */ |
|
31 | private $warning; |
|
32 | ||
33 | /** |
|
34 | * @param array $tones |
|
35 | * @param null|string $warning |
|
36 | */ |
|
37 | public function __construct(array $tones, $warning = null) |
|
38 | { |
|
39 | $this->tones = $tones; |
|
40 | $this->warning = $warning; |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * @param array $data |
|
45 | * |
|
46 | * @return \IBM\Watson\ToneAnalyzer\Model\UtteranceAnalyses |
|
47 | */ |
|
48 | public static function create(array $data) |
|
49 | { |
|
50 | $tones = []; |
|
51 | foreach ($data[static::KEY_TONE] as $tone) { |
|
52 | $tones[] = UtteranceAnalysis::create($tone); |
|
53 | } |
|
54 | ||
55 | return new self($tones, isset($data[static::KEY_WARNING]) ? $data[static::KEY_WARNING] : null); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @return array |
|
60 | */ |
|
61 | public function getTones() |
|
62 | { |
|
63 | return $this->tones; |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * @return null |
|
68 | */ |
|
69 | public function getWarning() |
|
70 | { |
|
71 | return $this->warning; |
|
72 | } |
|
73 | } |
|
74 |