From 15213183b67184a136928990f808efe78955461b Mon Sep 17 00:00:00 2001 From: "Slai.life" Date: Fri, 30 Oct 2026 06:22:27 +0800 Subject: [PATCH 1/2] docs(textanalytics): add Vietnamese samples for issue 49700 --- .../azure-ai-textanalytics/samples/README.md | 9 +++ ...mple_analyze_sentiment_vietnamese_async.py | 63 +++++++++++++++++++ ...le_extract_key_phrases_vietnamese_async.py | 61 ++++++++++++++++++ ...ple_recognize_entities_vietnamese_async.py | 63 +++++++++++++++++++ .../sample_analyze_sentiment_vietnamese.py | 55 ++++++++++++++++ .../sample_extract_key_phrases_vietnamese.py | 53 ++++++++++++++++ .../sample_recognize_entities_vietnamese.py | 55 ++++++++++++++++ 7 files changed, 359 insertions(+) create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_vietnamese_async.py create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_vietnamese_async.py create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_vietnamese_async.py create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment_vietnamese.py create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases_vietnamese.py create mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities_vietnamese.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md index f33960029cd8..8276a8bbb1bd 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md @@ -26,6 +26,9 @@ These sample programs show common scenarios for the Text Analytics client's offe |[sample_recognize_pii_entities.py][recognize_pii_entities] and [sample_recognize_pii_entities_async.py][recognize_pii_entities_async]|Recognize personally identifiable information in documents| |[sample_extract_key_phrases.py][extract_key_phrases] and [sample_extract_key_phrases_async.py][extract_key_phrases_async]|Extract key phrases from documents| |[sample_analyze_sentiment.py][analyze_sentiment] and [sample_analyze_sentiment_async.py][analyze_sentiment_async]|Analyze the sentiment of documents| +|[sample_analyze_sentiment_vietnamese.py][analyze_sentiment_vietnamese] and [sample_analyze_sentiment_vietnamese_async.py][analyze_sentiment_vietnamese_async]|Analyze sentiment in Vietnamese documents| +|[sample_extract_key_phrases_vietnamese.py][extract_key_phrases_vietnamese] and [sample_extract_key_phrases_vietnamese_async.py][extract_key_phrases_vietnamese_async]|Extract key phrases from Vietnamese documents| +|[sample_recognize_entities_vietnamese.py][recognize_entities_vietnamese] and [sample_recognize_entities_vietnamese_async.py][recognize_entities_vietnamese_async]|Recognize named entities in Vietnamese documents| |[sample_alternative_document_input.py][sample_alternative_document_input] and [sample_alternative_document_input_async.py][sample_alternative_document_input_async]|Pass documents to an endpoint using dicts| |[sample_analyze_healthcare_entities.py][analyze_healthcare_entities_sample] and [sample_analyze_healthcare_entities_async.py][analyze_healthcare_entities_sample_async]|Analyze healthcare entities| |[sample_analyze_actions.py][analyze_sample] and [sample_analyze_actions_async.py][analyze_sample_async]|Run multiple analyses together in a single request| @@ -92,6 +95,12 @@ what you can do with the Azure Text Analytics client library. [extract_key_phrases_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_async.py [analyze_sentiment]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment.py [analyze_sentiment_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_async.py +[analyze_sentiment_vietnamese]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment_vietnamese.py +[analyze_sentiment_vietnamese_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_vietnamese_async.py +[extract_key_phrases_vietnamese]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases_vietnamese.py +[extract_key_phrases_vietnamese_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_vietnamese_async.py +[recognize_entities_vietnamese]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities_vietnamese.py +[recognize_entities_vietnamese_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_vietnamese_async.py [get_detailed_diagnostics_information]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_get_detailed_diagnostics_information.py [get_detailed_diagnostics_information_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py [sample_alternative_document_input]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_alternative_document_input.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_vietnamese_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_vietnamese_async.py new file mode 100644 index 000000000000..db160757ade7 --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_vietnamese_async.py @@ -0,0 +1,63 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_analyze_sentiment_vietnamese_async.py + +DESCRIPTION: + This sample demonstrates asynchronous sentiment analysis for Vietnamese documents. + +USAGE: + python sample_analyze_sentiment_vietnamese_async.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + +import asyncio + + +async def sample_analyze_sentiment_vietnamese_async() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics.aio import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + documents = [ + { + "id": "1", + "language": "vi", + "text": "Dịch vụ giao hàng nhanh chóng và nhân viên hỗ trợ rất nhiệt tình.", + }, + { + "id": "2", + "language": "vi", + "text": "Ứng dụng thường xuyên bị lỗi và trải nghiệm thanh toán rất chậm.", + }, + ] + + async with client: + result = await client.analyze_sentiment(documents) + + for document, analysis in zip(documents, result): + if analysis.is_error: + print(f"Error analyzing document: {analysis.error}") + else: + print(f"Document: {document}") + print(f"Sentiment: {analysis.sentiment}") + print(f"Confidence scores: {analysis.confidence_scores}\n") + + +async def main() -> None: + await sample_analyze_sentiment_vietnamese_async() + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_vietnamese_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_vietnamese_async.py new file mode 100644 index 000000000000..df46aeeaab5c --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_vietnamese_async.py @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_extract_key_phrases_vietnamese_async.py + +DESCRIPTION: + This sample demonstrates asynchronous key phrase extraction for Vietnamese documents. + +USAGE: + python sample_extract_key_phrases_vietnamese_async.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + +import asyncio + + +async def sample_extract_key_phrases_vietnamese_async() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics.aio import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + articles = [ + { + "id": "1", + "language": "vi", + "text": "Thành phố Đà Nẵng triển khai hệ thống giao thông thông minh để giảm ùn tắc.", + }, + { + "id": "2", + "language": "vi", + "text": "Doanh nghiệp đầu tư vào năng lượng tái tạo và mở rộng trung tâm dữ liệu.", + }, + ] + + async with client: + result = await client.extract_key_phrases(articles) + + for index, document in enumerate(result): + if document.is_error: + print(f"Error analyzing article {index + 1}: {document.error}") + else: + print(f"Key phrases in article {index + 1}: {', '.join(document.key_phrases)}") + + +async def main() -> None: + await sample_extract_key_phrases_vietnamese_async() + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_vietnamese_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_vietnamese_async.py new file mode 100644 index 000000000000..24af754f4baa --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_vietnamese_async.py @@ -0,0 +1,63 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_recognize_entities_vietnamese_async.py + +DESCRIPTION: + This sample demonstrates asynchronous named entity recognition for Vietnamese documents. + +USAGE: + python sample_recognize_entities_vietnamese_async.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + +import asyncio + + +async def sample_recognize_entities_vietnamese_async() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics.aio import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + documents = [ + { + "id": "1", + "language": "vi", + "text": "Tập đoàn FPT mở văn phòng mới tại Thành phố Hồ Chí Minh vào tháng này.", + }, + { + "id": "2", + "language": "vi", + "text": "Ngân hàng Việt Nam ký thỏa thuận hợp tác với Công ty ABC tại Hà Nội.", + }, + ] + + async with client: + result = await client.recognize_entities(documents) + + for index, document in enumerate(result): + if document.is_error: + print(f"Error analyzing document {index + 1}: {document.error}") + else: + print(f"Entities in document {index + 1}:") + for entity in document.entities: + print(f" {entity.text}: {entity.category} ({entity.confidence_score:.2f})") + + +async def main() -> None: + await sample_recognize_entities_vietnamese_async() + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment_vietnamese.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment_vietnamese.py new file mode 100644 index 000000000000..abc28f03b3ca --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment_vietnamese.py @@ -0,0 +1,55 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_analyze_sentiment_vietnamese.py + +DESCRIPTION: + This sample demonstrates sentiment analysis for Vietnamese documents. + +USAGE: + python sample_analyze_sentiment_vietnamese.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + + +def sample_analyze_sentiment_vietnamese() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + documents = [ + { + "id": "1", + "language": "vi", + "text": "Dịch vụ giao hàng nhanh chóng và nhân viên hỗ trợ rất nhiệt tình.", + }, + { + "id": "2", + "language": "vi", + "text": "Ứng dụng thường xuyên bị lỗi và trải nghiệm thanh toán rất chậm.", + }, + ] + + result = client.analyze_sentiment(documents) + for document, analysis in zip(documents, result): + if analysis.is_error: + print(f"Error analyzing document: {analysis.error}") + else: + print(f"Document: {document}") + print(f"Sentiment: {analysis.sentiment}") + print(f"Confidence scores: {analysis.confidence_scores}\n") + + +if __name__ == "__main__": + sample_analyze_sentiment_vietnamese() \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases_vietnamese.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases_vietnamese.py new file mode 100644 index 000000000000..60b051ac7f69 --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases_vietnamese.py @@ -0,0 +1,53 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_extract_key_phrases_vietnamese.py + +DESCRIPTION: + This sample demonstrates key phrase extraction for Vietnamese documents. + +USAGE: + python sample_extract_key_phrases_vietnamese.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + + +def sample_extract_key_phrases_vietnamese() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + articles = [ + { + "id": "1", + "language": "vi", + "text": "Thành phố Đà Nẵng triển khai hệ thống giao thông thông minh để giảm ùn tắc.", + }, + { + "id": "2", + "language": "vi", + "text": "Doanh nghiệp đầu tư vào năng lượng tái tạo và mở rộng trung tâm dữ liệu.", + }, + ] + + result = client.extract_key_phrases(articles) + for index, document in enumerate(result): + if document.is_error: + print(f"Error analyzing article {index + 1}: {document.error}") + else: + print(f"Key phrases in article {index + 1}: {', '.join(document.key_phrases)}") + + +if __name__ == "__main__": + sample_extract_key_phrases_vietnamese() \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities_vietnamese.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities_vietnamese.py new file mode 100644 index 000000000000..a42a643b4509 --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities_vietnamese.py @@ -0,0 +1,55 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_recognize_entities_vietnamese.py + +DESCRIPTION: + This sample demonstrates named entity recognition for Vietnamese documents. + +USAGE: + python sample_recognize_entities_vietnamese.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. + 2) AZURE_LANGUAGE_KEY - your Language subscription key. +""" + + +def sample_recognize_entities_vietnamese() -> None: + import os + from azure.core.credentials import AzureKeyCredential + from azure.ai.textanalytics import TextAnalyticsClient + + endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] + key = os.environ["AZURE_LANGUAGE_KEY"] + client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + + documents = [ + { + "id": "1", + "language": "vi", + "text": "Tập đoàn FPT mở văn phòng mới tại Thành phố Hồ Chí Minh vào tháng này.", + }, + { + "id": "2", + "language": "vi", + "text": "Ngân hàng Việt Nam ký thỏa thuận hợp tác với Công ty ABC tại Hà Nội.", + }, + ] + + result = client.recognize_entities(documents) + for index, document in enumerate(result): + if document.is_error: + print(f"Error analyzing document {index + 1}: {document.error}") + else: + print(f"Entities in document {index + 1}:") + for entity in document.entities: + print(f" {entity.text}: {entity.category} ({entity.confidence_score:.2f})") + + +if __name__ == "__main__": + sample_recognize_entities_vietnamese() \ No newline at end of file From 8727f6093d4738cf0aa8fcd6eb3a86926d421eed Mon Sep 17 00:00:00 2001 From: "Slai.life" Date: Fri, 30 Oct 2026 07:19:01 +0800 Subject: [PATCH 2/2] docs(textanalytics): add Vietnamese sample spellings --- .vscode/cspell.json | 52 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 60c5b116004f..6322eb0f5d98 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -799,7 +799,57 @@ "engelska", "fhir", "FHIR", - "naam" + "naam", + "Dịch", + "giao", + "hàng", + "nhanh", + "chóng", + "nhân", + "viên", + "nhiệt", + "tình", + "dụng", + "thường", + "xuyên", + "trải", + "nghiệm", + "thanh", + "toán", + "chậm", + "Thành", + "Nẵng", + "triển", + "khai", + "thống", + "thông", + "minh", + "giảm", + "Doanh", + "nghiệp", + "năng", + "lượng", + "rộng", + "trung", + "liệu", + "Tập", + "đoàn", + "phòng", + "Hồ", + "Chí", + "Minh", + "tháng", + "Ngân", + "Việt", + "ký", + "thỏa", + "thuận", + "hợp", + "tác", + "Công", + "ty", + "Hà", + "Nội" ] }, {