Skip to content

Commit d4ade2c

Browse files
authored
Updates dlp, error, video, speech, language, and tts samples to new format (GoogleCloudPlatform#873)
1 parent 7bf3610 commit d4ade2c

File tree

68 files changed

+1911
-2979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1911
-2979
lines changed

dlp/quickstart.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
'item' => $content
7171
));
7272

73-
$likelihoods = ['Unknown', 'Very unlikely', 'Unlikely', 'Possible',
74-
'Likely', 'Very likely'];
75-
7673
// Print the results
7774
$findings = $response->getResult()->getFindings();
7875
if (count($findings) == 0) {
@@ -84,7 +81,7 @@
8481
print(' Quote: ' . $finding->getQuote() . PHP_EOL);
8582
}
8683
print(' Info type: ' . $finding->getInfoType()->getName() . PHP_EOL);
87-
$likelihoodString = $likelihoods[$finding->getLikelihood()];
84+
$likelihoodString = Likelihood::name($finding->getLikelihood());
8885
print(' Likelihood: ' . $likelihoodString . PHP_EOL);
8986
}
9087
}

dlp/src/inspect_file.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ function inspect_file(
8686
'item' => $content
8787
]);
8888

89-
$likelihoods = ['Unknown', 'Very unlikely', 'Unlikely', 'Possible',
90-
'Likely', 'Very likely'];
91-
9289
// Print the results
9390
$findings = $response->getResult()->getFindings();
9491
if (count($findings) == 0) {
@@ -100,7 +97,7 @@ function inspect_file(
10097
print(' Quote: ' . $finding->getQuote() . PHP_EOL);
10198
}
10299
print(' Info type: ' . $finding->getInfoType()->getName() . PHP_EOL);
103-
print(' Likelihood: ' . $likelihoods[$finding->getLikelihood()] . PHP_EOL);
100+
print(' Likelihood: ' . Likelihood::name($finding->getLikelihood()) . PHP_EOL);
104101
}
105102
}
106103
}

dlp/src/inspect_string.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ function inspect_string(
7575
'item' => $content
7676
]);
7777

78-
$likelihoods = ['Unknown', 'Very unlikely', 'Unlikely', 'Possible',
79-
'Likely', 'Very likely'];
80-
8178
// Print the results
8279
$findings = $response->getResult()->getFindings();
8380
if (count($findings) == 0) {
@@ -89,7 +86,7 @@ function inspect_string(
8986
print(' Quote: ' . $finding->getQuote() . PHP_EOL);
9087
}
9188
print(' Info type: ' . $finding->getInfoType()->getName() . PHP_EOL);
92-
$likelihoodString = $likelihoods[$finding->getLikelihood()];
89+
$likelihoodString = Likelihood::name($finding->getLikelihood());
9390
print(' Likelihood: ' . $likelihoodString . PHP_EOL);
9491
}
9592
}

dlp/src/reidentify_fpe.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ function reidentify_fpe(
117117
'item' => $item
118118
]);
119119

120-
$likelihoods = ['Unknown', 'Very unlikely', 'Unlikely', 'Possible',
121-
'Likely', 'Very likely'];
122-
123120
// Print the results
124121
$reidentifiedValue = $response->getItem()->getValue();
125122
print($reidentifiedValue);

language/README.md

Lines changed: 80 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -60,165 +60,112 @@ authentication:
6060

6161
## Samples
6262

