Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions language/src/analyze_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s TEXT\n", __FILE__);
}
list($_, $text) = $argv;
namespace Google\Cloud\Samples\Language;

# [START analyze_all]
use Google\Cloud\Language\V1\AnnotateTextRequest\Features;
Expand All @@ -38,13 +32,14 @@
use Google\Cloud\Language\V1\EntityMention\Type as MentionType;
use Google\Cloud\Language\V1\PartOfSpeech\Tag;

/** Uncomment and populate these variables in your code */
// $text = 'The text to analyze.';

// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();
/**
* @param string $text The text to analyze
*/
function analyze_all(string $text): void
{
// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();

try {
// Create a new Document, pass text and set type to PLAIN_TEXT
$document = (new Document())
->setContent($text)
Expand Down Expand Up @@ -105,7 +100,9 @@
printf('Token part of speech: %s' . PHP_EOL, Tag::name($token->getPartOfSpeech()->getTag()));
printf(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END analyze_all]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
26 changes: 12 additions & 14 deletions language/src/analyze_all_from_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FILE\n", __FILE__);
}
list($_, $uri) = $argv;
namespace Google\Cloud\Samples\Language;

# [START analyze_all_from_file]
use Google\Cloud\Language\V1\AnnotateTextRequest\Features;
Expand All @@ -38,12 +32,14 @@
use Google\Cloud\Language\V1\EntityMention\Type as MentionType;
use Google\Cloud\Language\V1\PartOfSpeech\Tag;

/** Uncomment and populate these variables in your code */
// $uri = 'The cloud storage object to analyze (gs://your-bucket-name/your-object-name)';
/**
* @param string $uri The cloud storage object to analyze (gs://your-bucket-name/your-object-name)
*/
function analyze_all_from_file(string $uri): void
{
// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();

// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, pass GCS URI and set type to PLAIN_TEXT
$document = (new Document())
->setGcsContentUri($uri)
Expand Down Expand Up @@ -109,7 +105,9 @@
printf('Token part of speech: %s' . PHP_EOL, Tag::name($token->getPartOfSpeech()->getTag()));
printf(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END analyze_all_from_file]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
26 changes: 12 additions & 14 deletions language/src/analyze_entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s TEXT\n", __FILE__);
}
list($_, $text) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_entities_text]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;
use Google\Cloud\Language\V1\Entity\Type as EntityType;

/** Uncomment and populate these variables in your code */
// $text = 'The text to analyze.';
/**
* @param string $text The text to analyze
*/
function analyze_entities(string $text): void
{
// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();

// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, add text as content and set type to PLAIN_TEXT
$document = (new Document())
->setContent($text)
Expand All @@ -62,7 +58,9 @@
}
printf(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_entities_text]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
26 changes: 12 additions & 14 deletions language/src/analyze_entities_from_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FILE\n", __FILE__);
}
list($_, $uri) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_entities_gcs]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;
use Google\Cloud\Language\V1\Entity\Type as EntityType;

/** Uncomment and populate these variables in your code */
// $uri = 'The cloud storage object to analyze (gs://your-bucket-name/your-object-name)';
/**
* @param string $uri The cloud storage object to analyze (gs://your-bucket-name/your-object-name)
*/
function analyze_entities_from_file(string $uri): void
{
// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();

// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, pass GCS URI and set type to PLAIN_TEXT
$document = (new Document())
->setGcsContentUri($uri)
Expand All @@ -62,7 +58,9 @@
}
printf(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_entities_gcs]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
24 changes: 11 additions & 13 deletions language/src/analyze_entity_sentiment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s TEXT\n", __FILE__);
}
list($_, $text) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_entity_sentiment_text]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;
use Google\Cloud\Language\V1\Entity\Type as EntityType;

/** Uncomment and populate these variables in your code */
// $text = 'The text to analyze.';
/**
* @param string $text The text to analyze
*/
function analyze_entity_sentiment(string $text): void
{
$languageServiceClient = new LanguageServiceClient();

$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, add text as content and set type to PLAIN_TEXT
$document = (new Document())
->setContent($text)
Expand All @@ -60,7 +56,9 @@
}
print(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_entity_sentiment_text]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
26 changes: 12 additions & 14 deletions language/src/analyze_entity_sentiment_from_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FILE\n", __FILE__);
}
list($_, $uri) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_entity_sentiment_gcs]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;
use Google\Cloud\Language\V1\Entity\Type as EntityType;

/** Uncomment and populate these variables in your code */
// $uri = 'The cloud storage object to analyze (gs://your-bucket-name/your-object-name)';
/**
* @param string $uri The cloud storage object to analyze (gs://your-bucket-name/your-object-name)
*/
function analyze_entity_sentiment_from_file(string $uri): void
{
// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();

// Create the Natural Language client
$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, pass GCS URI and set type to PLAIN_TEXT
$document = (new Document())
->setGcsContentUri($uri)
Expand All @@ -61,7 +57,9 @@
}
print(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_entity_sentiment_gcs]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
24 changes: 11 additions & 13 deletions language/src/analyze_sentiment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s TEXT\n", __FILE__);
}
list($_, $text) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_sentiment_text]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;

/** Uncomment and populate these variables in your code */
// $text = 'The text to analyze.';
/**
* @param string $text The text to analyze
*/
function analyze_sentiment(string $text): void
{
$languageServiceClient = new LanguageServiceClient();

$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, add text as content and set type to PLAIN_TEXT
$document = (new Document())
->setContent($text)
Expand All @@ -63,7 +59,9 @@
}
print(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_sentiment_text]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
24 changes: 11 additions & 13 deletions language/src/analyze_sentiment_from_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FILE\n", __FILE__);
}
list($_, $uri) = $argv;
namespace Google\Cloud\Samples\Language;

# [START language_sentiment_gcs]
use Google\Cloud\Language\V1\Document;
use Google\Cloud\Language\V1\Document\Type;
use Google\Cloud\Language\V1\LanguageServiceClient;

/** Uncomment and populate these variables in your code */
// $uri = 'The cloud storage object to analyze (gs://your-bucket-name/your-object-name)';
/**
* @param string $uri The cloud storage object to analyze (gs://your-bucket-name/your-object-name)
*/
function analyze_sentiment_from_file(string $uri): void
{
$languageServiceClient = new LanguageServiceClient();

$languageServiceClient = new LanguageServiceClient();
try {
// Create a new Document, pass GCS URI and set type to PLAIN_TEXT
$document = (new Document())
->setGcsContentUri($uri)
Expand All @@ -63,7 +59,9 @@
}
print(PHP_EOL);
}
} finally {
$languageServiceClient->close();
}
# [END language_sentiment_gcs]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Loading