@@ -134,7 +134,7 @@ def sentiment_analysis_example(client):
134
134
response.confidence_scores.negative,
135
135
))
136
136
for idx, sentence in enumerate (response.sentences):
137
- print (" [Offset: {} , Length: {} ]" .format(sentence.grapheme_offset, sentence.grapheme_length))
137
+ print (" [Length: {} ]" .format(sentence.grapheme_length))
138
138
print (" Sentence {} sentiment: {} " .format(idx+ 1 , sentence.sentiment))
139
139
print (" Sentence score:\n Positive={0:.2f } \n Neutral={1:.2f } \n Negative={2:.2f } \n " .format(
140
140
sentence.confidence_scores.positive,
@@ -152,14 +152,14 @@ sentiment_analysis_example(client)
152
152
Document Sentiment: positive
153
153
Overall scores: positive=1.00; neutral=0.00; negative=0.00
154
154
155
- [Offset: 0, Length: 30]
155
+ [Length: 30]
156
156
Sentence 1 sentiment: positive
157
157
Sentence score:
158
158
Positive=1.00
159
159
Neutral=0.00
160
160
Negative=0.00
161
161
162
- [Offset: 31, Length: 30]
162
+ [Length: 30]
163
163
Sentence 2 sentiment: neutral
164
164
Sentence score:
165
165
Positive=0.21
@@ -249,9 +249,8 @@ def entity_recognition_example(client):
249
249
250
250
print (" Named Entities:\n " )
251
251
for entity in result.entities:
252
- print (" \t Text: \t " , entity.text, " \t Category: \t " , entity.category, " \t SubCategory: \t " , entity.subcategory,
253
- " \n\t Offset: \t " , entity.grapheme_offset, " \t Length: \t " , entity.grapheme_offset,
254
- " \t Confidence Score: \t " , round (entity.score, 2 ), " \n " )
252
+ print (" \t Text: \t " , entity.text, " \t Category: \t " , entity.category, " \t SubCategory: \t " , entity.subcategory,
253
+ " \n\t Length: \t " , entity.grapheme_length, " \t Confidence Score: \t " , round (entity.score, 2 ), " \n " )
255
254
256
255
except Exception as err:
257
256
print (" Encountered exception. {} " .format(err))
@@ -263,11 +262,11 @@ entity_recognition_example(client)
263
262
``` console
264
263
Named Entities:
265
264
266
- Text: Seattle Category: Location SubCategory: GPE
267
- Offset : 26 Length: 26 Confidence Score: 0.92
265
+ Text: Seattle Category: Location SubCategory: GPE
266
+ Length : 7 Confidence Score: 0.92
268
267
269
- Text: last week Category: DateTime SubCategory: DateRange
270
- Offset : 34 Length: 34 Confidence Score: 0.8
268
+ Text: last week Category: DateTime SubCategory: DateRange
269
+ Length : 9 Confidence Score: 0.8
271
270
```
272
271
273
272
## Using NER to detect personal information
@@ -285,17 +284,17 @@ def entity_pii_example(client):
285
284
print (" Personally Identifiable Information Entities: " )
286
285
for entity in result.entities:
287
286
print (" \t Text: " ,entity.text," \t Category: " , entity.category," \t SubCategory: " , entity.subcategory)
288
- print (" \t\t Offset: " , entity.grapheme_offset, " \ t Length: " , entity.grapheme_length, " \t Score: {0:.2f } " .format(entity.score), " \n " )
287
+ print (" \t\t Length: " , entity.grapheme_length, " \t Score: {0:.2f } " .format(entity.score), " \n " )
289
288
290
289
entity_pii_example(client)
291
290
```
292
291
293
292
### Output
294
293
295
294
``` console
296
- Personally Identifiable Information Entities:
297
- Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
298
- Offset: 33 Length: 11 Score: 0.85
295
+ Personally Identifiable Information Entities:
296
+ Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
297
+ Length: 11 Score: 0.85
299
298
```
300
299
301
300
@@ -321,8 +320,7 @@ def entity_linking_example(client):
321
320
print (" \t Matches:" )
322
321
for match in entity.matches:
323
322
print (" \t\t Text:" , match.text)
324
- print (" \t\t Score: {0:.2f } " .format(match.score), " \t Offset: " , match.grapheme_offset,
325
- " \t Length: {} \n " .format(match.grapheme_length))
323
+ print (" \t\t Score: {0:.2f } " .format(match.score), " \t Length: {} \n " .format(match.grapheme_length))
326
324
327
325
except Exception as err:
328
326
print (" Encountered exception. {} " .format(err))
@@ -334,47 +332,47 @@ entity_linking_example(client)
334
332
``` console
335
333
Linked Entities:
336
334
337
- Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
335
+ Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
338
336
Data Source: Wikipedia
339
337
Matches:
340
338
Text: Altair 8800
341
- Score: 0.78 Offset: 125 Length: 11
339
+ Score: 0.78 Length: 11
342
340
343
- Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
341
+ Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
344
342
Data Source: Wikipedia
345
343
Matches:
346
344
Text: Bill Gates
347
- Score: 0.55 Offset: 25 Length: 10
345
+ Score: 0.55 Length: 10
348
346
349
347
Text: Gates
350
- Score: 0.55 Offset: 179 Length: 5
348
+ Score: 0.55 Length: 5
351
349
352
- Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
350
+ Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
353
351
Data Source: Wikipedia
354
352
Matches:
355
353
Text: Paul Allen
356
- Score: 0.53 Offset: 40 Length: 10
354
+ Score: 0.53 Length: 10
357
355
358
- Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
356
+ Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
359
357
Data Source: Wikipedia
360
358
Matches:
361
359
Text: Microsoft
362
- Score: 0.47 Offset: 0 Length: 9
360
+ Score: 0.47 Length: 9
363
361
364
362
Text: Microsoft
365
- Score: 0.47 Offset: 168 Length: 9
363
+ Score: 0.47 Length: 9
366
364
367
- Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
365
+ Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
368
366
Data Source: Wikipedia
369
367
Matches:
370
368
Text: April 4
371
- Score: 0.25 Offset: 54 Length: 7
369
+ Score: 0.25 Length: 7
372
370
373
- Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
371
+ Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
374
372
Data Source: Wikipedia
375
373
Matches:
376
374
Text: BASIC
377
- Score: 0.28 Offset: 98 Length: 5
375
+ Score: 0.28 Length: 5
378
376
379
377
```
380
378
0 commit comments