@@ -115,31 +115,32 @@ static void sentimentAnalysisExample(TextAnalyticsClient client)
115
115
String text = " I had the best day of my life. I wish you were there with me." ;
116
116
117
117
DocumentSentiment documentSentiment = client. analyzeSentiment(text);
118
+ System . out. printf(
119
+ " Recognized document sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n" ,
120
+ documentSentiment. getSentiment(),
121
+ documentSentiment. getConfidenceScores(). getPositive(),
122
+ documentSentiment. getConfidenceScores(). getNeutral(),
123
+ documentSentiment. getConfidenceScores(). getNegative());
124
+
125
+ for (SentenceSentiment sentenceSentiment : documentSentiment. getSentences()) {
118
126
System . out. printf(
119
- " Recognized document sentiment: %s, positive score: %.2f, neutral score: %.2f, negative score: %.2f.%n" ,
120
- documentSentiment. getSentiment(),
121
- documentSentiment. getConfidenceScores(). getPositive(),
122
- documentSentiment. getConfidenceScores(). getNeutral(),
123
- documentSentiment. getConfidenceScores(). getNegative());
124
-
125
- for (SentenceSentiment sentenceSentiment : documentSentiment. getSentences()) {
126
- System . out. printf(
127
- " Recognized sentence sentiment: %s, positive score: %.2f, neutral score: %.2f, negative score: %.2f.%n" ,
128
- sentenceSentiment. getSentiment(),
129
- sentenceSentiment. getConfidenceScores(). getPositive(),
130
- sentenceSentiment. getConfidenceScores(). getNeutral(),
131
- sentenceSentiment. getConfidenceScores(). getNegative());
132
- }
127
+ " Recognized sentence sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n" ,
128
+ sentenceSentiment. getSentiment(),
129
+ sentenceSentiment. getConfidenceScores(). getPositive(),
130
+ sentenceSentiment. getConfidenceScores(). getNeutral(),
131
+ sentenceSentiment. getConfidenceScores(). getNegative());
132
+ }
133
133
}
134
134
```
135
135
136
136
### Output
137
137
138
138
``` console
139
- Recognized document sentiment: positive, positive score: 1.00 , neutral score: 0.00 , negative score: 0.00 .
140
- Recognized sentence sentiment: positive, positive score: 1.00 , neutral score: 0.00 , negative score: 0.00 .
139
+ Recognized document sentiment: positive, positive score: 1.0 , neutral score: 0.0 , negative score: 0.0 .
140
+ Recognized sentence sentiment: positive, positive score: 1.0 , neutral score: 0.0 , negative score: 0.0 .
141
141
Recognized sentence sentiment: neutral, positive score: 0.21, neutral score: 0.77, negative score: 0.02.
142
142
```
143
+
143
144
## Language detection
144
145
145
146
Create a new function called ` detectLanguageExample() ` that takes the client that you created earlier, and call its ` detectLanguage() ` function. The returned ` DetectLanguageResult ` object will contain a primary language detected, a list of other languages detected if successful, or an ` errorMessage ` if not.
@@ -183,12 +184,10 @@ static void recognizeEntitiesExample(TextAnalyticsClient client)
183
184
184
185
for (CategorizedEntity entity : client. recognizeEntities(text)) {
185
186
System . out. printf(
186
- " Recognized entity: %s, entity category: %s, entity sub-category: %s, offset: %s, length: %s, score: %.2f .%n" ,
187
+ " Recognized entity: %s, entity category: %s, entity sub-category: %s, score: %s .%n" ,
187
188
entity. getText(),
188
189
entity. getCategory(),
189
- entity. getSubCategory() != null && ! entity. getSubCategory(). isEmpty() ? entity. getSubCategory() : " N/A" ,
190
- entity. getGraphemeOffset(),
191
- entity. getGraphemeLength(),
190
+ entity. getSubCategory(),
192
191
entity. getConfidenceScore());
193
192
}
194
193
}
@@ -197,8 +196,8 @@ static void recognizeEntitiesExample(TextAnalyticsClient client)
197
196
### Output
198
197
199
198
``` console
200
- Recognized entity: Seattle, entity category: Location, entity sub-category: GPE, offset: 26, length: 7, score: 0.92.
201
- Recognized entity: last week, entity category: DateTime, entity sub-category: DateRange, offset: 34, length: 9, score: 0.80 .
199
+ Recognized entity: Seattle, entity category: Location, entity sub-category: GPE, score: 0.92.
200
+ Recognized entity: last week, entity category: DateTime, entity sub-category: DateRange, score: 0.8 .
202
201
```
203
202
204
203
## Using NER to recognize personal information
@@ -213,12 +212,10 @@ static void recognizePIIEntitiesExample(TextAnalyticsClient client)
213
212
214
213
for (PiiEntity entity : client. recognizePiiEntities(text)) {
215
214
System . out. printf(
216
- " Recognized personal identifiable information entity: %s, entity category: %s, %nentity sub-category: %s, offset: %s, length: %s, score: %.2f .%n" ,
215
+ " Recognized personal identifiable information entity: %s, entity category: %s, %nentity sub-category: %s, score: %s .%n" ,
217
216
entity. getText(),
218
217
entity. getCategory(),
219
- entity. getSubCategory() != null && ! entity. getSubCategory(). isEmpty() ? entity. getSubCategory() : " N/A" ,
220
- entity. getGraphemeOffset(),
221
- entity. getGraphemeLength(),
218
+ entity. getSubCategory(),
222
219
entity. getConfidenceScore());
223
220
}
224
221
}
@@ -228,7 +225,7 @@ static void recognizePIIEntitiesExample(TextAnalyticsClient client)
228
225
229
226
``` console
230
227
Recognized personal identifiable information entity: 123-12-1234, entity category: U.S. Social Security Number (SSN),
231
- entity sub-category: N/A, offset: 33, length: 11 , score: 0.85.
228
+ entity sub-category: null , score: 0.85.
232
229
```
233
230
234
231
## Entity linking
@@ -254,10 +251,8 @@ static void recognizeLinkedEntitiesExample(TextAnalyticsClient client)
254
251
linkedEntity. getDataSource());
255
252
System . out. printf(" Matches:%n" );
256
253
for (LinkedEntityMatch linkedEntityMatch : linkedEntity. getLinkedEntityMatches()) {
257
- System . out. printf(" Text: %s, Offset: %s, Length: %s, Score: %.2f. %n" ,
254
+ System . out. printf(" Text: %s, Score: %.2f%n" ,
258
255
linkedEntityMatch. getText(),
259
- linkedEntityMatch. getGraphemeOffset(),
260
- linkedEntityMatch. getGraphemeLength(),
261
256
linkedEntityMatch. getConfidenceScore());
262
257
}
263
258
}
@@ -270,24 +265,24 @@ static void recognizeLinkedEntitiesExample(TextAnalyticsClient client)
270
265
Linked Entities:
271
266
Name: Altair 8800, ID: Altair 8800, URL: https://en.wikipedia.org/wiki/Altair_8800, Data Source: Wikipedia.
272
267
Matches:
273
- Text: Altair 8800, Offset: 11, Length: 116, Score: 0.78.
268
+ Text: Altair 8800, Score: 0.78
274
269
Name: Bill Gates, ID: Bill Gates, URL: https://en.wikipedia.org/wiki/Bill_Gates, Data Source: Wikipedia.
275
270
Matches:
276
- Text: Bill Gates, Offset: 10, Length: 25, Score: 0.55.
277
- Text: Gates, Offset: 5, Length: 161, Score: 0.55.
271
+ Text: Bill Gates, Score: 0.55
272
+ Text: Gates, Score: 0.55
278
273
Name: Paul Allen, ID: Paul Allen, URL: https://en.wikipedia.org/wiki/Paul_Allen, Data Source: Wikipedia.
279
274
Matches:
280
- Text: Paul Allen, Offset: 10, Length: 40, Score: 0.53.
275
+ Text: Paul Allen, Score: 0.53
281
276
Name: Microsoft, ID: Microsoft, URL: https://en.wikipedia.org/wiki/Microsoft, Data Source: Wikipedia.
282
277
Matches:
283
- Text: Microsoft, Offset: 9, Length: 0, Score: 0.47.
284
- Text: Microsoft, Offset: 9, Length: 150, Score: 0.47.
278
+ Text: Microsoft, Score: 0.47
279
+ Text: Microsoft, Score: 0.47
285
280
Name: April 4, ID: April 4, URL: https://en.wikipedia.org/wiki/April_4, Data Source: Wikipedia.
286
281
Matches:
287
- Text: April 4, Offset: 7, Length: 54, Score: 0.25.
282
+ Text: April 4, Score: 0.25
288
283
Name: BASIC, ID: BASIC, URL: https://en.wikipedia.org/wiki/BASIC, Data Source: Wikipedia.
289
284
Matches:
290
- Text: BASIC, Offset: 5, Length: 89, Score: 0.28.
285
+ Text: BASIC, Score: 0.28
291
286
```
292
287
## Key phrase extraction
293
288
0 commit comments