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
62 changes: 48 additions & 14 deletions language/api/README.md → language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
These samples show how to use the [Google Cloud Natural Language API][language-api]
to analyze text.

This repository contains samples that use the [Google Cloud
Library for PHP][google-cloud-php] to make REST calls as well as
contains samples using the more-efficient (though sometimes more
complex) [GRPC][grpc] API. The GRPC API also allows streaming requests.

[language-api]: http://cloud.google.com/natural-language
[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php/
[grpc]: http://grpc.io


## Setup

Expand Down Expand Up @@ -56,6 +49,10 @@ authentication:

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

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].

[grpc]: https://cloud.google.com/php/grpc

## Samples

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

Available commands:
all Analyze syntax, sentiment and entities in text.
entities Analyze entities in text.
help Displays help for a command
list Lists commands
sentiment Analyze sentiment in text.
syntax Analyze syntax in text.
all Analyze syntax, sentiment and entities in text.
entities Analyze entities in text.
help Displays help for a command
list Lists commands
sentiment Analyze sentiment in text.
syntax Analyze syntax in text.
entity-sentiment Analyze sentiment of entities in text.
classify Classify text into categories.

### Run Analyze Entities

Expand Down Expand Up @@ -181,11 +180,46 @@ To run the Analyze Syntax sample:
language: en
entities: { }


### Run Analyze Entity Sentiment

To run the Analyze Entity Sentiment sample:

$ php language.php entity-sentiment 'New York is great. New York is good.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we need to add entity-sentiment and classify to the list of Available commands up top, e.g:

Available commands:
  all               Analyze syntax, sentiment and entities in text.
  classify          Classify text into categories.
  entities          Analyze entities in text.
  entity-sentiment  Analyze entity sentiment in text.
  help              Displays help for a command
  list              Lists commands
  sentiment         Analyze sentiment in text.
  syntax            Analyze syntax in text.

Entity Name: New York
Entity Type: LOCATION
Entity Salience: 1
Entity Magnitude: 1.7999999523163
Entity Score: 0

Mentions:
Begin Offset: 0
Content: New York
Mention Type: PROPER
Mention Magnitude: 0.89999997615814
Mention Score: 0.89999997615814

Begin Offset: 17
Content: New York
Mention Type: PROPER
Mention Magnitude: 0.80000001192093
Mention Score: -0.80000001192093

### Run Classify Text

To run the Classify Text sample:

$ php language.php classify 'The first two gubernatorial elections since
President Donald Trump took office went in favor of Democratic candidates
in Virginia and New Jersey.'
Category Name: /News/Politics
Confidence: 0.99000000953674

## The client library

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

## Troubleshooting

Expand Down
10 changes: 5 additions & 5 deletions language/api/composer.json → language/composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"require": {
"google/cloud-language": "^0.4",
"google/cloud-language": "^0.9",
"symfony/console": "^3.0",
"google/cloud-storage": "^1.0",
"google/gax": "^0.21.2",
"google/proto-client": "^0.22.0"
"google/cloud-storage": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
Expand All @@ -23,7 +21,9 @@
"src/analyze_syntax.php",
"src/analyze_syntax_from_file.php",
"src/analyze_entity_sentiment.php",
"src/analyze_entity_sentiment_from_file.php"
"src/analyze_entity_sentiment_from_file.php",
"src/classify_text.php",
"src/classify_text_from_file.php"
]
}
}
Loading