Skip to content

Commit f3b0054

Browse files
committed
Update Python Quickstarts with preview.3
1 parent e984855 commit f3b0054

File tree

1 file changed

+31
-31
lines changed
  • articles/cognitive-services/text-analytics/includes/quickstarts

1 file changed

+31
-31
lines changed

articles/cognitive-services/text-analytics/includes/quickstarts/python-sdk.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,18 @@ def sentiment_analysis_example(client):
128128
document = ["I had the best day of my life. I wish you were there with me."]
129129
response = client.analyze_sentiment(inputs=document)[0]
130130
print("Document Sentiment: {}".format(response.sentiment))
131-
print("Overall scores: positive={0:.3f}; neutral={1:.3f}; negative={2:.3f} \n".format(
132-
response.sentiment_scores.positive,
133-
response.sentiment_scores.neutral,
134-
response.sentiment_scores.negative,
131+
print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
132+
response.confidence_scores.positive,
133+
response.confidence_scores.neutral,
134+
response.confidence_scores.negative,
135135
))
136136
for idx, sentence in enumerate(response.sentences):
137-
print("[Offset: {}, Length: {}]".format(sentence.offset, sentence.length))
137+
print("[Offset: {}, Length: {}]".format(sentence.grapheme_offset, sentence.grapheme_length))
138138
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
139-
print("Sentence score:\nPositive={0:.3f}\nNeutral={1:.3f}\nNegative={2:.3f}\n".format(
140-
sentence.sentiment_scores.positive,
141-
sentence.sentiment_scores.neutral,
142-
sentence.sentiment_scores.negative,
139+
print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
140+
sentence.confidence_scores.positive,
141+
sentence.confidence_scores.neutral,
142+
sentence.confidence_scores.negative,
143143
))
144144

145145

@@ -150,21 +150,21 @@ sentiment_analysis_example(client)
150150

151151
```console
152152
Document Sentiment: positive
153-
Overall scores: positive=1.000; neutral=0.000; negative=0.000
153+
Overall scores: positive=1.00; neutral=0.00; negative=0.00
154154

155155
[Offset: 0, Length: 30]
156156
Sentence 1 sentiment: positive
157157
Sentence score:
158-
Positive=1.000
159-
Neutral=0.000
160-
Negative=0.000
158+
Positive=1.00
159+
Neutral=0.00
160+
Negative=0.00
161161

162162
[Offset: 31, Length: 30]
163163
Sentence 2 sentiment: neutral
164164
Sentence score:
165-
Positive=0.210
166-
Neutral=0.770
167-
Negative=0.020
165+
Positive=0.21
166+
Neutral=0.77
167+
Negative=0.02
168168
```
169169

170170
#### [Version 2.1](#tab/version-2)
@@ -250,8 +250,8 @@ def entity_recognition_example(client):
250250
print("Named Entities:\n")
251251
for entity in result.entities:
252252
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
253-
"\n\tOffset: \t", entity.offset, "\tLength: \t", entity.offset,
254-
"\tConfidence Score: \t", round(entity.score, 3), "\n")
253+
"\n\tOffset: \t", entity.grapheme_offset, "\tLength: \t", entity.grapheme_offset,
254+
"\tConfidence Score: \t", round(entity.score, 2), "\n")
255255

256256
except Exception as err:
257257
print("Encountered exception. {}".format(err))
@@ -285,7 +285,7 @@ def entity_pii_example(client):
285285
print("Personally Identifiable Information Entities: ")
286286
for entity in result.entities:
287287
print("\tText: ",entity.text,"\tCategory: ", entity.category,"\tSubCategory: ", entity.subcategory)
288-
print("\t\tOffset: ", entity.offset, "\tLength: ", entity.length, "\tScore: {0:.3f}".format(entity.score), "\n")
288+
print("\t\tOffset: ", entity.grapheme_offset, "\tLength: ", entity.grapheme_length, "\tScore: {0:.2f}".format(entity.score), "\n")
289289

290290
entity_pii_example(client)
291291
```
@@ -295,7 +295,7 @@ entity_pii_example(client)
295295
```console
296296
Personally Identifiable Information Entities:
297297
Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
298-
Offset: 33 Length: 11 Score: 0.850
298+
Offset: 33 Length: 11 Score: 0.85
299299
```
300300

301301

@@ -316,13 +316,13 @@ def entity_linking_example(client):
316316

317317
print("Linked Entities:\n")
318318
for entity in result.entities:
319-
print("\tName: ", entity.name, "\tId: ", entity.id, "\tUrl: ", entity.url,
319+
print("\tName: ", entity.name, "\tId: ", entity.data_source_entity_id, "\tUrl: ", entity.url,
320320
"\n\tData Source: ", entity.data_source)
321321
print("\tMatches:")
322322
for match in entity.matches:
323323
print("\t\tText:", match.text)
324-
print("\t\tScore: {0:.3f}".format(match.score), "\tOffset: ", match.offset,
325-
"\tLength: {}\n".format(match.length))
324+
print("\t\tScore: {0:.2f}".format(match.score), "\tOffset: ", match.grapheme_offset,
325+
"\tLength: {}\n".format(match.grapheme_length))
326326

327327
except Exception as err:
328328
print("Encountered exception. {}".format(err))
@@ -338,43 +338,43 @@ Linked Entities:
338338
Data Source: Wikipedia
339339
Matches:
340340
Text: Altair 8800
341-
Score: 0.777 Offset: 125 Length: 11
341+
Score: 0.78 Offset: 125 Length: 11
342342

343343
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
344344
Data Source: Wikipedia
345345
Matches:
346346
Text: Bill Gates
347-
Score: 0.555 Offset: 25 Length: 10
347+
Score: 0.55 Offset: 25 Length: 10
348348

349349
Text: Gates
350-
Score: 0.555 Offset: 179 Length: 5
350+
Score: 0.55 Offset: 179 Length: 5
351351

352352
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
353353
Data Source: Wikipedia
354354
Matches:
355355
Text: Paul Allen
356-
Score: 0.533 Offset: 40 Length: 10
356+
Score: 0.53 Offset: 40 Length: 10
357357

358358
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
359359
Data Source: Wikipedia
360360
Matches:
361361
Text: Microsoft
362-
Score: 0.469 Offset: 0 Length: 9
362+
Score: 0.47 Offset: 0 Length: 9
363363

364364
Text: Microsoft
365-
Score: 0.469 Offset: 168 Length: 9
365+
Score: 0.47 Offset: 168 Length: 9
366366

367367
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
368368
Data Source: Wikipedia
369369
Matches:
370370
Text: April 4
371-
Score: 0.248 Offset: 54 Length: 7
371+
Score: 0.25 Offset: 54 Length: 7
372372

373373
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
374374
Data Source: Wikipedia
375375
Matches:
376376
Text: BASIC
377-
Score: 0.281 Offset: 98 Length: 5
377+
Score: 0.28 Offset: 98 Length: 5
378378

379379
```
380380

0 commit comments

Comments
 (0)