Skip to content

Commit fe969b8

Browse files
committed
Remove grapheme_offset from output
1 parent f3b0054 commit fe969b8

File tree

1 file changed

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

1 file changed

+28
-30
lines changed

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def sentiment_analysis_example(client):
134134
response.confidence_scores.negative,
135135
))
136136
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))
138138
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
139139
print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
140140
sentence.confidence_scores.positive,
@@ -152,14 +152,14 @@ sentiment_analysis_example(client)
152152
Document Sentiment: positive
153153
Overall scores: positive=1.00; neutral=0.00; negative=0.00
154154

155-
[Offset: 0, Length: 30]
155+
[Length: 30]
156156
Sentence 1 sentiment: positive
157157
Sentence score:
158158
Positive=1.00
159159
Neutral=0.00
160160
Negative=0.00
161161

162-
[Offset: 31, Length: 30]
162+
[Length: 30]
163163
Sentence 2 sentiment: neutral
164164
Sentence score:
165165
Positive=0.21
@@ -249,9 +249,8 @@ def entity_recognition_example(client):
249249

250250
print("Named Entities:\n")
251251
for entity in result.entities:
252-
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
253-
"\n\tOffset: \t", entity.grapheme_offset, "\tLength: \t", entity.grapheme_offset,
254-
"\tConfidence Score: \t", round(entity.score, 2), "\n")
252+
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
253+
"\n\tLength: \t", entity.grapheme_length, "\tConfidence Score: \t", round(entity.score, 2), "\n")
255254

256255
except Exception as err:
257256
print("Encountered exception. {}".format(err))
@@ -263,11 +262,11 @@ entity_recognition_example(client)
263262
```console
264263
Named Entities:
265264

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
268267

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
271270
```
272271

273272
## Using NER to detect personal information
@@ -285,17 +284,17 @@ def entity_pii_example(client):
285284
print("Personally Identifiable Information Entities: ")
286285
for entity in result.entities:
287286
print("\tText: ",entity.text,"\tCategory: ", entity.category,"\tSubCategory: ", entity.subcategory)
288-
print("\t\tOffset: ", entity.grapheme_offset, "\tLength: ", entity.grapheme_length, "\tScore: {0:.2f}".format(entity.score), "\n")
287+
print("\t\tLength: ", entity.grapheme_length, "\tScore: {0:.2f}".format(entity.score), "\n")
289288

290289
entity_pii_example(client)
291290
```
292291

293292
### Output
294293

295294
```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
299298
```
300299

301300

@@ -321,8 +320,7 @@ def entity_linking_example(client):
321320
print("\tMatches:")
322321
for match in entity.matches:
323322
print("\t\tText:", match.text)
324-
print("\t\tScore: {0:.2f}".format(match.score), "\tOffset: ", match.grapheme_offset,
325-
"\tLength: {}\n".format(match.grapheme_length))
323+
print("\t\tScore: {0:.2f}".format(match.score), "\tLength: {}\n".format(match.grapheme_length))
326324

327325
except Exception as err:
328326
print("Encountered exception. {}".format(err))
@@ -334,47 +332,47 @@ entity_linking_example(client)
334332
```console
335333
Linked Entities:
336334

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
338336
Data Source: Wikipedia
339337
Matches:
340338
Text: Altair 8800
341-
Score: 0.78 Offset: 125 Length: 11
339+
Score: 0.78 Length: 11
342340

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
344342
Data Source: Wikipedia
345343
Matches:
346344
Text: Bill Gates
347-
Score: 0.55 Offset: 25 Length: 10
345+
Score: 0.55 Length: 10
348346

349347
Text: Gates
350-
Score: 0.55 Offset: 179 Length: 5
348+
Score: 0.55 Length: 5
351349

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
353351
Data Source: Wikipedia
354352
Matches:
355353
Text: Paul Allen
356-
Score: 0.53 Offset: 40 Length: 10
354+
Score: 0.53 Length: 10
357355

358-
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
356+
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
359357
Data Source: Wikipedia
360358
Matches:
361359
Text: Microsoft
362-
Score: 0.47 Offset: 0 Length: 9
360+
Score: 0.47 Length: 9
363361

364362
Text: Microsoft
365-
Score: 0.47 Offset: 168 Length: 9
363+
Score: 0.47 Length: 9
366364

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
368366
Data Source: Wikipedia
369367
Matches:
370368
Text: April 4
371-
Score: 0.25 Offset: 54 Length: 7
369+
Score: 0.25 Length: 7
372370

373-
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
371+
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
374372
Data Source: Wikipedia
375373
Matches:
376374
Text: BASIC
377-
Score: 0.28 Offset: 98 Length: 5
375+
Score: 0.28 Length: 5
378376

379377
```
380378

0 commit comments

Comments
 (0)