63-
To run the Natural Language Samples:
64-
65-
$ php language.php
66-
Cloud Natural Language
67-
68-
Usage:
69-
command [options] [arguments]
70-
71-
Options:
72-
-h, --help Display this help message
73-
-q, --quiet Do not output any message
74-
-V, --version Display this application version
75-
--ansi Force ANSI output
76-
--no-ansi Disable ANSI output
77-
-n, --no-interaction Do not ask any interactive question
78-
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
79-
80-
Available commands:
81-
all Analyze syntax, sentiment and entities in text.
82-
entities Analyze entities in text.
83-
help Displays help for a command
84-
list Lists commands
85-
sentiment Analyze sentiment in text.
86-
syntax Analyze syntax in text.
87-
entity-sentiment Analyze sentiment of entities in text.
88-
classify Classify text into categories.
63+
To run the Natural Language Samples, run `php src/SNIPPET_NAME.php`. For example:
64+
65+
```sh
66+
$ php src/analyze_all.php "This is some text to analyze"
67+
$ php src/analyze_all_from_file.php "gs://your-gcs-bucket/file-to-analyze.txt"
68+
```
8969

9070
### Run Analyze Entities
9171

9272
To run the Analyze Entities sample:
9373

94-
$ php language.php entities 'I know the way to San Jose. Do You?'
95-
entities:
96-
-
97-
name: way
98-
type: OTHER
99-
metadata: { }
100-
salience: 0.6970506
101-
mentions:
102-
-
103-
text:
104-
content: way
105-
beginOffset: 11
106-
type: COMMON
107-
-
108-
name: 'San Jose'
109-
type: LOCATION
110-
metadata:
111-
mid: /m/0f04v
112-
wikipedia_url: 'http://en.wikipedia.org/wiki/San_Jose,_California'
113-
salience: 0.30294943
114-
mentions:
115-
-
116-
text:
117-
content: 'San Jose'
118-
beginOffset: 18
119-
type: PROPER
120-
language: en
74+
```
75+
$ php src/analyze_entities.php 'I know the way to San Jose. Do You?'
76+
Name: way
77+
Type: OTHER
78+
Salience: 0.63484555
79+
80+
Name: San Jose
81+
Type: LOCATION
82+
Salience: 0.36515442
83+
```
12184

12285
### Run Analyze Sentiment
12386

12487
To run the Analyze Sentiment sample:
12588

126-
$ php language.php sentiment 'I know the way to San Jose. Do you?'
127-
documentSentiment:
128-
magnitude: 0.3
129-
score: 0.3
130-
language: en
131-
sentences:
132-
-
133-
text:
134-
content: 'I know the way to San Jose'
135-
beginOffset: 0
136-
sentiment:
137-
magnitude: 0.3
138-
score: 0.3
139-
-
140-
text:
141-
content: 'Do you?'
142-
beginOffset: 28
143-
sentiment:
144-
magnitude: 0.1
145-
score: -0.1
89+
```
90+
Document Sentiment:
91+
Magnitude: 0.1
92+
Score: 0
93+
94+
Sentence: I know the way to San Jose.
95+
Sentence Sentiment:
96+
Entity Magnitude: 0
97+
Entity Score: 0
98+
99+
Sentence: Do you?
100+
Sentence Sentiment:
101+
Entity Magnitude: 0
102+
Entity Score: 0
103+
```
146104

147105
### Run Analyze Syntax
148106

149107
To run the Analyze Syntax sample:
150108

