Skip to content

Commit 6584b3c

Browse files
authored
NL classifyText samples and client library version update (GoogleCloudPlatform#479)
* NL classifyText samples and client library version update * Code review changes; README update * Restructuring directory + README update * Updated entity sentiment and classify text samples to use v1 instead of v1beta2 * Tiny linting issue
1 parent 636b155 commit 6584b3c

23 files changed

+339
-1946
lines changed

language/api/README.md renamed to language/README.md

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
These samples show how to use the [Google Cloud Natural Language API][language-api]
44
to analyze text.
55

6-
This repository contains samples that use the [Google Cloud
7-
Library for PHP][google-cloud-php] to make REST calls as well as
8-
contains samples using the more-efficient (though sometimes more
9-
complex) [GRPC][grpc] API. The GRPC API also allows streaming requests.
10-
116
[language-api]: http://cloud.google.com/natural-language
127
[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php/
13-
[grpc]: http://grpc.io
14-
158

169
## Setup
1710

@@ -56,6 +49,10 @@ authentication:
5649

5750
1. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to that file.
5851

52+
1. If you are using the Analyze Entity Sentiment or Classify Text features, you will need to install and enable the [gRPC extension for PHP][grpc].
53+
54+
[grpc]: https://cloud.google.com/php/grpc
55+
5956
## Samples
6057

6158
To run the Natural Language Samples:
@@ -76,12 +73,14 @@ To run the Natural Language Samples:
7673
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
7774

7875
Available commands:
79-
all Analyze syntax, sentiment and entities in text.
80-
entities Analyze entities in text.
81-
help Displays help for a command
82-
list Lists commands
83-
sentiment Analyze sentiment in text.
84-
syntax Analyze syntax in text.
76+
all Analyze syntax, sentiment and entities in text.
77+
entities Analyze entities in text.
78+
help Displays help for a command
79+
list Lists commands
80+
sentiment Analyze sentiment in text.
81+
syntax Analyze syntax in text.
82+
entity-sentiment Analyze sentiment of entities in text.
83+
classify Classify text into categories.
8584

8685
### Run Analyze Entities
8786

@@ -181,11 +180,46 @@ To run the Analyze Syntax sample:
181180
language: en
182181
entities: { }
183182

183+
184+
### Run Analyze Entity Sentiment
185+
186+
To run the Analyze Entity Sentiment sample:
187+
188+
$ php language.php entity-sentiment 'New York is great. New York is good.'
189+
Entity Name: New York
190+
Entity Type: LOCATION
191+
Entity Salience: 1
192+
Entity Magnitude: 1.7999999523163
193+
Entity Score: 0
194+
195+
Mentions:
196+
Begin Offset: 0
197+
Content: New York
198+
Mention Type: PROPER
199+
Mention Magnitude: 0.89999997615814
200+
Mention Score: 0.89999997615814
201+
202+
Begin Offset: 17
203+
Content: New York
204+
Mention Type: PROPER
205+
Mention Magnitude: 0.80000001192093
206+
Mention Score: -0.80000001192093
207+
208+
### Run Classify Text
209+
210+
To run the Classify Text sample:
211+
212+
$ php language.php classify 'The first two gubernatorial elections since
213+
President Donald Trump took office went in favor of Democratic candidates
214+
in Virginia and New Jersey.'
215+
Category Name: /News/Politics
216+
Confidence: 0.99000000953674
217+
184218
## The client library
185219

186220
This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].
187221
You can read the documentation for more details on API usage and use GitHub
188-
to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues].
222+
to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues].
189223

190224
## Troubleshooting
191225

language/api/composer.json renamed to language/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"require": {
3-
"google/cloud-language": "^0.4",
3+
"google/cloud-language": "^0.9",
44
"symfony/console": "^3.0",
5-
"google/cloud-storage": "^1.0",
6-
"google/gax": "^0.21.2",
7-
"google/proto-client": "^0.22.0"
5+
"google/cloud-storage": "^1.0"
86
},
97
"require-dev": {
108
"phpunit/phpunit": "~4.0"
@@ -23,7 +21,9 @@
2321
"src/analyze_syntax.php",
2422
"src/analyze_syntax_from_file.php",
2523
"src/analyze_entity_sentiment.php",
26-
"src/analyze_entity_sentiment_from_file.php"
24+
"src/analyze_entity_sentiment_from_file.php",
25+
"src/classify_text.php",
26+
"src/classify_text_from_file.php"
2727
]
2828
}
2929
}

0 commit comments

Comments
 (0)