Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 2a2f10f

Browse files
author
mandre42
authored
Merge pull request #7 from RecastAI/develop
Add processing_language and sentiment
2 parents f1b5d9f + fc5cc75 commit 2a2f10f

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

src/apis/resources/Conversation.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public function __construct($token, $responseBody)
2121
$this->next_actions = $responseBody->next_actions;
2222
$this->memory = $responseBody->memory;
2323
$this->entities = $responseBody->entities;
24+
$this->sentiment = $responseBody->sentiment;
2425
$this->intents = $responseBody->intents;
2526
$this->conversation_token = $responseBody->conversation_token;
2627
$this->language = $responseBody->language;
28+
$this->processing_language = $responseBody->processing_language;
2729
$this->version = $responseBody->version;
2830
$this->timestamp = $responseBody->timestamp;
2931
$this->status = $responseBody->status;
@@ -83,6 +85,49 @@ public function nextActions()
8385
return ($this->nextActions ? $this->nextActions : []);
8486
}
8587

88+
/**
89+
* SENTIMENT HELPERS
90+
* Returns whether or not the response sentiment corresponds to the checked one
91+
* @return {boolean}: true or false
92+
*/
93+
94+
public function isPositive()
95+
{
96+
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_POSITIVE);
97+
}
98+
99+
/**
100+
* @return bool
101+
*/
102+
public function isNeutral()
103+
{
104+
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_NEUTRAL);
105+
}
106+
107+
/**
108+
* @return bool
109+
*/
110+
public function isNegative()
111+
{
112+
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_NEGATIVE);
113+
}
114+
115+
/**
116+
* @return bool
117+
*/
118+
public function isVPositive()
119+
{
120+
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VPOSITIVE);
121+
}
122+
123+
/**
124+
* @return bool
125+
*/
126+
public function isVNegative()
127+
{
128+
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VNEGATIVE);
129+
}
130+
86131
/**
87132
* Returns the memory matching the alias
88133
* or all the memory if no alias provided

src/apis/resources/Response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct($response) {
3131
}
3232

3333
$this->language = $response->language;
34+
$this->processing_language = $response->processing_language;
3435
$this->version = $response->version;
3536
$this->timestamp = $response->timestamp;
3637
$this->status = $response->status;

tests/ConversationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function testConversationClassAttributes()
3030
$this->assertEquals($conversation->action, $result->results->action);
3131
$this->assertEquals($conversation->nextActions, $result->results->next_actions);
3232
$this->assertEquals($conversation->memory, $result->results->memory);
33+
$this->assertEquals($conversation->language, $result->results->language);
34+
$this->assertEquals($conversation->processing_language, $result->results->processing_language);
35+
$this->assertEquals($conversation->sentiment, $result->results->sentiment);
3336
}
3437

3538
public function testResponseClassMethods()
@@ -45,5 +48,10 @@ public function testResponseClassMethods()
4548
$this->assertEquals($conversation->joinedReplies('\n'), join('\n', $result->results->replies));
4649
$this->assertEquals($conversation->memory(), $result->results->memory);
4750
$this->assertEquals($conversation->memory('loc'), $result->results->memory->loc);
51+
$this->assertEquals($conversation->isVPositive(), false);
52+
$this->assertEquals($conversation->isPositive(), false);
53+
$this->assertEquals($conversation->isNeutral(), true);
54+
$this->assertEquals($conversation->isNegative(), false);
55+
$this->assertEquals($conversation->isVNegative(), false);
4856
}
4957
}

tests/ResponseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function testResponseClassAttributes()
3333
$this->assertEquals($response->source, $result->results->{'source'});
3434
$this->assertEquals($response->sentiment, $result->results->{'sentiment'});
3535
$this->assertEquals($response->language, $result->results->{'language'});
36+
$this->assertEquals($response->processing_language, $result->results->{'processing_language'});
3637
$this->assertEquals($response->version, $result->results->{'version'});
3738
$this->assertEquals($response->timestamp, $result->results->{'timestamp'});
3839
$this->assertEquals($count, 4);

tests/data/Converse.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Salut",
66
"Need location please"
77
],
8+
"sentiment": "neutral",
89
"action": {
910
"slug": "greetings",
1011
"done": true,
@@ -29,6 +30,7 @@
2930
],
3031
"conversation_token": "f6362f5ded83031d42c2d02d954359f9",
3132
"language": "en",
33+
"processing_language": "en",
3234
"timestamp": "2016-10-05T12:07:30.907Z",
3335
"status": 200
3436
},

tests/data/Request.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
]
4646
},
4747
"language": "en",
48+
"processing_language": "en",
4849
"version": "2.0.0",
4950
"timestamp": "2016-07-10T23:17:59+02:00",
5051
"status": 200

0 commit comments

Comments
 (0)