Skip to content

Commit b270d46

Browse files
committed
Updated setType to use Type:PLAIN_TEXT and revert parameter
1. $document->setContent($text)->setType(1) to $document->setContent($text)->setType(Type::PLAIN_TEXT) 2. classify_text_from_file($matches[0], $projectId) to classify_text_from_file($content, $projectId);
1 parent 3057a7b commit b270d46

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

language/language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
// Regex to match a Cloud Storage path as the first argument
291291
// e.g "gs://my-bucket/file_with_text.txt"
292292
if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) {
293-
classify_text_from_file($matches[0], $projectId);
293+
classify_text_from_file($content, $projectId);
294294
} else {
295295
classify_text($content, $projectId);
296296
}

language/src/classify_text.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Google\Cloud\Samples\Language;
2626

2727
use Google\Cloud\Language\V1beta2\Document;
28+
use Google\Cloud\Language\V1beta2\Document\Type;
2829
use Google\Cloud\Language\V1beta2\LanguageServiceClient;
2930
/**
3031
* Classify text (20+ words) into categories.
@@ -51,16 +52,16 @@ function classify_text($text, $projectId = null)
5152
try {
5253
// Create a new Document
5354
$document = new Document();
54-
// Pass GCS URI and set document type to PLAIN_TEXT
55-
$document->setContent($text)->setType(1);
55+
// Pass GCS URI and set document type to PLAIN_TEXT (1)
56+
$document->setContent($text)->setType(Type::PLAIN_TEXT);
5657
// Call the analyzeSentiment function
5758
$response = $languageServiceClient->classifyText($document);
5859
$categories = $response->getCategories();
5960
// Print document information
6061
foreach ($categories as $category) {
6162
printf('Category Name: %s' . PHP_EOL, $category->getName());
6263
printf('Confidence: %s' . PHP_EOL, $category->getConfidence());
63-
printf(PHP_EOL);
64+
print(PHP_EOL);
6465
}
6566
} finally {
6667
$languageServiceClient->close();

language/src/classify_text_from_file.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Google\Cloud\Samples\Language;
2626

2727
use Google\Cloud\Language\V1beta2\Document;
28+
use Google\Cloud\Language\V1beta2\Document\Type;
2829
use Google\Cloud\Language\V1beta2\LanguageServiceClient;
2930

3031
/**
@@ -44,15 +45,15 @@ function classify_text_from_file($gcsUri, $projectId = null)
4445
// Create a new Document
4546
$document = new Document();
4647
// Pass GCS URI and set document type to PLAIN_TEXT
47-
$document->setGcsContentUri($gcsUri)->setType(1);
48+
$document->setGcsContentUri($gcsUri)->setType(Type::PLAIN_TEXT);
4849
// Call the analyzeSentiment function
4950
$response = $languageServiceClient->classifyText($document);
5051
$categories = $response->getCategories();
5152
// Print document information
5253
foreach ($categories as $category) {
5354
printf('Category Name: %s' . PHP_EOL, $category->getName());
5455
printf('Confidence: %s' . PHP_EOL, $category->getConfidence());
55-
printf(PHP_EOL);
56+
print(PHP_EOL);
5657
}
5758
} finally {
5859
$languageServiceClient->close();

0 commit comments

Comments
 (0)