|
21 | 21 | * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md |
22 | 22 | */ |
23 | 23 |
|
24 | | -// Include Google Cloud dependendencies using Composer |
25 | | -require_once __DIR__ . '/../vendor/autoload.php'; |
26 | | - |
27 | | -if (count($argv) != 2) { |
28 | | - return printf("Usage: php %s TEXT\n", __FILE__); |
29 | | -} |
30 | | -list($_, $text) = $argv; |
| 24 | +namespace Google\Cloud\Samples\Language; |
31 | 25 |
|
32 | 26 | # [START language_entities_text] |
33 | 27 | use Google\Cloud\Language\V1\Document; |
34 | 28 | use Google\Cloud\Language\V1\Document\Type; |
35 | 29 | use Google\Cloud\Language\V1\LanguageServiceClient; |
36 | 30 | use Google\Cloud\Language\V1\Entity\Type as EntityType; |
37 | 31 |
|
38 | | -/** Uncomment and populate these variables in your code */ |
39 | | -// $text = 'The text to analyze.'; |
| 32 | +/** |
| 33 | + * @param string $text The text to analyze |
| 34 | + */ |
| 35 | +function analyze_entities(string $text): void |
| 36 | +{ |
| 37 | + // Create the Natural Language client |
| 38 | + $languageServiceClient = new LanguageServiceClient(); |
40 | 39 |
|
41 | | -// Create the Natural Language client |
42 | | -$languageServiceClient = new LanguageServiceClient(); |
43 | | -try { |
44 | 40 | // Create a new Document, add text as content and set type to PLAIN_TEXT |
45 | 41 | $document = (new Document()) |
46 | 42 | ->setContent($text) |
|
62 | 58 | } |
63 | 59 | printf(PHP_EOL); |
64 | 60 | } |
65 | | -} finally { |
66 | | - $languageServiceClient->close(); |
67 | 61 | } |
68 | 62 | # [END language_entities_text] |
| 63 | + |
| 64 | +// The following 2 lines are only needed to run the samples |
| 65 | +require_once __DIR__ . '/../../testing/sample_helpers.php'; |
| 66 | +\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
0 commit comments