151-
$ php language.php syntax 'I know the way to San Jose. Do you?'
152-
sentences:
153-
-
154-
text:
155-
content: 'I know the way to San Jose.'
156-
beginOffset: 0
157-
-
158-
text:
159-
content: 'Do you?'
160-
beginOffset: 28
161-
tokens:
162-
-
163-
text:
164-
content: I
165-
beginOffset: 0
166-
partOfSpeech:
167-
tag: PRON
168-
aspect: ASPECT_UNKNOWN
169-
case: NOMINATIVE
170-
form: FORM_UNKNOWN
171-
gender: GENDER_UNKNOWN
172-
mood: MOOD_UNKNOWN
173-
number: SINGULAR
174-
person: FIRST
175-
proper: PROPER_UNKNOWN
176-
reciprocity: RECIPROCITY_UNKNOWN
177-
tense: TENSE_UNKNOWN
178-
voice: VOICE_UNKNOWN
179-
dependencyEdge:
180-
headTokenIndex: 1
181-
label: NSUBJ
182-
lemma: I
183-
score: 0.3
184-
...
185-
language: en
186-
entities: { }
109+
```
110+
$ php src/analyze_syntax.php 'I know the way to San Jose. Do you?'
111+
Token text: I
112+
Token part of speech: PRON
113+
114+
Token text: know
115+
Token part of speech: VERB
116+
117+
Token text: the
118+
Token part of speech: DET
119+
120+
Token text: way
121+
Token part of speech: NOUN
122+
123+
Token text: to
124+
Token part of speech: ADP
187125
126+
Token text: San
127+
Token part of speech: NOUN
128+
129+
Token text: Jose
130+
Token part of speech: NOUN
131+
132+
Token text: .
133+
Token part of speech: PUNCT
134+
135+
Token text: Do
136+
Token part of speech: VERB
137+
138+
Token text: you
139+
Token part of speech: PRON
140+
141+
Token text: ?
142+
Token part of speech: PUNCT
143+
```
188144

189145
### Run Analyze Entity Sentiment
190146

191147
To run the Analyze Entity Sentiment sample:
192148

193-
$ php language.php entity-sentiment 'New York is great. New York is good.'
194-
Entity Name: New York
195-
Entity Type: LOCATION
196-
Entity Salience: 1
197-
Entity Magnitude: 1.7999999523163
198-
Entity Score: 0
199-
200-
Mentions:
201-
Begin Offset: 0
202-
Content: New York
203-
Mention Type: PROPER
204-
Mention Magnitude: 0.89999997615814
205-
Mention Score: 0.89999997615814
206-
207-
Begin Offset: 17
208-
Content: New York
209-
Mention Type: PROPER
210-
Mention Magnitude: 0.80000001192093
211-
Mention Score: -0.80000001192093
149+
```
150+
$ php src/analyze_entity_sentiment.php 'New York is great. New York is good.'
151+
Entity Name: New York
152+
Entity Type: LOCATION
153+
Entity Salience: 1
154+
Entity Magnitude: 1.8
155+
Entity Score: 0.9
156+
```
212157

213158
### Run Classify Text
214159

215160
To run the Classify Text sample:
216161

217-
$ php language.php classify 'The first two gubernatorial elections since
218-
President Donald Trump took office went in favor of Democratic candidates
219-
in Virginia and New Jersey.'
220-
Category Name: /News/Politics
221-
Confidence: 0.99000000953674
162+
```
163+
$ php src/classify_text.php 'The first two gubernatorial elections since
164+
President Donald Trump took office went in favor of Democratic candidates
165+
in Virginia and New Jersey.'
166+
Category Name: /News/Politics
167+
Confidence: 0.99
168+
```
222169

223170
## The client library
224171

language/composer.json

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
{
22
"require": {
33
"google/cloud-language": "~0.18",
4-
"google/cloud-storage": "^1.3",
5-
"symfony/console": "^3.0"
4+
"google/cloud-storage": "^1.3"
65
},
7-
"minimum-stability": "dev",
86
"require-dev": {
9-
"phpunit/phpunit": "~4.0",
7+
"phpunit/phpunit": "^5",
108
"google/cloud-tools": "dev-master"
11-
},
12-
"autoload": {
13-
"files": [
14-
"src/analyze_all.php",
15-
"src/analyze_all_from_file.php",
16-
"src/analyze_entities.php",
17-
"src/analyze_entities_from_file.php",
18-
"src/analyze_sentiment.php",
19-
"src/analyze_sentiment_from_file.php",
20-
"src/analyze_syntax.php",
21-
"src/analyze_syntax_from_file.php",
22-
"src/analyze_entity_sentiment.php",
23-
"src/analyze_entity_sentiment_from_file.php",
24-
"src/classify_text.php",
25-
"src/classify_text_from_file.php"
26-
]
279
}
2810
}

0 commit comments

Comments
 (0)