1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace IBM\Watson\ToneAnalyzer\Model; |
6
|
|
|
|
7
|
|
|
use IBM\Watson\Common\Model\CreatableFromArray; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* ToneAnalysis object containing document level analysis and sentence level analysis. |
11
|
|
|
*/ |
12
|
|
|
class ToneAnalysis implements CreatableFromArray |
13
|
|
|
{ |
14
|
|
|
const KEY_DOCUMENT_TONE = 'document_tone'; |
15
|
|
|
const KEY_SENTENCE_TONE = 'sentences_tone'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis |
19
|
|
|
*/ |
20
|
|
|
private $documentAnalysis; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $sentenceAnalysis; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis $documentAnalysis |
29
|
|
|
* @param array $sentenceAnalysis |
30
|
|
|
*/ |
31
|
|
|
public function __construct(DocumentAnalysis $documentAnalysis, array $sentenceAnalysis) |
32
|
|
|
{ |
33
|
|
|
$this->documentAnalysis = $documentAnalysis; |
34
|
|
|
$this->sentenceAnalysis = $sentenceAnalysis; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create DocumentAnalysis object from array. |
39
|
|
|
* |
40
|
|
|
* @param array $data |
41
|
|
|
* |
42
|
|
|
* @return \IBM\Watson\Common\Model\CreatableFromArray |
43
|
|
|
*/ |
44
|
|
|
public static function create(array $data): CreatableFromArray |
45
|
|
|
{ |
46
|
|
|
$sentenceTones = []; |
47
|
|
|
|
48
|
|
|
if (isset($data[static::KEY_SENTENCE_TONE])) { |
49
|
|
|
foreach ($data[static::KEY_SENTENCE_TONE] as $sentence) { |
50
|
|
|
$sentenceTones[] = $sentence; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new self( |
55
|
|
|
DocumentAnalysis::create($data[static::KEY_DOCUMENT_TONE]), |
56
|
|
|
$sentenceTones |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis |
62
|
|
|
*/ |
63
|
|
|
public function getDocumentAnalysis(): DocumentAnalysis |
64
|
|
|
{ |
65
|
|
|
return $this->documentAnalysis; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getSentenceAnalysis(): array |
72
|
|
|
{ |
73
|
|
|
return $this->sentenceAnalysis; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|