-
Notifications
You must be signed in to change notification settings - Fork 1k
Add gcs example to language #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d328a8d
e3a8a0b
78d3fc3
26754db
ad19720
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,36 +23,44 @@ | |
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| /** | ||
| * Command line utility to transcribe. | ||
| * Command line utility for the Natural Language APIs. | ||
| * | ||
| * Usage: php speech.php transcribe | ||
| * Usage: php language.php entities TEXT | ||
| */ | ||
| class AnalyzeEntitiesCommand extends Command | ||
| class EntitiesCommand extends Command | ||
| { | ||
| protected function configure() | ||
| { | ||
| $this | ||
| ->setName('entities') | ||
| ->setDescription('Analyze some natural language text.') | ||
| ->setDescription('Analyze entities in text.') | ||
| ->setHelp(<<<EOF | ||
| The <info>%command.name%</info> command analyzes text using the Google Cloud Natural Language API. | ||
|
|
||
| <info>php %command.full_name% Text to analyze.</info> | ||
|
|
||
| <info>php %command.full_name% gs://my_bucket/file_with_text.txt</info> | ||
|
|
||
| EOF | ||
| ) | ||
| ->addArgument( | ||
| 'text', | ||
| 'content', | ||
| InputArgument::IS_ARRAY | InputArgument::REQUIRED, | ||
| 'Text to analyze' | ||
| 'Text or path to Cloud Storage file' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel little bit weird to use the same argument for the text and the gs path. If the text contains the sub-text "gs://your-bucket/your-object", does it match the regex?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on the regex! This is now fixed. As for the |
||
| ) | ||
| ; | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| $text = implode(" ", $input->getArgument('text')); | ||
| $result = analyze_entities($text); | ||
| $content = implode(' ', (array) $input->getArgument('content')); | ||
| // Regex to match a Cloud Storage path as the first argument | ||
| // e.g "gs://my-bucket/file_with_text.txt" | ||
| if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) { | ||
| $result = analyze_entities_from_file($matches[1], $matches[2]); | ||
| } else { | ||
| $result = analyze_entities($content); | ||
| } | ||
| print_annotation($result); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: Is this really a utility? I'd call it command line sample or somthing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is both a utility and a sample. I do not think we need to change this.