Skip to content

Commit bed6d48

Browse files
committed
@gogasca Updated setType to use Type:PLAIN_TEXT
1 parent 8e5ee41 commit bed6d48

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

language/language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
// Regex to match a Cloud Storage path as the first argument
214214
// e.g "gs://my-bucket/file_with_text.txt"
215215
if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) {
216-
analyze_syntax_from_file($matches[0], $projectId);
216+
analyze_syntax_from_file($content, $projectId);
217217
} else {
218218
analyze_syntax($content, $projectId);
219219
}

language/src/analyze_syntax.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
/**
@@ -62,15 +63,15 @@ function analyze_syntax($text, $projectId = null)
6263
// Create a new Document
6364
$document = new Document();
6465
// Add text as content and set document type to PLAIN_TEXT
65-
$document->setContent($text)->setType(1);
66+
$document->setContent($text)->setType(Type::PLAIN_TEXT);
6667
// Call the analyzeEntities function
6768
$response = $languageServiceClient->analyzeSyntax($document, []);
6869
$tokens = $response->getTokens();
6970
// Print out information about each entity
7071
foreach ($tokens as $token) {
7172
printf('Token text: %s' . PHP_EOL, $token->getText()->getContent());
7273
printf('Token part of speech: %s' . PHP_EOL, $tag_types[$token->getPartOfSpeech()->getTag()]);
73-
printf(PHP_EOL);
74+
print(PHP_EOL);
7475
}
7576
} finally {
7677
$languageServiceClient->close();

language/src/analyze_syntax_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
/**
@@ -62,15 +63,15 @@ function analyze_syntax_from_file($gcsUri, $projectId = null)
6263
// Create a new Document
6364
$document = new Document();
6465
// Pass GCS URI and set document type to PLAIN_TEXT
65-
$document->setGcsContentUri($gcsUri)->setType(1);
66+
$document->setGcsContentUri($gcsUri)->setType(Type::PLAIN_TEXT);
6667
// Call the analyzeEntities function
6768
$response = $languageServiceClient->analyzeSyntax($document, []);
6869
$tokens = $response->getTokens();
6970
// Print out information about each entity
7071
foreach ($tokens as $token) {
7172
printf('Token text: %s' . PHP_EOL, $token->getText()->getContent());
7273
printf('Token part of speech: %s' . PHP_EOL, $tag_types[$token->getPartOfSpeech()->getTag()]);
73-
printf(PHP_EOL);
74+
print(PHP_EOL);
7475
}
7576
} finally {
7677
$languageServiceClient->close();

0 commit comments

Comments
 (0)