Skip to content

Commit 563e0ac

Browse files
authored
Merge pull request #46 from thediris/patch-3
udpate Python TextAnalytics quickstart to adhere to sdk changes, and reflect that api v3.0 is not preview anymore
2 parents a78af03 + 541a865 commit 563e0ac

File tree

1 file changed

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

1 file changed

+55
-59
lines changed

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

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.author: aahi
88

99
<a name="HOLTop"></a>
1010

11-
#### [Version 3.0-preview](#tab/version-3)
11+
#### [Version 3.0](#tab/version-3)
1212

1313
[v3 Reference documentation](https://aka.ms/azsdk-python-textanalytics-ref-docs) | [v3 Library source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics) | [v3 Package (PiPy)](https://pypi.org/project/azure-ai-textanalytics/) | [v3 Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples)
1414

@@ -32,7 +32,7 @@ ms.author: aahi
3232

3333
After installing Python, you can install the client library with:
3434

35-
#### [Version 3.0-preview](#tab/version-3)
35+
#### [Version 3.0](#tab/version-3)
3636

3737
```console
3838
pip install azure-ai-textanalytics
@@ -66,7 +66,7 @@ endpoint = "<paste-your-text-analytics-endpoint-here>"
6666

6767
## Object model
6868

69-
#### [Version 3.0-preview](#tab/version-3)
69+
#### [Version 3.0](#tab/version-3)
7070

7171
The Text Analytics client is a `TextAnalyticsClient` object that authenticates to Azure using your key. The client provides several methods for analyzing text as a batch.
7272

@@ -95,7 +95,7 @@ These code snippets show you how to do the following tasks with the Text Analyti
9595

9696
## Authenticate the client
9797

98-
#### [Version 3.0-preview](#tab/version-3)
98+
#### [Version 3.0](#tab/version-3)
9999

100100
Create a function to instantiate the `TextAnalyticsClient` object with your `key` AND `endpoint` created above. Then create a new client.
101101

@@ -124,7 +124,7 @@ Create a function to instantiate the `TextAnalyticsClient` object with your `key
124124

125125
## Sentiment analysis
126126

127-
#### [Version 3.0-preview](#tab/version-3)
127+
#### [Version 3.0](#tab/version-3)
128128

129129
Create a new function called `sentiment_analysis_example()` that takes the client as an argument, then calls the `analyze_sentiment()` function. The returned response object will contain the sentiment label and score of the entire input document, as well as a sentiment analysis for each sentence.
130130

@@ -141,7 +141,7 @@ def sentiment_analysis_example(client):
141141
response.confidence_scores.negative,
142142
))
143143
for idx, sentence in enumerate(response.sentences):
144-
print("[Length: {}]".format(sentence.grapheme_length))
144+
print("Sentence: {}".format(sentence.text))
145145
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
146146
print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
147147
sentence.confidence_scores.positive,
@@ -158,14 +158,14 @@ sentiment_analysis_example(client)
158158
Document Sentiment: positive
159159
Overall scores: positive=1.00; neutral=0.00; negative=0.00
160160

161-
[Length: 30]
161+
Sentence: I had the best day of my life.
162162
Sentence 1 sentiment: positive
163163
Sentence score:
164164
Positive=1.00
165165
Neutral=0.00
166166
Negative=0.00
167167

168-
[Length: 30]
168+
Sentence: I wish you were there with me.
169169
Sentence 2 sentiment: neutral
170170
Sentence score:
171171
Positive=0.21
@@ -192,7 +192,7 @@ Document ID: 4 , Sentiment Score: 1.00
192192

193193
## Language detection
194194

195-
#### [Version 3.0-preview](#tab/version-3)
195+
#### [Version 3.0](#tab/version-3)
196196

197197
Create a new function called `language_detection_example()` that takes the client as an argument, then calls the `detect_language()` function. The returned response object will contain the detected language in `primary_language` if successful, and an `error` if not.
198198

@@ -237,10 +237,10 @@ Document ID: 3 , Language: Chinese_Simplified
237237

238238
## Named Entity recognition (NER)
239239

240-
#### [Version 3.0-preview](#tab/version-3)
240+
#### [Version 3.0](#tab/version-3)
241241

