Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
9 changes: 9 additions & 0 deletions sdk/textanalytics/azure-ai-textanalytics/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
Original file line number Diff line number Diff line change
@@ -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())
Original file line number Diff line number Diff line change
@@ -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())
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading