| @@ 70-91 (lines=22) @@ | ||
| 67 | $tone->analyze('text'); |
|
| 68 | } |
|
| 69 | ||
| 70 | public function testDocumentToneAnalysis() |
|
| 71 | { |
|
| 72 | $rawResponse = '{"document_tone": {"tones": [{"score": 0.6165,"tone_id": "sadness","tone_name": "Sadness"}]}}'; |
|
| 73 | ||
| 74 | $this->httpClient->shouldReceive('sendRequest')->once()->andReturnUsing(function () use ($rawResponse) { |
|
| 75 | return new Response(200, ['Content-Type' => 'application/json'], $rawResponse); |
|
| 76 | }); |
|
| 77 | ||
| 78 | $tone = new Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
|
| 79 | ||
| 80 | $response = $tone->analyze('text', ['content_language' => 'en', 'accept_language' => 'en']); |
|
| 81 | ||
| 82 | $tones = $response->getDocumentAnalysis()->getTones(); |
|
| 83 | ||
| 84 | $this->assertNotEmpty($tones); |
|
| 85 | ||
| 86 | $firstTone = $tones[0]; |
|
| 87 | ||
| 88 | $this->assertEquals('sadness', $firstTone->getId()); |
|
| 89 | $this->assertEquals('Sadness', $firstTone->getName()); |
|
| 90 | $this->assertEquals(0.6165, $firstTone->getScore()); |
|
| 91 | } |
|
| 92 | ||
| 93 | public function testSentenceToneAnaysis() |
|
| 94 | { |
|
| @@ 93-172 (lines=80) @@ | ||
| 90 | $this->assertEquals(0.6165, $firstTone->getScore()); |
|
| 91 | } |
|
| 92 | ||
| 93 | public function testSentenceToneAnaysis() |
|
| 94 | { |
|
| 95 | $rawResponse = '{ |
|
| 96 | "document_tone": { |
|
| 97 | "tones": [ |
|
| 98 | { |
|
| 99 | "score": 0.6165, |
|
| 100 | "tone_id": "sadness", |
|
| 101 | "tone_name": "Sadness" |
|
| 102 | }, |
|
| 103 | { |
|
| 104 | "score": 0.829888, |
|
| 105 | "tone_id": "analytical", |
|
| 106 | "tone_name": "Analytical" |
|
| 107 | } |
|
| 108 | ] |
|
| 109 | }, |
|
| 110 | "sentences_tone": [ |
|
| 111 | { |
|
| 112 | "sentence_id": 0, |
|
| 113 | "text": "Team, I know that times are tough!", |
|
| 114 | "tones": [ |
|
| 115 | { |
|
| 116 | "score": 0.801827, |
|
| 117 | "tone_id": "analytical", |
|
| 118 | "tone_name": "Analytical" |
|
| 119 | } |
|
| 120 | ] |
|
| 121 | }, |
|
| 122 | { |
|
| 123 | "sentence_id": 1, |
|
| 124 | "text": "Product sales have been disappointing for the past three quarters.", |
|
| 125 | "tones": [ |
|
| 126 | { |
|
| 127 | "score": 0.771241, |
|
| 128 | "tone_id": "sadness", |
|
| 129 | "tone_name": "Sadness" |
|
| 130 | }, |
|
| 131 | { |
|
| 132 | "score": 0.687768, |
|
| 133 | "tone_id": "analytical", |
|
| 134 | "tone_name": "Analytical" |
|
| 135 | } |
|
| 136 | ] |
|
| 137 | }, |
|
| 138 | { |
|
| 139 | "sentence_id": 2, |
|
| 140 | "text": "We have a competitive product, but we need to do a better job of selling it!", |
|
| 141 | "tones": [ |
|
| 142 | { |
|
| 143 | "score": 0.506763, |
|
| 144 | "tone_id": "analytical", |
|
| 145 | "tone_name": "Analytical" |
|
| 146 | } |
|
| 147 | ] |
|
| 148 | } |
|
| 149 | ] |
|
| 150 | }'; |
|
| 151 | ||
| 152 | $this->httpClient->shouldReceive('sendRequest')->once()->andReturnUsing(function () use ($rawResponse) { |
|
| 153 | return new Response(200, ['Content-Type' => 'application/json'], $rawResponse); |
|
| 154 | }); |
|
| 155 | ||
| 156 | $tone = new Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
|
| 157 | ||
| 158 | $response = $tone->analyze('text', ['content_language' => 'en', 'accept_language' => 'en']); |
|
| 159 | ||
| 160 | $sentences = $response->getSentenceAnalysis()->getSentences(); |
|
| 161 | ||
| 162 | $this->assertNotEmpty($sentences); |
|
| 163 | ||
| 164 | $firstSentence = $sentences[0]; |
|
| 165 | ||
| 166 | $this->assertEquals(0, $firstSentence->getId()); |
|
| 167 | $this->assertEquals('Team, I know that times are tough!', $firstSentence->getText()); |
|
| 168 | ||
| 169 | $tones = $firstSentence->getTones(); |
|
| 170 | ||
| 171 | $this->assertNotEmpty($tones); |
|
| 172 | } |
|
| 173 | } |
|
| 174 | ||