242242
> [!NOTE]
243-
> In version `3.0-preview`:
243+
> In version `3.0`:
244244
> * Entity linking is a separate request than NER.
245245
246246
Create a new function called `entity_recognition_example` that takes the client as an argument, then calls the `recognize_entities()` function and iterates through the results. The returned response object will contain the list of detected entities in `entity` if successful, and an `error` if not. For each detected entity, print its Category and Sub-Category if exists.
@@ -255,7 +255,7 @@ def entity_recognition_example(client):
255255
print("Named Entities:\n")
256256
for entity in result.entities:
257257
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
258-
"\n\tLength: \t", entity.grapheme_length, "\tConfidence Score: \t", round(entity.confidence_score, 2), "\n")
258+
"\n\tConfidence Score: \t", round(entity.confidence_score, 2), "\n")
259259

260260
except Exception as err:
261261
print("Encountered exception. {}".format(err))
@@ -267,11 +267,14 @@ entity_recognition_example(client)
267267
```console
268268
Named Entities:
269269

270-
Text: Seattle Category: Location SubCategory: GPE
271-
Length: 7 Confidence Score: 0.92
270+
Text: trip Category: Event SubCategory: None
271+
Confidence Score: 0.61
272272

273-
Text: last week Category: DateTime SubCategory: DateRange
274-
Length: 9 Confidence Score: 0.8
273+
Text: Seattle Category: Location SubCategory: GPE
274+
Confidence Score: 0.82
275+
276+
Text: last week Category: DateTime SubCategory: DateRange
277+
Confidence Score: 0.8
275278
```
276279

277280
## Entity Linking
@@ -296,7 +299,7 @@ def entity_linking_example(client):
296299
print("\tMatches:")
297300
for match in entity.matches:
298301
print("\t\tText:", match.text)
299-
print("\t\tConfidence Score: {0:.2f}".format(match.confidence_score), "\tLength: {}\n".format(match.grapheme_length))
302+
print("\t\tConfidence Score: {0:.2f}".format(match.confidence_score))
300303

301304
except Exception as err:
302305
print("Encountered exception. {}".format(err))
@@ -308,47 +311,40 @@ entity_linking_example(client)
308311
```console
309312
Linked Entities:
310313

311-
Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
312-
Data Source: Wikipedia
313-
Matches:
314-
Text: Altair 8800
315-
Confidence Score: 0.00 Length: 11
316-
317-
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
318-
Data Source: Wikipedia
319-
Matches:
320-
Text: Bill Gates
321-
Confidence Score: 0.00 Length: 10
322-
323-
Text: Gates
324-
Confidence Score: 0.00 Length: 5
325-
326-
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
327-
Data Source: Wikipedia
328-
Matches:
329-
Text: Paul Allen
330-
Confidence Score: 0.00 Length: 10
331-
332-
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
333-
Data Source: Wikipedia
334-
Matches:
335-
Text: Microsoft
336-
Confidence Score: 0.00 Length: 9
337-
338-
Text: Microsoft
339-
Confidence Score: 0.00 Length: 9
340-
341-
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
342-
Data Source: Wikipedia
343-
Matches:
344-
Text: April 4
345-
Confidence Score: 0.00 Length: 7
346-
347-
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
348-
Data Source: Wikipedia
349-
Matches:
350-
Text: BASIC
351-
Confidence Score: 0.00 Length: 5
314+
Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
315+
Data Source: Wikipedia
316+
Matches:
317+
Text: Altair 8800
318+
Confidence Score: 0.88
319+
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
320+
Data Source: Wikipedia
321+
Matches:
322+
Text: Bill Gates
323+
Confidence Score: 0.63
324+
Text: Gates
325+
Confidence Score: 0.63
326+
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
327+
Data Source: Wikipedia
328+
Matches:
329+
Text: Paul Allen
330+
Confidence Score: 0.60
331+
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
332+
Data Source: Wikipedia
333+
Matches:
334+
Text: Microsoft
335+
Confidence Score: 0.55
336+
Text: Microsoft
337+
Confidence Score: 0.55
338+
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
339+
Data Source: Wikipedia
340+
Matches:
341+
Text: April 4
342+
Confidence Score: 0.32
343+
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
344+
Data Source: Wikipedia
345+
Matches:
346+
Text: BASIC
347+
Confidence Score: 0.33
352348
```
353349

354350
#### [Version 2.1](#tab/version-2)
@@ -404,7 +400,7 @@ Document ID: 2
404400
## Key phrase extraction
405401

406402

407-
#### [Version 3.0-preview](#tab/version-3)
403+
#### [Version 3.0](#tab/version-3)
408404

409405
Create a new function called `key_phrase_extraction_example()` that takes the client as an argument, then calls the `extract_key_phrases()` function. The result will contain the list of detected key phrases in `key_phrases` if successful, and an `error` if not. Print any detected key phrases.
410406

0 commit comments

Comments
 (0)