Skip to content

Commit 0f85462

Browse files
authored
fix(deps): update dependency google/cloud-language to v1 (#2119)
1 parent 8cf8b22 commit 0f85462

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

language/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"google/cloud-language": "^0.34.0",
3+
"google/cloud-language": "^1.0.0",
44
"google/cloud-storage": "^1.20.1"
55
}
66
}

language/quickstart.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,33 @@
2020
require __DIR__ . '/vendor/autoload.php';
2121

2222
# Imports the Google Cloud client library
23-
use Google\Cloud\Language\LanguageClient;
23+
use Google\Cloud\Language\V2\AnalyzeSentimentRequest;
24+
use Google\Cloud\Language\V2\Client\LanguageServiceClient;
25+
use Google\Cloud\Language\V2\Document;
2426

2527
# Your Google Cloud Platform project ID
2628
$projectId = 'YOUR_PROJECT_ID';
2729

2830
# Instantiates a client
29-
$language = new LanguageClient([
31+
$language = new LanguageServiceClient([
3032
'projectId' => $projectId
3133
]);
3234

3335
# The text to analyze
3436
$text = 'Hello, world!';
37+
$document = (new Document())
38+
->setContent($text)
39+
->setType(Document\Type::PLAIN_TEXT);
40+
$analyzeSentimentRequest = (new AnalyzeSentimentRequest())
41+
->setDocument($document);
3542

3643
# Detects the sentiment of the text
37-
$annotation = $language->analyzeSentiment($text);
38-
$sentiment = $annotation->sentiment();
44+
$response = $language->analyzeSentiment($analyzeSentimentRequest);
45+
foreach ($response->getSentences() as $sentence) {
46+
$sentiment = $sentence->getSentiment();
47+
echo 'Text: ' . $sentence->getText()->getContent() . PHP_EOL;
48+
printf('Sentiment: %s, %s' . PHP_EOL, $sentiment->getScore(), $sentiment->getMagnitude());
49+
}
3950

40-
echo 'Text: ' . $text . '
41-
Sentiment: ' . $sentiment['score'] . ', ' . $sentiment['magnitude'];
4251
# [END language_quickstart]
43-
return $sentiment;
52+
return $sentiment ?? null;

testing/bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@
3030
DG\BypassFinals::enable();
3131

3232
require_once __DIR__ . '/vendor/autoload.php';
33-

0 commit comments

Comments
 (0)