Skip to content

Conversation

@bshaffer
Copy link
Contributor

@bshaffer bshaffer commented Sep 30, 2016

Updates CLI to accept gs:// path to language file

<info>php %command.full_name% Text to analyze.</info>
<info>php %command.full_name% gs://my_bucket/file_with_text.txt</info>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underscores are invalid in GCS buckets!!

$text = implode(" ", $input->getArgument('text'));
$result = analyze_entities($text);
$content = implode(' ', (array) $input->getArgument('content'));
if (preg_match('/gs:\/\/([a-z|0-9|\.|-]+)\/(\S+)/', $content, $matches)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining the regexp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeat for similar code below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


/**
* Command line utility to transcribe.
* Command line utility for the Natural Language APIs.
Copy link
Contributor

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

Copy link
Contributor Author

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.

* Command line utility for the Natural Language APIs.
*
* Usage: php speech.php transcribe
* Usage: php language.php entities
Copy link
Contributor

@tmatsuo tmatsuo Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This usage is not complete because there is argument. Remove it, or make it complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

'content',
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Text to analyze'
'Text or path to Cloud Storage file'
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
I think it's simpler if you make the text argument OPTIONAL (actually it's conditionally required), and add an option --gs-path or something?

If the text contains the sub-text "gs://your-bucket/your-object", does it match the regex?
For example, can you analyze the following text?

To analyze the text stored in cloud storage, specify the gs path like gs://your-bucket/your-object as the argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the regex! This is now fixed.

As for the --gcs-path, I experimented with this but I found it to be cumbersome. I think the current approach works better.

<info>php %command.full_name% Text to analyze.</info>
<info>php %command.full_name% gs://my-bucket/file_with_text.txt</info>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sub-command everything sounds a bit weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest? analyze-all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it sounds much better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

if (!self::$hasCredentials) {
$this->markTestSkipped('No application credentials were found.');
}
if (!$gcsFile = getenv('GOOGLE_LANGUAGE_GCS_FILE')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the envvar on travis and jenkins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@bshaffer bshaffer force-pushed the add-gcs-example-to-language branch from 0dac7f9 to 696ac34 Compare October 4, 2016 20:05
- Renames command classes for consistency
@bshaffer bshaffer force-pushed the add-gcs-example-to-language branch from 696ac34 to d328a8d Compare October 4, 2016 20:06
@bshaffer
Copy link
Contributor Author

bshaffer commented Oct 4, 2016

@tmatsuo PTAL

@bshaffer bshaffer merged commit 10c7c11 into master Oct 4, 2016
@bshaffer bshaffer deleted the add-gcs-example-to-language branch October 4, 2016 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants