зеркало из
1
0
Форкнуть 0

[textanalytics] Moves textanalytics track2 and renames namespace/package (#9149)

* moves text analytics track 2 to sdk/textanalytics and renames to azure-ai-textanalytics

* more renames

* fix env var name for async testcase

* bump azure-core version in setup.py

* update shared reqs

* readme.rst -> readme.md for nspkg

* pylint fixes for nspkg

* change nspkg version

* update nspkg manifest.in

* temp add azure-ai-nspkg to dev_requirements.txt until pkg released

* update code from swagger fixes

* review updates
This commit is contained in:
Krista Pratico 2019-12-16 15:34:57 -08:00 коммит произвёл GitHub
Родитель bae787e724
Коммит 647f54445c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
269 изменённых файлов: 22185 добавлений и 3 удалений

Просмотреть файл

@ -54,6 +54,7 @@ known_content_issues:
- ['sdk/storage/azure-storage-nspkg/README.rst', '#4554']
- ['sdk/storage/README.md', '#4554']
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#4554']
- ['sdk/textanalytics/azure-ai-textanalytics/samples/README.md', '#4554']
# nspckg and common.
- ['sdk/cognitiveservices/azure-cognitiveservices-nspkg/README.rst', 'nspkg and common']
@ -76,6 +77,7 @@ known_content_issues:
- ['sdk/appconfiguration/azure-appconfiguration/README.md', 'nspkg and common']
- ['sdk/appconfiguration/azure-appconfiguration/samples/README.md', 'nspkg and common']
- ['sdk/keyvault/azure-keyvault-nspkg/README.md', 'nspkg and common']
- ['sdk/textanalytics/azure-ai-nspkg/README.md', 'nspkg and common']
# root readme
- ['README.md', 'root readme']

Просмотреть файл

@ -10,4 +10,5 @@ MYPY_HARD_FAILURE_OPTED = [
"azure-eventhub",
"azure-eventhub-checkpointstoreblob",
"azure-eventhub-checkpointstoreblob-aio",
"azure-ai-textanalytics"
]

Просмотреть файл

@ -0,0 +1,2 @@
include *.md
include azure/ai/__init__.py

Просмотреть файл

@ -0,0 +1,16 @@
# Microsoft Azure SDK for Python
This is the Microsoft Azure ai Services namespace package.
This package is not intended to be installed directly by the end user.
Since version 3.0, this is Python 2 package only, Python 3.x SDKs will use `PEP420 <https://www.python.org/dev/peps/pep-0420/>` as namespace package strategy.
To avoid issues with package servers that does not support `python_requires`, a Python 3 package is installed but is empty.
It provides the necessary files for other packages to extend the azure.ai namespace.
If you are looking to install the Azure client libraries, see the
`azure <https://pypi.python.org/pypi/azure>`__ bundle package.
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fsdk%2Ftextanalytics%2Fazure-ai-nspkg%2FREADME.png)

Просмотреть файл

@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

Просмотреть файл

@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

Просмотреть файл

@ -0,0 +1,2 @@
[packaging]
auto_update = false

Просмотреть файл

@ -0,0 +1,59 @@
#!/usr/bin/env python
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------
import sys
from setuptools import setup
# azure v0.x is not compatible with this package
# azure v0.x used to have a __version__ attribute (newer versions don't)
try:
import azure
try:
ver = azure.__version__
raise Exception(
'This package is incompatible with azure=={}. '.format(ver) +
'Uninstall it with "pip uninstall azure".'
)
except AttributeError:
pass
except ImportError:
pass
PACKAGES = []
# Do an empty package on Python 3 and not python_requires, since not everybody is ready
# https://github.com/Azure/azure-sdk-for-python/issues/3447
# https://github.com/Azure/azure-sdk-for-python/issues/3481
if sys.version_info[0] < 3:
PACKAGES = ['azure.ai']
setup(
name='azure-ai-nspkg',
version='1.0.0',
description='Microsoft Azure ai Namespace Package [Internal]',
long_description=open('README.md', 'r').read(),
license='MIT License',
author='Microsoft Corporation',
author_email='azpysdkhelp@microsoft.com',
url='https://github.com/Azure/azure-sdk-for-python',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
],
zip_safe=False,
packages=PACKAGES,
install_requires=[
'azure-nspkg>=3.0.0',
]
)

Просмотреть файл

@ -0,0 +1,116 @@
# Change Log azure-ai-textanalytics
## 2020-01-06 1.0.0b1
Version (1.0.0b1) is the first preview of our efforts to create a user-friendly and Pythonic client library for Azure Text Analytics. For more information about this, and preview releases of other Azure SDK libraries, please visit
https://azure.github.io/azure-sdk/releases/latest/python.html.
**Breaking changes: New API design**
- New namespace:
- The namespace for Azure Text Analytics client library has changed from `azure.cognitiveservices.language.textanalytics` to `azure.ai.textanalytics`
- New operations and naming:
- `detect_language` is renamed to `detect_languages`
- `entities` is renamed to `recognize_entities`
- `key_phrases` is renamed to `extract_key_phrases`
- `sentiment` is renamed to `analyze_sentiment`
- New operation `recognize_pii_entities` finds personally identifiable information entities in text
- New operation `recognize_linked_entities` provides links from a well-known knowledge base for each recognized entity
- New module-level operations `single_detect_language`, `single_recognize_entities`, `single_extract_key_phrases`, `single_analyze_sentiment`, `single_recognize_pii_entities`, and `single_recognize_linked_entities` perform
function on a single string instead of a batch of text documents and can be imported from the `azure.ai.textanalytics` namespace.
- New client and module-level async APIs added to subnamespace `azure.ai.textanalytics.aio`.
- `MultiLanguageInput` has been renamed to `TextDocumentInput`
- `LanguageInput` has been renamed to `DetectLanguageInput`
- `DocumentLanguage` has been renamed to `DetectLanguageResult`
- `DocumentEntities` has been renamed to `RecognizeEntitiesResult`
- `DocumentLinkedEntities` has been renamed to `RecognizeLinkedEntitiesResult`
- `DocumentKeyPhrases` has been renamed to `ExtractKeyPhrasesResult`
- `DocumentSentiment` has been renamed to `AnalyzeSentimentResult`
- `DocumentStatistics` has been renamed to `TextDocumentStatistics`
- `RequestStatistics` has been renamed to `TextDocumentBatchStatistics`
- `Entity` has been renamed to `NamedEntity`
- `Match` has been renamed to `LinkedEntityMatch`
- The batching methods' `documents` parameter has been renamed `inputs`
- New input types:
- `detect_languages` can take as input a `list[DetectLanguageInput]` or a `list[str]`. A list of dict-like objects in the same shape as `DetectLanguageInput` is still accepted as input.
- `recognize_entities`, `recognize_pii_entities`, `recognize_linked_entities`, `extract_key_phrases`, `analyze_sentiment` can take as input a `list[TextDocumentInput]` or `list[str]`.
A list of dict-like objects in the same shape as `TextDocumentInput` is still accepted as input.
- New parameters/keyword arguments:
- All operations now take a keyword argument `model_version` which allows the user to specify a string referencing the desired model version to be used for analysis. If no string specified, it will default to the latest, non-preview version.
- `detect_languages` now takes a parameter `country_hint` which allows you to specify the country hint for the entire batch. Any per-item country hints will take precedence over a whole batch hint.
- `recognize_entities`, `recognize_pii_entities`, `recognize_linked_entities`, `extract_key_phrases`, `analyze_sentiment` now take a parameter `language` which allows you to specify the language for the entire batch.
Any per-item specified language will take precedence over a whole batch hint.
- A `response_hook` keyword argument can be passed with a callback to use the raw response from the service. Additionally, values returned for `TextDocumentBatchStatistics` and `model_version` used must be retrieved using a response hook.
- `show_stats` and `model_version` parameters move to keyword only arguments.
- New return types
- The return types for the batching methods (`detect_languages`, `recognize_entities`, `recognize_pii_entities`, `recognize_linked_entities`, `extract_key_phrases`, `analyze_sentiment`) now return a heterogeneous list of
result objects and document errors in the order passed in with the request. To iterate over the list and filter for result or error, a boolean on each object called `is_error` can be used to determine whether the returned response object at
that index is a result or an error:
- `detect_languages` now returns a List[Union[`DetectLanguageResult`, `DocumentError`]]
- `recognize_entities` now returns a List[Union[`RecognizeEntitiesResult`, `DocumentError`]]
- `recognize_pii_entities` now returns a List[Union[`RecognizePiiEntitiesResult`, `DocumentError`]]
- `recognize_linked_entities` now returns a List[Union[`RecognizeLinkedEntitiesResult`, `DocumentError`]]
- `extract_key_phrases` now returns a List[Union[`ExtractKeyPhrasesResult`, `DocumentError`]]
- `analyze_sentiment` now returns a List[Union[`AnalyzeSentimentResult`, `DocumentError`]]
- The module-level, single text operations will return a single result object or raise the error found on the document:
- `single_detect_languages` returns a `DetectLanguageResult`
- `single_recognize_entities` returns a `RecognizeEntitiesResult`
- `single_recognize_pii_entities` returns a `RecognizePiiEntitiesResult`
- `single_recognize_linked_entities` returns a `RecognizeLinkedEntitiesResult`
- `single_extract_key_phrases` returns a `ExtractKeyPhrasesResult`
- `single_analyze_sentiment` returns a `AnalyzeSentimentResult`
- New underlying REST pipeline implementation, based on the new `azure-core` library.
- Client and pipeline configuration is now available via keyword arguments at both the client level, and per-operation. See reference documentation for a full list of optional configuration arguments.
- Authentication using `azure-identity` credentials
- see the
[Azure Identity documentation](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/identity/azure-identity/README.md)
for more information
- New error hierarchy:
- All service errors will now use the base type: `azure.core.exceptions.HttpResponseError`
- There is one exception type derived from this base type for authentication errors:
- `ClientAuthenticationError`: Authentication failed.
### 2019-03-12 0.2.0
**Features**
- Client class can be used as a context manager to keep the underlying HTTP session open for performance
- New method "entities"
- Model KeyPhraseBatchResultItem has a new parameter statistics
- Model KeyPhraseBatchResult has a new parameter statistics
- Model LanguageBatchResult has a new parameter statistics
- Model LanguageBatchResultItem has a new parameter statistics
- Model SentimentBatchResult has a new parameter statistics
**Breaking changes**
- TextAnalyticsAPI main client has been renamed TextAnalyticsClient
- TextAnalyticsClient parameter is no longer a region but a complete endpoint
**General Breaking changes**
This version uses a next-generation code generator that *might* introduce breaking changes.
- Model signatures now use only keyword-argument syntax. All positional arguments must be re-written as keyword-arguments.
To keep auto-completion in most cases, models are now generated for Python 2 and Python 3. Python 3 uses the "*" syntax for keyword-only arguments.
- Enum types now use the "str" mixin (class AzureEnum(str, Enum)) to improve the behavior when unrecognized enum values are encountered.
While this is not a breaking change, the distinctions are important, and are documented here:
https://docs.python.org/3/library/enum.html#others
At a glance:
- "is" should not be used at all.
- "format" will return the string value, where "%s" string formatting will return `NameOfEnum.stringvalue`. Format syntax should be prefered.
**Bugfixes**
- Compatibility of the sdist with wheel 0.31.0
### 2018-01-12 0.1.0
* Initial Release

Просмотреть файл

@ -0,0 +1,5 @@
recursive-include tests *.py
recursive-include samples *.py *.md
include *.md
include azure/__init__.py
include azure/ai/__init__.py

Просмотреть файл

@ -0,0 +1,370 @@
# Azure Text Analytics client library for Python
Text Analytics is a cloud-based service that provides advanced natural language processing over raw text, and includes four main functions:
* Sentiment Analysis
* Named Entity Recognition
* Language Detection
* Key Phrase Extraction
[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics) | [Package (PyPI)](https://pypi.org/project/azure-ai-textanalytics/) | [API reference documentation](https://aka.ms/azsdk-python-textanalytics-ref-docs) | [Product documentation](https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples)
## Getting started
### Prerequisites
* Python 2.7, or 3.5 or later is required to use this package.
* You must have an [Azure subscription](https://azure.microsoft.com/free/) and an
[Cognitive Services or Text Analytics account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows) to use this package.
### Install the package
Install the Azure Text Analytics client library for Python with [pip](https://pypi.org/project/pip/):
```bash
pip install azure-ai-textanalytics --pre
```
### Create a Cognitive Services or Text Analytics resource
Text Analytics supports both [multi-service and single-service access](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows). Create a Cognitive Services resource if you plan
to access multiple cognitive services under a single endpoint/key. For Text Analytics access only, create a Text Analytics resource.
You can create either resource using the
[Azure Portal](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#create-a-new-azure-cognitive-services-resource)
or [Azure CLI](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows).
Below is an example of how you can create a Text Analytics resource using the CLI:
```bash
# Create a new resource group to hold the text analytics resource -
# if using an existing resource group, skip this step
az group create --name my-resource-group --location westus2
```
```bash
# Create text analytics
az cognitiveservices account create \
--name text-analytics-resource \
--resource-group my-resource-group \
--kind TextAnalytics \
--sku F0 \
--location westus2 \
--yes
```
### Create the client
The Azure Text Analytics client library for Python allows you to engage with the Text Analytics service to
analyze sentiment, recognize entities, detect language, and extract key phrases from text.
Interaction with this service begins with an instance of a [client](#Client).
To create a client object, you will need the cognitive services or text analytics endpoint to
your resource and a credential that allows you access:
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics = TextAnalyticsClient(endpoint="https://westus2.api.cognitive.microsoft.com/", credential=credential)
```
Note that if you create a [custom subdomain](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-custom-subdomains)
for your resource the endpoint may look different than in the above code snippet.
For example, `https://<my-custom-subdomain>.cognitiveservices.azure.com/`.
#### Looking up the endpoint
You can find the endpoint for your text analytics resource using the
[Azure Portal](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#get-the-keys-for-your-resource)
or [Azure CLI](https://docs.microsoft.com/cli/azure/cognitiveservices/account?view=azure-cli-latest#az-cognitiveservices-account-show):
```bash
# Get the endpoint for the text analytics resource
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "endpoint"
```
#### Types of credentials
The `credential` parameter may be provided as the subscription key to your resource or as a token from Azure Active Directory.
See the full details regarding [authentication](https://docs.microsoft.com/azure/cognitive-services/authentication) of
cognitive services.
1. To use a [subscription key](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#get-the-keys-for-your-resource),
provide the key as a string. This can be found in the Azure Portal under the "Quickstart"
section or by running the following Azure CLI command:
```az cognitiveservices account keys list --name "resource-name" --resource-group "resource-group-name"```
Use the key as the credential parameter to authenticate the client:
```python
from azure.ai.textanalytics import TextAnalyticsClient
service = TextAnalyticsClient(endpoint="https://westus2.api.cognitive.microsoft.com/", credential="<subscription_key>")
```
2. To use an [Azure Active Directory (AAD) token credential](https://docs.microsoft.com/azure/cognitive-services/authentication#authenticate-with-azure-active-directory),
provide an instance of the desired credential type obtained from the
[azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#credentials) library.
Note that regional endpoints do not support AAD authentication. Create a [custom subdomain](https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain)
name for your resource in order to use this type of authentication.
Authentication with AAD requires some initial setup:
* [Install azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#install-the-package)
* [Register a new AAD application](https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal)
* [Grant access](https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal) to Text Analytics by assigning the `"Cognitive Services User"` role to your service principal.
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#credentials) from azure.identity to use.
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#defaultazurecredential)
can be used to authenticate the client:
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
Use the returned token credential to authenticate the client:
```python
from azure.identity import DefaultAzureCredential
from azure.ai.textanalytics import TextAnalyticsClient
token_credential = DefaultAzureCredential()
text_analytics_client = TextAnalyticsClient(
endpoint="https://<my-custom-subdomain>.cognitiveservices.azure.com/",
credential=token_credential
)
```
## Key concepts
The following are types of text analysis that the service offers:
1. [Sentiment Analysis](https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-sentiment-analysis)
Use sentiment analysis to find out what customers think of your brand or topic by analyzing raw text for clues about positive or negative sentiment.
Scores closer to `1` indicate positive sentiment, while scores closer to `0` indicate negative sentiment.
Sentiment analysis returns scores and labels at a document and sentence level.
2. [Named Entity Recognition](https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-entity-linking)
Use named entity recognition (NER) to identify different entities in text and categorize them into pre-defined classes, or types.
Entity recognition in the client library provides three different methods depending on what you are interested in.
* `recognize_entities()` can be used to identify and categorize entities in your text as people, places, organizations, date/time, quantities, percentages, currencies, and more.
* `recognize_pii_entities()` can be used to recognize personally identifiable information such as SSNs and bank account numbers.
* `recognize_linked_entities()` can be used to identify and disambiguate the identity of an entity found in text (For example, determining whether
"Mars" is being used as the planet or as the Roman god of war). This process uses Wikipedia as the knowledge base to which recognized entities are linked.
See a full list of [Named Entity Recognition Types](https://docs.microsoft.com/azure/cognitive-services/text-analytics/named-entity-types?tabs=personal).
3. [Language Detection](https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-language-detection)
Detect the language of the input text and report a single language code for every document submitted on the request.
The language code is paired with a score indicating the strength of the score.
A wide range of languages, variants, dialects, and some regional/cultural languages are supported -
see [supported languages](https://docs.microsoft.com/azure/cognitive-services/text-analytics/language-support#language-detection) for full details.
4. [Key Phrase Extraction](https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-keyword-extraction)
Extract key phrases to quickly identify the main points in text.
For example, for the input text "The food was delicious and there were wonderful staff", the main talking points returned: "food" and "wonderful staff".
See [Language and regional support](https://docs.microsoft.com/azure/cognitive-services/text-analytics/language-support) for what is currently available for each operation.
### Client
The Text Analytics client library provides a [TextAnalyticsClient](https://aka.ms/azsdk-python-textanalytics-textanalyticsclient) to do analysis on batches of documents.
A batch contains the text documents you wish to process, and may contain a per-item ID and language/country hint
if you choose. For example, a batch can simply be passed as a list of strings:
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = ["I hated the movie. It was so slow!", "The movie made it into my top ten favorites.", "What a great movie!"]
result = text_analytics_client.analyze_sentiment(documents)
```
or as a list of [DetectLanguageInput](https://aka.ms/azsdk-python-textanalytics-detectlanguageinput) or [TextDocumentInput](https://aka.ms/azsdk-python-textanalytics-textdocumentinput):
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = [
{"id": "1", "language": "en", "text": "I hated the movie. It was so slow!"},
{"id": "2", "language": "en", "text": "The movie made it into my top ten favorites."},
{"id": "3", "language": "en", "text": "What a great movie!"}
]
result = text_analytics_client.analyze_sentiment(documents)
```
The returned response will be index-matched with the order of the provided documents.
### Single text operations
The Text Analytics client library also provides module-level operations which can be performed on a single string
of text.
These operations are an introduction to the client library and have simpler inputs and outputs than
that of the batched client operations. The endpoint and credential are passed in with the desired text and
other optional parameters.
```python
from azure.ai.textanalytics import single_analyze_sentiment
text = "I did not like the restaurant. The food was too spicy."
result = single_analyze_sentiment(endpoint=endpoint, credential=credential, text_input=text, language="en")
print(result.sentiment)
```
## Examples
The following section provides several code snippets covering some of the most common Text Analytics tasks, including:
* [Analyze Sentiment](#analyze-sentient "Analyze sentiment")
* [Recognize Entities](#recognize-entities "Recognize entities")
* [Extract Key Phrases](#extract-key-phrases "Extract key phrases")
* [Detect Languages](#detect-languages "Detect languages")
### Analyze sentiment
Analyze sentiment in a batch of documents.
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = [
"I did not like the restaurant. The food was too spicy.",
"The restaurant was decorated beautifully. The atmosphere was unlike any other restaurant I've been to.",
"The food was yummy. :)"
]
result = text_analytics_client.analyze_sentiment(documents, language="en")
for text in result:
print(text.sentiment)
```
### Recognize entities
Recognize entities in a batch of documents.
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = [
"Microsoft was founded by Bill Gates and Paul Allen.",
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
"Jeff bought three dozen eggs because there was a 50% discount."
]
result = text_analytics_client.recognize_entities(documents, language="en")
for text in result:
print(text.entities)
```
### Extract key phrases
Extract key phrases in a batch of documents.
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = [
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
"I need to take my cat to the veterinarian.",
"I will travel to South America in the summer."
]
result = text_analytics_client.extract_key_phrases(documents, language="en")
for text in result:
print(text.key_phrases)
```
### Detect languages
Detect language in a batch of documents.
```python
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint, key)
documents = [
"This is written in English.",
"Il documento scritto in italiano.",
"Dies ist in englischer Sprache verfasst."
]
result = text_analytics_client.detect_languages(documents)
for text in result:
print(text.detected_languages[0].name)
```
## Optional Configuration
Optional keyword arguments that can be passed in at the client and per-operation level.
### Retry Policy configuration
Use the following keyword arguments when instantiating a client to configure the retry policy:
* __retry_total__ (int): Total number of retries to allow. Takes precedence over other counts.
Pass in `retry_total=0` if you do not want to retry on requests. Defaults to 10.
* __retry_connect__ (int): How many connection-related errors to retry on. Defaults to 3.
* __retry_read__ (int): How many times to retry on read errors. Defaults to 3.
* __retry_status__ (int): How many times to retry on bad status codes. Defaults to 3.
### Other client / per-operation configuration
Other optional configuration keyword arguments that can be specified on the client or per-operation.
**Client keyword arguments:**
* __connection_timeout__ (int): A single float in seconds for the connection timeout. Defaults to 300 seconds.
* __read_timeout__ (int): A single float in seconds for the read timeout. Defaults to 300 seconds.
* __transport__ (Any): User-provided transport to send the HTTP request.
**Per-operation keyword arguments:**
* __response_hook__ (callable): The given callback uses the raw response returned from the service.
Can also be passed in at the client.
* __request_id__ (str): Optional user specified identification of the request.
* __user_agent__ (str): Appends the custom value to the user-agent header to be sent with the request.
* __logging_enable__ (bool): Enables logging at the DEBUG level. Defaults to False. Can also be passed in at
the client level to enable it for all requests.
* __headers__ (dict): Pass in custom headers as key, value pairs. E.g. `headers={'CustomValue': value}`
## Troubleshooting
The Text Analytics client will raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md).
## Next steps
### More sample code
These code samples show common scenario operations with the Azure Text Analytics client library.
The async versions of the samples (the python sample files appended with `_async`) show asynchronous operations
with Text Analytics and require Python 3.5 or later.
Authenticate the client with a Cognitive Services/Text Analytics subscription key or a token credential from [azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity):
* [sample_authentication.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_authentication.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_authentication_async.py))
In a batch of documents:
* Detect languages: [sample_detect_languages.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_detect_languages.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_detect_languages_async.py))
* Recognize entities: [sample_recognize_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_async.py))
* Recognize linked entities: [sample_recognize_linked_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_linked_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_linked_entities_async.py))
* Recognize personally identifiable information: [sample_recognize_pii_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_pii_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_pii_entities_async.py))
* Extract key phrases: [sample_extract_key_phrases.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_async.py))
* Analyze sentiment: [sample_analyze_sentiment.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_async.py))
In a single string of text:
* Detect language: [sample_single_detect_language.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_detect_language.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_detect_language_async.py))
* Recognize entities: [sample_single_recognize_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_entities_async.py))
* Recognize linked entities: [sample_single_recognize_linked_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_linked_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_linked_entities_async.py))
* Recognize personally identifiable information: [sample_single_recognize_pii_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_pii_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_pii_entities_async.py))
* Extract key phrases: [sample_single_extract_key_phrases.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_extract_key_phrases.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_extract_key_phrases_async.py))
* Analyze sentiment: [sample_single_analyze_sentiment.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_analyze_sentiment.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_analyze_sentiment_async.py))
### Additional documentation
For more extensive documentation on Azure Cognitive Services, see the [Azure Cognitive Services documentation](https://docs.microsoft.com/azure/cognitive-services/) on docs.microsoft.com.
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

Просмотреть файл

@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore

Просмотреть файл

@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore

Просмотреть файл

@ -0,0 +1,409 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import Any, Optional # pylint: disable=unused-import
from ._text_analytics_client import TextAnalyticsClient
from ._request_handlers import _validate_single_input
from ._response_handlers import process_single_error
from ._version import VERSION
from ._models import (
DetectLanguageInput,
TextDocumentInput,
DetectedLanguage,
DocumentError,
NamedEntity,
LinkedEntity,
AnalyzeSentimentResult,
RecognizeEntitiesResult,
DetectLanguageResult,
TextAnalyticsError,
InnerError,
ExtractKeyPhrasesResult,
RecognizeLinkedEntitiesResult,
RecognizePiiEntitiesResult,
TextDocumentStatistics,
LinkedEntityMatch,
TextDocumentBatchStatistics,
SentenceSentiment,
SentimentConfidenceScorePerLabel
)
__all__ = [
'TextAnalyticsClient',
'DetectLanguageInput',
'TextDocumentInput',
'single_detect_language',
'single_recognize_entities',
'single_recognize_pii_entities',
'single_recognize_linked_entities',
'single_extract_key_phrases',
'single_analyze_sentiment',
'DetectedLanguage',
'RecognizeEntitiesResult',
'RecognizePiiEntitiesResult',
'DetectLanguageResult',
'NamedEntity',
'TextAnalyticsError',
'InnerError',
'ExtractKeyPhrasesResult',
'RecognizeLinkedEntitiesResult',
'AnalyzeSentimentResult',
'TextDocumentStatistics',
'DocumentError',
'LinkedEntity',
'LinkedEntityMatch',
'TextDocumentBatchStatistics',
'SentenceSentiment',
'SentimentConfidenceScorePerLabel'
]
__version__ = VERSION
def single_detect_language(
endpoint, # type: str
credential, # type: str
input_text, # type: str
country_hint="US", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> DetectLanguageResult
"""Detect Language for a single document.
Returns the detected language and a numeric score between zero and
one. Scores close to one indicate 100% certainty that the identified
language is true. See https://aka.ms/talangs for the list of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to detect language from.
:param str country_hint: The country hint for the text. Accepts two
letter country codes specified by ISO 3166-1 alpha-2.
Defaults to "US". If you don't want to use a country hint,
pass the empty string "".
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of DetectLanguageResult.
:rtype: ~azure.ai.textanalytics.DetectLanguageResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_detect_language.py
:start-after: [START single_detect_language]
:end-before: [END single_detect_language]
:language: python
:dedent: 8
:caption: Detecting language in a single string.
"""
doc = _validate_single_input(input_text, "country_hint", country_hint)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.detect_languages(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # DetectLanguageResult
def single_recognize_entities(
endpoint, # type: str
credential, # type: str
input_text, # type: str
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> RecognizeEntitiesResult
"""Named Entity Recognition for a single document.
Returns a list of general named entities in a given document.
For a list of supported entity types, check: https://aka.ms/taner
For a list of enabled languages, check: https://aka.ms/talangs
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizeEntitiesResult.
:rtype: ~azure.ai.textanalytics.RecognizeEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_recognize_entities.py
:start-after: [START single_recognize_entities]
:end-before: [END single_recognize_entities]
:language: python
:dedent: 8
:caption: Recognize entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.recognize_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizeEntitiesResult
def single_recognize_pii_entities(
endpoint, # type: str
credential, # type: str
input_text, # type: str
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> RecognizePiiEntitiesResult
"""Recognize entities containing personal information for a single document.
Returns a list of personal information entities ("SSN",
"Bank Account", etc) in the document. For the list of supported entity types,
check https://aka.ms/tanerpii. See https://aka.ms/talangs
for the list of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizePiiEntitiesResult.
:rtype: ~azure.ai.textanalytics.RecognizePiiEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_recognize_pii_entities.py
:start-after: [START single_recognize_pii_entities]
:end-before: [END single_recognize_pii_entities]
:language: python
:dedent: 8
:caption: Recognize personally identifiable information entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.recognize_pii_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizePiiEntitiesResult
def single_recognize_linked_entities(
endpoint, # type: str
credential, # type: str
input_text, # type: str
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> RecognizeLinkedEntitiesResult
"""Recognize linked entities from a well-known knowledge base
for a single document.
Returns a list of recognized entities with links to a
well-known knowledge base. See https://aka.ms/talangs for
supported languages in Text Analytics API.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizeLinkedEntitiesResult
:rtype: ~azure.ai.textanalytics.RecognizeLinkedEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_recognize_linked_entities.py
:start-after: [START single_recognize_linked_entities]
:end-before: [END single_recognize_linked_entities]
:language: python
:dedent: 8
:caption: Recognize linked entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.recognize_linked_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizeLinkedEntitiesResult
def single_extract_key_phrases(
endpoint, # type: str
credential, # type: str
input_text, # type: str
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> ExtractKeyPhrasesResult
"""Extract Key Phrases for a single document.
Returns a list of strings denoting the key phrases in the input
text. See https://aka.ms/talangs for the list of enabled
languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to extract key phrases from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of ExtractKeyPhrasesResult
:rtype: ~azure.ai.textanalytics.ExtractKeyPhrasesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_extract_key_phrases.py
:start-after: [START single_extract_key_phrases]
:end-before: [END single_extract_key_phrases]
:language: python
:dedent: 8
:caption: Extract key phrases in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.extract_key_phrases(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # ExtractKeyPhrasesResult
def single_analyze_sentiment(
endpoint, # type: str
credential, # type: str
input_text, # type: str
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> AnalyzeSentimentResult
"""Analyze sentiment in a single document.
Returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See https://aka.ms/talangs for the list
of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to analyze sentiment from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of AnalyzeSentimentResult
:rtype: ~azure.ai.textanalytics.AnalyzeSentimentResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_single_analyze_sentiment.py
:start-after: [START single_analyze_sentiment]
:end-before: [END single_analyze_sentiment]
:language: python
:dedent: 8
:caption: Analyze sentiment in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = client.analyze_sentiment(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # AnalyzeSentimentResult

Просмотреть файл

@ -0,0 +1,83 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import six
from azure.core.configuration import Configuration
from azure.core.pipeline import Pipeline
from azure.core.pipeline.transport import RequestsTransport
from azure.core.pipeline.policies import (
UserAgentPolicy,
HeadersPolicy,
RequestIdPolicy,
ProxyPolicy,
NetworkTraceLoggingPolicy,
RetryPolicy,
RedirectPolicy,
BearerTokenCredentialPolicy,
DistributedTracingPolicy,
HttpLoggingPolicy,
)
from ._policies import CognitiveServicesCredentialPolicy, TextAnalyticsResponseHook
from ._version import VERSION
class TextAnalyticsClientBase(object):
def __init__(self, credential, **kwargs):
self._pipeline = self._create_pipeline(credential, **kwargs)
def _create_pipeline(self, credential, **kwargs):
credential_policy = None
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
if hasattr(credential, "get_token"):
credential_policy = BearerTokenCredentialPolicy(
credential, "https://cognitiveservices.azure.com/.default"
)
elif isinstance(credential, six.string_types):
credential_policy = CognitiveServicesCredentialPolicy(credential)
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))
config = self._create_configuration(**kwargs)
config.transport = kwargs.get("transport") # type: ignore
if not config.transport:
config.transport = RequestsTransport(**kwargs)
config.user_agent_policy.add_user_agent(
"azsdk-python-azure-ai-textanalytics/{}".format(VERSION)
)
policies = [
config.headers_policy,
config.user_agent_policy,
RequestIdPolicy(**kwargs),
config.proxy_policy,
config.redirect_policy,
config.retry_policy,
credential_policy,
config.logging_policy,
TextAnalyticsResponseHook(**kwargs),
DistributedTracingPolicy(**kwargs),
HttpLoggingPolicy(**kwargs),
]
return Pipeline(config.transport, policies=policies)
def _create_configuration(self, **kwargs): # pylint: disable=no-self-use
config = Configuration(**kwargs)
config.user_agent_policy = kwargs.get("user_agent_policy") or UserAgentPolicy(**kwargs)
config.headers_policy = kwargs.get("headers_policy") or HeadersPolicy(**kwargs)
config.proxy_policy = kwargs.get("proxy_policy") or ProxyPolicy(**kwargs)
config.logging_policy = kwargs.get("logging_policy") or NetworkTraceLoggingPolicy(**kwargs)
config.retry_policy = kwargs.get("retry_policy") or RetryPolicy(**kwargs)
config.redirect_policy = kwargs.get("redirect_policy") or RedirectPolicy(**kwargs)
return config
def __enter__(self):
self._client.__enter__() # pylint:disable=no-member
return self
def __exit__(self, *args):
self._client.__exit__(*args) # pylint:disable=no-member

Просмотреть файл

@ -0,0 +1,18 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from ._text_analytics_client import TextAnalyticsClient
__all__ = ['TextAnalyticsClient']
from ._version import VERSION
__version__ = VERSION

Просмотреть файл

@ -0,0 +1,53 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core.configuration import Configuration
from azure.core.pipeline import policies
from ._version import VERSION
class TextAnalyticsClientConfiguration(Configuration):
"""Configuration for TextAnalyticsClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus.api.cognitive.microsoft.com).
:type endpoint: str
"""
def __init__(self, credentials, endpoint, **kwargs):
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
super(TextAnalyticsClientConfiguration, self).__init__(**kwargs)
self._configure(**kwargs)
self.user_agent_policy.add_user_agent('azsdk-python-azure-ai-textanalytics/{}'.format(VERSION))
self.generate_client_request_id = True
self.credentials = credentials
self.endpoint = endpoint
def _configure(self, **kwargs):
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)

Просмотреть файл

@ -0,0 +1,51 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core import PipelineClient
from msrest import Serializer, Deserializer
from ._configuration import TextAnalyticsClientConfiguration
from .operations import TextAnalyticsClientOperationsMixin
from . import models
class TextAnalyticsClient(TextAnalyticsClientOperationsMixin):
"""The Text Analytics API is a suite of text analytics web services built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction and language detection. No training data is needed to use this API; just bring your text data. This API uses advanced natural language processing techniques to deliver best in class predictions. Further documentation can be found in https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus.api.cognitive.microsoft.com).
:type endpoint: str
"""
def __init__(
self, credentials, endpoint, **kwargs):
base_url = '{Endpoint}/text/analytics/v3.0-preview.1'
self._config = TextAnalyticsClientConfiguration(credentials, endpoint, **kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = 'v3.0-preview.1'
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
def close(self):
self._client.close()
def __enter__(self):
self._client.__enter__()
return self
def __exit__(self, *exc_details):
self._client.__exit__(*exc_details)

Просмотреть файл

@ -0,0 +1,13 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
VERSION = "v3.0-preview.1"

Просмотреть файл

@ -0,0 +1,13 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from ._text_analytics_client_async import TextAnalyticsClient
__all__ = ['TextAnalyticsClient']

Просмотреть файл

@ -0,0 +1,53 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core.configuration import Configuration
from azure.core.pipeline import policies
from .._version import VERSION
class TextAnalyticsClientConfiguration(Configuration):
"""Configuration for TextAnalyticsClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus.api.cognitive.microsoft.com).
:type endpoint: str
"""
def __init__(self, credentials, endpoint, **kwargs):
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
super(TextAnalyticsClientConfiguration, self).__init__(**kwargs)
self._configure(**kwargs)
self.user_agent_policy.add_user_agent('azsdk-python-azure-ai-textanalytics/{}'.format(VERSION))
self.generate_client_request_id = True
self.credentials = credentials
self.endpoint = endpoint
def _configure(self, **kwargs):
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.AsyncRetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs)

Просмотреть файл

@ -0,0 +1,51 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core import AsyncPipelineClient
from msrest import Serializer, Deserializer
from ._configuration_async import TextAnalyticsClientConfiguration
from .operations_async import TextAnalyticsClientOperationsMixin
from .. import models
class TextAnalyticsClient(TextAnalyticsClientOperationsMixin):
"""The Text Analytics API is a suite of text analytics web services built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction and language detection. No training data is needed to use this API; just bring your text data. This API uses advanced natural language processing techniques to deliver best in class predictions. Further documentation can be found in https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus.api.cognitive.microsoft.com).
:type endpoint: str
"""
def __init__(
self, credentials, endpoint, **kwargs):
base_url = '{Endpoint}/text/analytics/v3.0-preview.1'
self._config = TextAnalyticsClientConfiguration(credentials, endpoint, **kwargs)
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = 'v3.0-preview.1'
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
async def close(self):
await self._client.close()
async def __aenter__(self):
await self._client.__aenter__()
return self
async def __aexit__(self, *exc_details):
await self._client.__aexit__(*exc_details)

Просмотреть файл

@ -0,0 +1,16 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from ._text_analytics_client_operations_async import TextAnalyticsClientOperationsMixin
__all__ = [
'TextAnalyticsClientOperationsMixin',
]

Просмотреть файл

@ -0,0 +1,451 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core.exceptions import map_error
from ... import models
import uuid
class TextAnalyticsClientOperationsMixin:
async def entities_recognition_general(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Named Entity Recognition.
The API returns a list of general named entities in a given document.
For the list of supported entity types, check <a
href="https://aka.ms/taner">Supported Entity Types in Text Analytics
API</a>. See the <a href="https://aka.ms/talangs">Supported languages
in Text Analytics API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntitiesResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntitiesResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_recognition_general.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntitiesResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_recognition_general.metadata = {'url': '/entities/recognition/general'}
async def entities_recognition_pii(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Entities containing personal information.
The API returns a list of entities with personal information (\"SSN\",
\"Bank Account\" etc) in the document. For the list of supported entity
types, check <a href="https://aka.ms/tanerpii">Supported Entity Types
in Text Analytics API</a>. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntitiesResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntitiesResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_recognition_pii.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntitiesResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_recognition_pii.metadata = {'url': '/entities/recognition/pii'}
async def entities_linking(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Linked entities from a well-known knowledge base.
The API returns a list of recognized entities with links to a
well-known knowledge base. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntityLinkingResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntityLinkingResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_linking.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntityLinkingResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_linking.metadata = {'url': '/entities/linking'}
async def key_phrases(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Key Phrases.
The API returns a list of strings denoting the key phrases in the input
text. See the <a href="https://aka.ms/talangs">Supported languages in
Text Analytics API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: KeyPhraseResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.KeyPhraseResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.key_phrases.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('KeyPhraseResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
key_phrases.metadata = {'url': '/keyPhrases'}
async def languages(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Detect Language.
The API returns the detected language and a numeric score between 0 and
1. Scores close to 1 indicate 100% certainty that the identified
language is true. See the <a href="https://aka.ms/talangs">Supported
languages in Text Analytics API</a> for the list of enabled languages.
:param documents:
:type documents: list[~azure.ai.textanalytics.models.LanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: LanguageResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.LanguageResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.LanguageBatchInput(documents=documents)
# Construct URL
url = self.languages.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'LanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('LanguageResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
languages.metadata = {'url': '/languages'}
async def sentiment(self, documents, model_version=None, show_stats=None, *, cls=None, **kwargs):
"""Sentiment.
The API returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: SentimentResponse or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.SentimentResponse
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.sentiment.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('SentimentResponse', response)
if cls:
return cls(response, deserialized, None)
return deserialized
sentiment.metadata = {'url': '/sentiment'}

Просмотреть файл

@ -0,0 +1,101 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
try:
from ._models_py3 import DetectedLanguage
from ._models_py3 import DocumentEntities
from ._models_py3 import DocumentError
from ._models_py3 import DocumentKeyPhrases
from ._models_py3 import DocumentLanguage
from ._models_py3 import DocumentLinkedEntities
from ._models_py3 import DocumentSentiment
from ._models_py3 import DocumentStatistics
from ._models_py3 import EntitiesResult
from ._models_py3 import Entity
from ._models_py3 import EntityLinkingResult
from ._models_py3 import InnerError
from ._models_py3 import KeyPhraseResult
from ._models_py3 import LanguageBatchInput
from ._models_py3 import LanguageInput
from ._models_py3 import LanguageResult
from ._models_py3 import LinkedEntity
from ._models_py3 import Match
from ._models_py3 import MultiLanguageBatchInput
from ._models_py3 import MultiLanguageInput
from ._models_py3 import RequestStatistics
from ._models_py3 import SentenceSentiment
from ._models_py3 import SentimentConfidenceScorePerLabel
from ._models_py3 import SentimentResponse
from ._models_py3 import TextAnalyticsError, TextAnalyticsErrorException
except (SyntaxError, ImportError):
from ._models import DetectedLanguage
from ._models import DocumentEntities
from ._models import DocumentError
from ._models import DocumentKeyPhrases
from ._models import DocumentLanguage
from ._models import DocumentLinkedEntities
from ._models import DocumentSentiment
from ._models import DocumentStatistics
from ._models import EntitiesResult
from ._models import Entity
from ._models import EntityLinkingResult
from ._models import InnerError
from ._models import KeyPhraseResult
from ._models import LanguageBatchInput
from ._models import LanguageInput
from ._models import LanguageResult
from ._models import LinkedEntity
from ._models import Match
from ._models import MultiLanguageBatchInput
from ._models import MultiLanguageInput
from ._models import RequestStatistics
from ._models import SentenceSentiment
from ._models import SentimentConfidenceScorePerLabel
from ._models import SentimentResponse
from ._models import TextAnalyticsError, TextAnalyticsErrorException
from ._text_analytics_client_enums import (
ErrorCodeValue,
InnerErrorCodeValue,
DocumentSentimentValue,
SentenceSentimentValue,
)
__all__ = [
'DetectedLanguage',
'DocumentEntities',
'DocumentError',
'DocumentKeyPhrases',
'DocumentLanguage',
'DocumentLinkedEntities',
'DocumentSentiment',
'DocumentStatistics',
'EntitiesResult',
'Entity',
'EntityLinkingResult',
'InnerError',
'KeyPhraseResult',
'LanguageBatchInput',
'LanguageInput',
'LanguageResult',
'LinkedEntity',
'Match',
'MultiLanguageBatchInput',
'MultiLanguageInput',
'RequestStatistics',
'SentenceSentiment',
'SentimentConfidenceScorePerLabel',
'SentimentResponse',
'TextAnalyticsError', 'TextAnalyticsErrorException',
'ErrorCodeValue',
'InnerErrorCodeValue',
'DocumentSentimentValue',
'SentenceSentimentValue',
]

Просмотреть файл

@ -0,0 +1,936 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.serialization import Model
from azure.core.exceptions import HttpResponseError
class DetectedLanguage(Model):
"""DetectedLanguage.
All required parameters must be populated in order to send to Azure.
:param name: Required. Long name of a detected language (e.g. English,
French).
:type name: str
:param iso6391_name: Required. A two letter representation of the detected
language according to the ISO 639-1 standard (e.g. en, fr).
:type iso6391_name: str
:param score: Required. A confidence score between 0 and 1. Scores close
to 1 indicate 100% certainty that the identified language is true.
:type score: float
"""
_validation = {
'name': {'required': True},
'iso6391_name': {'required': True},
'score': {'required': True},
}
_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'iso6391_name': {'key': 'iso6391Name', 'type': 'str'},
'score': {'key': 'score', 'type': 'float'},
}
def __init__(self, **kwargs):
super(DetectedLanguage, self).__init__(**kwargs)
self.name = kwargs.get('name', None)
self.iso6391_name = kwargs.get('iso6391_name', None)
self.score = kwargs.get('score', None)
class DocumentEntities(Model):
"""DocumentEntities.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param entities: Required. Recognized entities in the document.
:type entities: list[~azure.ai.textanalytics.models.Entity]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'entities': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'entities': {'key': 'entities', 'type': '[Entity]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, **kwargs):
super(DocumentEntities, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.entities = kwargs.get('entities', None)
self.statistics = kwargs.get('statistics', None)
class DocumentError(Model):
"""DocumentError.
All required parameters must be populated in order to send to Azure.
:param id: Required. Document Id.
:type id: str
:param error: Required. Document Error.
:type error: ~azure.ai.textanalytics.models.TextAnalyticsError
"""
_validation = {
'id': {'required': True},
'error': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'error': {'key': 'error', 'type': 'TextAnalyticsError'},
}
def __init__(self, **kwargs):
super(DocumentError, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.error = kwargs.get('error', None)
class DocumentKeyPhrases(Model):
"""DocumentKeyPhrases.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param key_phrases: Required. A list of representative words or phrases.
The number of key phrases returned is proportional to the number of words
in the input document.
:type key_phrases: list[str]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'key_phrases': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'key_phrases': {'key': 'keyPhrases', 'type': '[str]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, **kwargs):
super(DocumentKeyPhrases, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.key_phrases = kwargs.get('key_phrases', None)
self.statistics = kwargs.get('statistics', None)
class DocumentLanguage(Model):
"""DocumentLanguage.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param detected_languages: Required. A list of extracted languages.
:type detected_languages:
list[~azure.ai.textanalytics.models.DetectedLanguage]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'detected_languages': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'detected_languages': {'key': 'detectedLanguages', 'type': '[DetectedLanguage]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, **kwargs):
super(DocumentLanguage, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.detected_languages = kwargs.get('detected_languages', None)
self.statistics = kwargs.get('statistics', None)
class DocumentLinkedEntities(Model):
"""DocumentLinkedEntities.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param entities: Required. Recognized well-known entities in the document.
:type entities: list[~azure.ai.textanalytics.models.LinkedEntity]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'entities': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'entities': {'key': 'entities', 'type': '[LinkedEntity]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, **kwargs):
super(DocumentLinkedEntities, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.entities = kwargs.get('entities', None)
self.statistics = kwargs.get('statistics', None)
class DocumentSentiment(Model):
"""DocumentSentiment.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param sentiment: Required. Predicted sentiment for document (Negative,
Neutral, Positive, or Mixed). Possible values include: 'positive',
'neutral', 'negative', 'mixed'
:type sentiment: str or
~azure.ai.textanalytics.models.DocumentSentimentValue
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
:param document_scores: Required. Document level sentiment confidence
scores between 0 and 1 for each sentiment class.
:type document_scores:
~azure.ai.textanalytics.models.SentimentConfidenceScorePerLabel
:param sentences: Required. Sentence level sentiment analysis.
:type sentences: list[~azure.ai.textanalytics.models.SentenceSentiment]
"""
_validation = {
'id': {'required': True},
'sentiment': {'required': True},
'document_scores': {'required': True},
'sentences': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'sentiment': {'key': 'sentiment', 'type': 'DocumentSentimentValue'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
'document_scores': {'key': 'documentScores', 'type': 'SentimentConfidenceScorePerLabel'},
'sentences': {'key': 'sentences', 'type': '[SentenceSentiment]'},
}
def __init__(self, **kwargs):
super(DocumentSentiment, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.sentiment = kwargs.get('sentiment', None)
self.statistics = kwargs.get('statistics', None)
self.document_scores = kwargs.get('document_scores', None)
self.sentences = kwargs.get('sentences', None)
class DocumentStatistics(Model):
"""if showStats=true was specified in the request this field will contain
information about the document payload.
All required parameters must be populated in order to send to Azure.
:param characters_count: Required. Number of text elements recognized in
the document.
:type characters_count: int
:param transactions_count: Required. Number of transactions for the
document.
:type transactions_count: int
"""
_validation = {
'characters_count': {'required': True},
'transactions_count': {'required': True},
}
_attribute_map = {
'characters_count': {'key': 'charactersCount', 'type': 'int'},
'transactions_count': {'key': 'transactionsCount', 'type': 'int'},
}
def __init__(self, **kwargs):
super(DocumentStatistics, self).__init__(**kwargs)
self.characters_count = kwargs.get('characters_count', None)
self.transactions_count = kwargs.get('transactions_count', None)
class EntitiesResult(Model):
"""EntitiesResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentEntities]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentEntities]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, **kwargs):
super(EntitiesResult, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
self.errors = kwargs.get('errors', None)
self.statistics = kwargs.get('statistics', None)
self.model_version = kwargs.get('model_version', None)
class Entity(Model):
"""Entity.
All required parameters must be populated in order to send to Azure.
:param text: Required. Entity text as appears in the request.
:type text: str
:param type: Required. Entity type, such as Person/Location/Org/SSN etc
:type type: str
:param subtype: Entity sub type, such as Age/Year/TimeRange etc
:type subtype: str
:param offset: Required. Start position (in Unicode characters) for the
entity text.
:type offset: int
:param length: Required. Length (in Unicode characters) for the entity
text.
:type length: int
:param score: Required. Confidence score between 0 and 1 of the extracted
entity.
:type score: float
"""
_validation = {
'text': {'required': True},
'type': {'required': True},
'offset': {'required': True},
'length': {'required': True},
'score': {'required': True},
}
_attribute_map = {
'text': {'key': 'text', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'subtype': {'key': 'subtype', 'type': 'str'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
'score': {'key': 'score', 'type': 'float'},
}
def __init__(self, **kwargs):
super(Entity, self).__init__(**kwargs)
self.text = kwargs.get('text', None)
self.type = kwargs.get('type', None)
self.subtype = kwargs.get('subtype', None)
self.offset = kwargs.get('offset', None)
self.length = kwargs.get('length', None)
self.score = kwargs.get('score', None)
class EntityLinkingResult(Model):
"""EntityLinkingResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents:
list[~azure.ai.textanalytics.models.DocumentLinkedEntities]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentLinkedEntities]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, **kwargs):
super(EntityLinkingResult, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
self.errors = kwargs.get('errors', None)
self.statistics = kwargs.get('statistics', None)
self.model_version = kwargs.get('model_version', None)
class InnerError(Model):
"""InnerError.
All required parameters must be populated in order to send to Azure.
:param code: Required. Error code. Possible values include:
'invalidParameterValue', 'invalidRequestBodyFormat', 'emptyRequest',
'missingInputRecords', 'invalidDocument', 'modelVersionIncorrect',
'invalidDocumentBatch', 'unsupportedLanguageCode', 'invalidCountryHint'
:type code: str or ~azure.ai.textanalytics.models.InnerErrorCodeValue
:param message: Required. Error message.
:type message: str
:param details: Error details.
:type details: dict[str, str]
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.models.InnerError
"""
_validation = {
'code': {'required': True},
'message': {'required': True},
}
_attribute_map = {
'code': {'key': 'code', 'type': 'InnerErrorCodeValue'},
'message': {'key': 'message', 'type': 'str'},
'details': {'key': 'details', 'type': '{str}'},
'target': {'key': 'target', 'type': 'str'},
'inner_error': {'key': 'innerError', 'type': 'InnerError'},
}
def __init__(self, **kwargs):
super(InnerError, self).__init__(**kwargs)
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.details = kwargs.get('details', None)
self.target = kwargs.get('target', None)
self.inner_error = kwargs.get('inner_error', None)
class KeyPhraseResult(Model):
"""KeyPhraseResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentKeyPhrases]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentKeyPhrases]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, **kwargs):
super(KeyPhraseResult, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
self.errors = kwargs.get('errors', None)
self.statistics = kwargs.get('statistics', None)
self.model_version = kwargs.get('model_version', None)
class LanguageBatchInput(Model):
"""LanguageBatchInput.
All required parameters must be populated in order to send to Azure.
:param documents: Required.
:type documents: list[~azure.ai.textanalytics.models.LanguageInput]
"""
_validation = {
'documents': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[LanguageInput]'},
}
def __init__(self, **kwargs):
super(LanguageBatchInput, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
class LanguageInput(Model):
"""LanguageInput.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param text: Required.
:type text: str
:param country_hint:
:type country_hint: str
"""
_validation = {
'id': {'required': True},
'text': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'text': {'key': 'text', 'type': 'str'},
'country_hint': {'key': 'countryHint', 'type': 'str'},
}
def __init__(self, **kwargs):
super(LanguageInput, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.text = kwargs.get('text', None)
self.country_hint = kwargs.get('country_hint', None)
class LanguageResult(Model):
"""LanguageResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentLanguage]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentLanguage]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, **kwargs):
super(LanguageResult, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
self.errors = kwargs.get('errors', None)
self.statistics = kwargs.get('statistics', None)
self.model_version = kwargs.get('model_version', None)
class LinkedEntity(Model):
"""LinkedEntity.
All required parameters must be populated in order to send to Azure.
:param name: Required. Entity Linking formal name.
:type name: str
:param matches: Required. List of instances this entity appears in the
text.
:type matches: list[~azure.ai.textanalytics.models.Match]
:param language: Required. Language used in the data source.
:type language: str
:param id: Unique identifier of the recognized entity from the data
source.
:type id: str
:param url: Required. URL for the entity's page from the data source.
:type url: str
:param data_source: Required. Data source used to extract entity linking,
such as Wiki/Bing etc.
:type data_source: str
"""
_validation = {
'name': {'required': True},
'matches': {'required': True},
'language': {'required': True},
'url': {'required': True},
'data_source': {'required': True},
}
_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'matches': {'key': 'matches', 'type': '[Match]'},
'language': {'key': 'language', 'type': 'str'},
'id': {'key': 'id', 'type': 'str'},
'url': {'key': 'url', 'type': 'str'},
'data_source': {'key': 'dataSource', 'type': 'str'},
}
def __init__(self, **kwargs):
super(LinkedEntity, self).__init__(**kwargs)
self.name = kwargs.get('name', None)
self.matches = kwargs.get('matches', None)
self.language = kwargs.get('language', None)
self.id = kwargs.get('id', None)
self.url = kwargs.get('url', None)
self.data_source = kwargs.get('data_source', None)
class Match(Model):
"""Match.
All required parameters must be populated in order to send to Azure.
:param score: Required. If a well-known item is recognized, a decimal
number denoting the confidence level between 0 and 1 will be returned.
:type score: float
:param text: Required. Entity text as appears in the request.
:type text: str
:param offset: Required. Start position (in Unicode characters) for the
entity match text.
:type offset: int
:param length: Required. Length (in Unicode characters) for the entity
match text.
:type length: int
"""
_validation = {
'score': {'required': True},
'text': {'required': True},
'offset': {'required': True},
'length': {'required': True},
}
_attribute_map = {
'score': {'key': 'score', 'type': 'float'},
'text': {'key': 'text', 'type': 'str'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
}
def __init__(self, **kwargs):
super(Match, self).__init__(**kwargs)
self.score = kwargs.get('score', None)
self.text = kwargs.get('text', None)
self.offset = kwargs.get('offset', None)
self.length = kwargs.get('length', None)
class MultiLanguageBatchInput(Model):
"""Contains a set of input documents to be analyzed by the service.
All required parameters must be populated in order to send to Azure.
:param documents: Required. The set of documents to process as part of
this batch.
:type documents: list[~azure.ai.textanalytics.models.MultiLanguageInput]
"""
_validation = {
'documents': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[MultiLanguageInput]'},
}
def __init__(self, **kwargs):
super(MultiLanguageBatchInput, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
class MultiLanguageInput(Model):
"""Contains an input document to be analyzed by the service.
All required parameters must be populated in order to send to Azure.
:param id: Required. A unique, non-empty document identifier.
:type id: str
:param text: Required. The input text to process.
:type text: str
:param language: (Optional) This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, use "en" for English as default.
:type language: str
"""
_validation = {
'id': {'required': True},
'text': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'text': {'key': 'text', 'type': 'str'},
'language': {'key': 'language', 'type': 'str'},
}
def __init__(self, **kwargs):
super(MultiLanguageInput, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.text = kwargs.get('text', None)
self.language = kwargs.get('language', None)
class RequestStatistics(Model):
"""if showStats=true was specified in the request this field will contain
information about the request payload.
All required parameters must be populated in order to send to Azure.
:param documents_count: Required. Number of documents submitted in the
request.
:type documents_count: int
:param valid_documents_count: Required. Number of valid documents. This
excludes empty, over-size limit or non-supported languages documents.
:type valid_documents_count: int
:param erroneous_documents_count: Required. Number of invalid documents.
This includes empty, over-size limit or non-supported languages documents.
:type erroneous_documents_count: int
:param transactions_count: Required. Number of transactions for the
request.
:type transactions_count: long
"""
_validation = {
'documents_count': {'required': True},
'valid_documents_count': {'required': True},
'erroneous_documents_count': {'required': True},
'transactions_count': {'required': True},
}
_attribute_map = {
'documents_count': {'key': 'documentsCount', 'type': 'int'},
'valid_documents_count': {'key': 'validDocumentsCount', 'type': 'int'},
'erroneous_documents_count': {'key': 'erroneousDocumentsCount', 'type': 'int'},
'transactions_count': {'key': 'transactionsCount', 'type': 'long'},
}
def __init__(self, **kwargs):
super(RequestStatistics, self).__init__(**kwargs)
self.documents_count = kwargs.get('documents_count', None)
self.valid_documents_count = kwargs.get('valid_documents_count', None)
self.erroneous_documents_count = kwargs.get('erroneous_documents_count', None)
self.transactions_count = kwargs.get('transactions_count', None)
class SentenceSentiment(Model):
"""SentenceSentiment.
All required parameters must be populated in order to send to Azure.
:param sentiment: Required. The predicted Sentiment for the sentence.
Possible values include: 'positive', 'neutral', 'negative'
:type sentiment: str or
~azure.ai.textanalytics.models.SentenceSentimentValue
:param sentence_scores: Required. The sentiment confidence score between 0
and 1 for the sentence for all classes.
:type sentence_scores:
~azure.ai.textanalytics.models.SentimentConfidenceScorePerLabel
:param offset: Required. The sentence offset from the start of the
document.
:type offset: int
:param length: Required. The length of the sentence by Unicode standard.
:type length: int
:param warnings: The warnings generated for the sentence.
:type warnings: list[str]
"""
_validation = {
'sentiment': {'required': True},
'sentence_scores': {'required': True},
'offset': {'required': True},
'length': {'required': True},
}
_attribute_map = {
'sentiment': {'key': 'sentiment', 'type': 'SentenceSentimentValue'},
'sentence_scores': {'key': 'sentenceScores', 'type': 'SentimentConfidenceScorePerLabel'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
'warnings': {'key': 'warnings', 'type': '[str]'},
}
def __init__(self, **kwargs):
super(SentenceSentiment, self).__init__(**kwargs)
self.sentiment = kwargs.get('sentiment', None)
self.sentence_scores = kwargs.get('sentence_scores', None)
self.offset = kwargs.get('offset', None)
self.length = kwargs.get('length', None)
self.warnings = kwargs.get('warnings', None)
class SentimentConfidenceScorePerLabel(Model):
"""Represents the confidence scores between 0 and 1 across all sentiment
classes: positive, neutral, negative.
All required parameters must be populated in order to send to Azure.
:param positive: Required.
:type positive: float
:param neutral: Required.
:type neutral: float
:param negative: Required.
:type negative: float
"""
_validation = {
'positive': {'required': True},
'neutral': {'required': True},
'negative': {'required': True},
}
_attribute_map = {
'positive': {'key': 'positive', 'type': 'float'},
'neutral': {'key': 'neutral', 'type': 'float'},
'negative': {'key': 'negative', 'type': 'float'},
}
def __init__(self, **kwargs):
super(SentimentConfidenceScorePerLabel, self).__init__(**kwargs)
self.positive = kwargs.get('positive', None)
self.neutral = kwargs.get('neutral', None)
self.negative = kwargs.get('negative', None)
class SentimentResponse(Model):
"""SentimentResponse.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Sentiment analysis per document.
:type documents: list[~azure.ai.textanalytics.models.DocumentSentiment]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentSentiment]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, **kwargs):
super(SentimentResponse, self).__init__(**kwargs)
self.documents = kwargs.get('documents', None)
self.errors = kwargs.get('errors', None)
self.statistics = kwargs.get('statistics', None)
self.model_version = kwargs.get('model_version', None)
class TextAnalyticsError(Model):
"""TextAnalyticsError.
All required parameters must be populated in order to send to Azure.
:param code: Required. Error code. Possible values include:
'invalidRequest', 'invalidArgument', 'internalServerError',
'serviceUnavailable'
:type code: str or ~azure.ai.textanalytics.models.ErrorCodeValue
:param message: Required. Error message.
:type message: str
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.models.InnerError
:param details: Details about specific errors that led to this reported
error.
:type details: list[~azure.ai.textanalytics.models.TextAnalyticsError]
"""
_validation = {
'code': {'required': True},
'message': {'required': True},
}
_attribute_map = {
'code': {'key': 'code', 'type': 'ErrorCodeValue'},
'message': {'key': 'message', 'type': 'str'},
'target': {'key': 'target', 'type': 'str'},
'inner_error': {'key': 'innerError', 'type': 'InnerError'},
'details': {'key': 'details', 'type': '[TextAnalyticsError]'},
}
def __init__(self, **kwargs):
super(TextAnalyticsError, self).__init__(**kwargs)
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.target = kwargs.get('target', None)
self.inner_error = kwargs.get('inner_error', None)
self.details = kwargs.get('details', None)
class TextAnalyticsErrorException(HttpResponseError):
"""Server responsed with exception of type: 'TextAnalyticsError'.
:param deserialize: A deserializer
:param response: Server response to be deserialized.
"""
def __init__(self, response, deserialize, *args):
model_name = 'TextAnalyticsError'
self.error = deserialize(model_name, response)
if self.error is None:
self.error = deserialize.dependencies[model_name]()
super(TextAnalyticsErrorException, self).__init__(response=response)

Просмотреть файл

@ -0,0 +1,936 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.serialization import Model
from azure.core.exceptions import HttpResponseError
class DetectedLanguage(Model):
"""DetectedLanguage.
All required parameters must be populated in order to send to Azure.
:param name: Required. Long name of a detected language (e.g. English,
French).
:type name: str
:param iso6391_name: Required. A two letter representation of the detected
language according to the ISO 639-1 standard (e.g. en, fr).
:type iso6391_name: str
:param score: Required. A confidence score between 0 and 1. Scores close
to 1 indicate 100% certainty that the identified language is true.
:type score: float
"""
_validation = {
'name': {'required': True},
'iso6391_name': {'required': True},
'score': {'required': True},
}
_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'iso6391_name': {'key': 'iso6391Name', 'type': 'str'},
'score': {'key': 'score', 'type': 'float'},
}
def __init__(self, *, name: str, iso6391_name: str, score: float, **kwargs) -> None:
super(DetectedLanguage, self).__init__(**kwargs)
self.name = name
self.iso6391_name = iso6391_name
self.score = score
class DocumentEntities(Model):
"""DocumentEntities.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param entities: Required. Recognized entities in the document.
:type entities: list[~azure.ai.textanalytics.models.Entity]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'entities': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'entities': {'key': 'entities', 'type': '[Entity]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, *, id: str, entities, statistics=None, **kwargs) -> None:
super(DocumentEntities, self).__init__(**kwargs)
self.id = id
self.entities = entities
self.statistics = statistics
class DocumentError(Model):
"""DocumentError.
All required parameters must be populated in order to send to Azure.
:param id: Required. Document Id.
:type id: str
:param error: Required. Document Error.
:type error: ~azure.ai.textanalytics.models.TextAnalyticsError
"""
_validation = {
'id': {'required': True},
'error': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'error': {'key': 'error', 'type': 'TextAnalyticsError'},
}
def __init__(self, *, id: str, error, **kwargs) -> None:
super(DocumentError, self).__init__(**kwargs)
self.id = id
self.error = error
class DocumentKeyPhrases(Model):
"""DocumentKeyPhrases.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param key_phrases: Required. A list of representative words or phrases.
The number of key phrases returned is proportional to the number of words
in the input document.
:type key_phrases: list[str]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'key_phrases': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'key_phrases': {'key': 'keyPhrases', 'type': '[str]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, *, id: str, key_phrases, statistics=None, **kwargs) -> None:
super(DocumentKeyPhrases, self).__init__(**kwargs)
self.id = id
self.key_phrases = key_phrases
self.statistics = statistics
class DocumentLanguage(Model):
"""DocumentLanguage.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param detected_languages: Required. A list of extracted languages.
:type detected_languages:
list[~azure.ai.textanalytics.models.DetectedLanguage]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'detected_languages': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'detected_languages': {'key': 'detectedLanguages', 'type': '[DetectedLanguage]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, *, id: str, detected_languages, statistics=None, **kwargs) -> None:
super(DocumentLanguage, self).__init__(**kwargs)
self.id = id
self.detected_languages = detected_languages
self.statistics = statistics
class DocumentLinkedEntities(Model):
"""DocumentLinkedEntities.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param entities: Required. Recognized well-known entities in the document.
:type entities: list[~azure.ai.textanalytics.models.LinkedEntity]
:param statistics: if showStats=true was specified in the request this
field will contain information about the document payload.
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
"""
_validation = {
'id': {'required': True},
'entities': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'entities': {'key': 'entities', 'type': '[LinkedEntity]'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
}
def __init__(self, *, id: str, entities, statistics=None, **kwargs) -> None:
super(DocumentLinkedEntities, self).__init__(**kwargs)
self.id = id
self.entities = entities
self.statistics = statistics
class DocumentSentiment(Model):
"""DocumentSentiment.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param sentiment: Required. Predicted sentiment for document (Negative,
Neutral, Positive, or Mixed). Possible values include: 'positive',
'neutral', 'negative', 'mixed'
:type sentiment: str or
~azure.ai.textanalytics.models.DocumentSentimentValue
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.DocumentStatistics
:param document_scores: Required. Document level sentiment confidence
scores between 0 and 1 for each sentiment class.
:type document_scores:
~azure.ai.textanalytics.models.SentimentConfidenceScorePerLabel
:param sentences: Required. Sentence level sentiment analysis.
:type sentences: list[~azure.ai.textanalytics.models.SentenceSentiment]
"""
_validation = {
'id': {'required': True},
'sentiment': {'required': True},
'document_scores': {'required': True},
'sentences': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'sentiment': {'key': 'sentiment', 'type': 'DocumentSentimentValue'},
'statistics': {'key': 'statistics', 'type': 'DocumentStatistics'},
'document_scores': {'key': 'documentScores', 'type': 'SentimentConfidenceScorePerLabel'},
'sentences': {'key': 'sentences', 'type': '[SentenceSentiment]'},
}
def __init__(self, *, id: str, sentiment, document_scores, sentences, statistics=None, **kwargs) -> None:
super(DocumentSentiment, self).__init__(**kwargs)
self.id = id
self.sentiment = sentiment
self.statistics = statistics
self.document_scores = document_scores
self.sentences = sentences
class DocumentStatistics(Model):
"""if showStats=true was specified in the request this field will contain
information about the document payload.
All required parameters must be populated in order to send to Azure.
:param characters_count: Required. Number of text elements recognized in
the document.
:type characters_count: int
:param transactions_count: Required. Number of transactions for the
document.
:type transactions_count: int
"""
_validation = {
'characters_count': {'required': True},
'transactions_count': {'required': True},
}
_attribute_map = {
'characters_count': {'key': 'charactersCount', 'type': 'int'},
'transactions_count': {'key': 'transactionsCount', 'type': 'int'},
}
def __init__(self, *, characters_count: int, transactions_count: int, **kwargs) -> None:
super(DocumentStatistics, self).__init__(**kwargs)
self.characters_count = characters_count
self.transactions_count = transactions_count
class EntitiesResult(Model):
"""EntitiesResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentEntities]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentEntities]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, *, documents, errors, model_version: str, statistics=None, **kwargs) -> None:
super(EntitiesResult, self).__init__(**kwargs)
self.documents = documents
self.errors = errors
self.statistics = statistics
self.model_version = model_version
class Entity(Model):
"""Entity.
All required parameters must be populated in order to send to Azure.
:param text: Required. Entity text as appears in the request.
:type text: str
:param type: Required. Entity type, such as Person/Location/Org/SSN etc
:type type: str
:param subtype: Entity sub type, such as Age/Year/TimeRange etc
:type subtype: str
:param offset: Required. Start position (in Unicode characters) for the
entity text.
:type offset: int
:param length: Required. Length (in Unicode characters) for the entity
text.
:type length: int
:param score: Required. Confidence score between 0 and 1 of the extracted
entity.
:type score: float
"""
_validation = {
'text': {'required': True},
'type': {'required': True},
'offset': {'required': True},
'length': {'required': True},
'score': {'required': True},
}
_attribute_map = {
'text': {'key': 'text', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'subtype': {'key': 'subtype', 'type': 'str'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
'score': {'key': 'score', 'type': 'float'},
}
def __init__(self, *, text: str, type: str, offset: int, length: int, score: float, subtype: str=None, **kwargs) -> None:
super(Entity, self).__init__(**kwargs)
self.text = text
self.type = type
self.subtype = subtype
self.offset = offset
self.length = length
self.score = score
class EntityLinkingResult(Model):
"""EntityLinkingResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents:
list[~azure.ai.textanalytics.models.DocumentLinkedEntities]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentLinkedEntities]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, *, documents, errors, model_version: str, statistics=None, **kwargs) -> None:
super(EntityLinkingResult, self).__init__(**kwargs)
self.documents = documents
self.errors = errors
self.statistics = statistics
self.model_version = model_version
class InnerError(Model):
"""InnerError.
All required parameters must be populated in order to send to Azure.
:param code: Required. Error code. Possible values include:
'invalidParameterValue', 'invalidRequestBodyFormat', 'emptyRequest',
'missingInputRecords', 'invalidDocument', 'modelVersionIncorrect',
'invalidDocumentBatch', 'unsupportedLanguageCode', 'invalidCountryHint'
:type code: str or ~azure.ai.textanalytics.models.InnerErrorCodeValue
:param message: Required. Error message.
:type message: str
:param details: Error details.
:type details: dict[str, str]
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.models.InnerError
"""
_validation = {
'code': {'required': True},
'message': {'required': True},
}
_attribute_map = {
'code': {'key': 'code', 'type': 'InnerErrorCodeValue'},
'message': {'key': 'message', 'type': 'str'},
'details': {'key': 'details', 'type': '{str}'},
'target': {'key': 'target', 'type': 'str'},
'inner_error': {'key': 'innerError', 'type': 'InnerError'},
}
def __init__(self, *, code, message: str, details=None, target: str=None, inner_error=None, **kwargs) -> None:
super(InnerError, self).__init__(**kwargs)
self.code = code
self.message = message
self.details = details
self.target = target
self.inner_error = inner_error
class KeyPhraseResult(Model):
"""KeyPhraseResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentKeyPhrases]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentKeyPhrases]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, *, documents, errors, model_version: str, statistics=None, **kwargs) -> None:
super(KeyPhraseResult, self).__init__(**kwargs)
self.documents = documents
self.errors = errors
self.statistics = statistics
self.model_version = model_version
class LanguageBatchInput(Model):
"""LanguageBatchInput.
All required parameters must be populated in order to send to Azure.
:param documents: Required.
:type documents: list[~azure.ai.textanalytics.models.LanguageInput]
"""
_validation = {
'documents': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[LanguageInput]'},
}
def __init__(self, *, documents, **kwargs) -> None:
super(LanguageBatchInput, self).__init__(**kwargs)
self.documents = documents
class LanguageInput(Model):
"""LanguageInput.
All required parameters must be populated in order to send to Azure.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param text: Required.
:type text: str
:param country_hint:
:type country_hint: str
"""
_validation = {
'id': {'required': True},
'text': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'text': {'key': 'text', 'type': 'str'},
'country_hint': {'key': 'countryHint', 'type': 'str'},
}
def __init__(self, *, id: str, text: str, country_hint: str=None, **kwargs) -> None:
super(LanguageInput, self).__init__(**kwargs)
self.id = id
self.text = text
self.country_hint = country_hint
class LanguageResult(Model):
"""LanguageResult.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Response by document
:type documents: list[~azure.ai.textanalytics.models.DocumentLanguage]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentLanguage]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, *, documents, errors, model_version: str, statistics=None, **kwargs) -> None:
super(LanguageResult, self).__init__(**kwargs)
self.documents = documents
self.errors = errors
self.statistics = statistics
self.model_version = model_version
class LinkedEntity(Model):
"""LinkedEntity.
All required parameters must be populated in order to send to Azure.
:param name: Required. Entity Linking formal name.
:type name: str
:param matches: Required. List of instances this entity appears in the
text.
:type matches: list[~azure.ai.textanalytics.models.Match]
:param language: Required. Language used in the data source.
:type language: str
:param id: Unique identifier of the recognized entity from the data
source.
:type id: str
:param url: Required. URL for the entity's page from the data source.
:type url: str
:param data_source: Required. Data source used to extract entity linking,
such as Wiki/Bing etc.
:type data_source: str
"""
_validation = {
'name': {'required': True},
'matches': {'required': True},
'language': {'required': True},
'url': {'required': True},
'data_source': {'required': True},
}
_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'matches': {'key': 'matches', 'type': '[Match]'},
'language': {'key': 'language', 'type': 'str'},
'id': {'key': 'id', 'type': 'str'},
'url': {'key': 'url', 'type': 'str'},
'data_source': {'key': 'dataSource', 'type': 'str'},
}
def __init__(self, *, name: str, matches, language: str, url: str, data_source: str, id: str=None, **kwargs) -> None:
super(LinkedEntity, self).__init__(**kwargs)
self.name = name
self.matches = matches
self.language = language
self.id = id
self.url = url
self.data_source = data_source
class Match(Model):
"""Match.
All required parameters must be populated in order to send to Azure.
:param score: Required. If a well-known item is recognized, a decimal
number denoting the confidence level between 0 and 1 will be returned.
:type score: float
:param text: Required. Entity text as appears in the request.
:type text: str
:param offset: Required. Start position (in Unicode characters) for the
entity match text.
:type offset: int
:param length: Required. Length (in Unicode characters) for the entity
match text.
:type length: int
"""
_validation = {
'score': {'required': True},
'text': {'required': True},
'offset': {'required': True},
'length': {'required': True},
}
_attribute_map = {
'score': {'key': 'score', 'type': 'float'},
'text': {'key': 'text', 'type': 'str'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
}
def __init__(self, *, score: float, text: str, offset: int, length: int, **kwargs) -> None:
super(Match, self).__init__(**kwargs)
self.score = score
self.text = text
self.offset = offset
self.length = length
class MultiLanguageBatchInput(Model):
"""Contains a set of input documents to be analyzed by the service.
All required parameters must be populated in order to send to Azure.
:param documents: Required. The set of documents to process as part of
this batch.
:type documents: list[~azure.ai.textanalytics.models.MultiLanguageInput]
"""
_validation = {
'documents': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[MultiLanguageInput]'},
}
def __init__(self, *, documents, **kwargs) -> None:
super(MultiLanguageBatchInput, self).__init__(**kwargs)
self.documents = documents
class MultiLanguageInput(Model):
"""Contains an input document to be analyzed by the service.
All required parameters must be populated in order to send to Azure.
:param id: Required. A unique, non-empty document identifier.
:type id: str
:param text: Required. The input text to process.
:type text: str
:param language: (Optional) This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, use "en" for English as default.
:type language: str
"""
_validation = {
'id': {'required': True},
'text': {'required': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'text': {'key': 'text', 'type': 'str'},
'language': {'key': 'language', 'type': 'str'},
}
def __init__(self, *, id: str, text: str, language: str=None, **kwargs) -> None:
super(MultiLanguageInput, self).__init__(**kwargs)
self.id = id
self.text = text
self.language = language
class RequestStatistics(Model):
"""if showStats=true was specified in the request this field will contain
information about the request payload.
All required parameters must be populated in order to send to Azure.
:param documents_count: Required. Number of documents submitted in the
request.
:type documents_count: int
:param valid_documents_count: Required. Number of valid documents. This
excludes empty, over-size limit or non-supported languages documents.
:type valid_documents_count: int
:param erroneous_documents_count: Required. Number of invalid documents.
This includes empty, over-size limit or non-supported languages documents.
:type erroneous_documents_count: int
:param transactions_count: Required. Number of transactions for the
request.
:type transactions_count: long
"""
_validation = {
'documents_count': {'required': True},
'valid_documents_count': {'required': True},
'erroneous_documents_count': {'required': True},
'transactions_count': {'required': True},
}
_attribute_map = {
'documents_count': {'key': 'documentsCount', 'type': 'int'},
'valid_documents_count': {'key': 'validDocumentsCount', 'type': 'int'},
'erroneous_documents_count': {'key': 'erroneousDocumentsCount', 'type': 'int'},
'transactions_count': {'key': 'transactionsCount', 'type': 'long'},
}
def __init__(self, *, documents_count: int, valid_documents_count: int, erroneous_documents_count: int, transactions_count: int, **kwargs) -> None:
super(RequestStatistics, self).__init__(**kwargs)
self.documents_count = documents_count
self.valid_documents_count = valid_documents_count
self.erroneous_documents_count = erroneous_documents_count
self.transactions_count = transactions_count
class SentenceSentiment(Model):
"""SentenceSentiment.
All required parameters must be populated in order to send to Azure.
:param sentiment: Required. The predicted Sentiment for the sentence.
Possible values include: 'positive', 'neutral', 'negative'
:type sentiment: str or
~azure.ai.textanalytics.models.SentenceSentimentValue
:param sentence_scores: Required. The sentiment confidence score between 0
and 1 for the sentence for all classes.
:type sentence_scores:
~azure.ai.textanalytics.models.SentimentConfidenceScorePerLabel
:param offset: Required. The sentence offset from the start of the
document.
:type offset: int
:param length: Required. The length of the sentence by Unicode standard.
:type length: int
:param warnings: The warnings generated for the sentence.
:type warnings: list[str]
"""
_validation = {
'sentiment': {'required': True},
'sentence_scores': {'required': True},
'offset': {'required': True},
'length': {'required': True},
}
_attribute_map = {
'sentiment': {'key': 'sentiment', 'type': 'SentenceSentimentValue'},
'sentence_scores': {'key': 'sentenceScores', 'type': 'SentimentConfidenceScorePerLabel'},
'offset': {'key': 'offset', 'type': 'int'},
'length': {'key': 'length', 'type': 'int'},
'warnings': {'key': 'warnings', 'type': '[str]'},
}
def __init__(self, *, sentiment, sentence_scores, offset: int, length: int, warnings=None, **kwargs) -> None:
super(SentenceSentiment, self).__init__(**kwargs)
self.sentiment = sentiment
self.sentence_scores = sentence_scores
self.offset = offset
self.length = length
self.warnings = warnings
class SentimentConfidenceScorePerLabel(Model):
"""Represents the confidence scores between 0 and 1 across all sentiment
classes: positive, neutral, negative.
All required parameters must be populated in order to send to Azure.
:param positive: Required.
:type positive: float
:param neutral: Required.
:type neutral: float
:param negative: Required.
:type negative: float
"""
_validation = {
'positive': {'required': True},
'neutral': {'required': True},
'negative': {'required': True},
}
_attribute_map = {
'positive': {'key': 'positive', 'type': 'float'},
'neutral': {'key': 'neutral', 'type': 'float'},
'negative': {'key': 'negative', 'type': 'float'},
}
def __init__(self, *, positive: float, neutral: float, negative: float, **kwargs) -> None:
super(SentimentConfidenceScorePerLabel, self).__init__(**kwargs)
self.positive = positive
self.neutral = neutral
self.negative = negative
class SentimentResponse(Model):
"""SentimentResponse.
All required parameters must be populated in order to send to Azure.
:param documents: Required. Sentiment analysis per document.
:type documents: list[~azure.ai.textanalytics.models.DocumentSentiment]
:param errors: Required. Errors by document id.
:type errors: list[~azure.ai.textanalytics.models.DocumentError]
:param statistics:
:type statistics: ~azure.ai.textanalytics.models.RequestStatistics
:param model_version: Required. This field indicates which model is used
for scoring.
:type model_version: str
"""
_validation = {
'documents': {'required': True},
'errors': {'required': True},
'model_version': {'required': True},
}
_attribute_map = {
'documents': {'key': 'documents', 'type': '[DocumentSentiment]'},
'errors': {'key': 'errors', 'type': '[DocumentError]'},
'statistics': {'key': 'statistics', 'type': 'RequestStatistics'},
'model_version': {'key': 'modelVersion', 'type': 'str'},
}
def __init__(self, *, documents, errors, model_version: str, statistics=None, **kwargs) -> None:
super(SentimentResponse, self).__init__(**kwargs)
self.documents = documents
self.errors = errors
self.statistics = statistics
self.model_version = model_version
class TextAnalyticsError(Model):
"""TextAnalyticsError.
All required parameters must be populated in order to send to Azure.
:param code: Required. Error code. Possible values include:
'invalidRequest', 'invalidArgument', 'internalServerError',
'serviceUnavailable'
:type code: str or ~azure.ai.textanalytics.models.ErrorCodeValue
:param message: Required. Error message.
:type message: str
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.models.InnerError
:param details: Details about specific errors that led to this reported
error.
:type details: list[~azure.ai.textanalytics.models.TextAnalyticsError]
"""
_validation = {
'code': {'required': True},
'message': {'required': True},
}
_attribute_map = {
'code': {'key': 'code', 'type': 'ErrorCodeValue'},
'message': {'key': 'message', 'type': 'str'},
'target': {'key': 'target', 'type': 'str'},
'inner_error': {'key': 'innerError', 'type': 'InnerError'},
'details': {'key': 'details', 'type': '[TextAnalyticsError]'},
}
def __init__(self, *, code, message: str, target: str=None, inner_error=None, details=None, **kwargs) -> None:
super(TextAnalyticsError, self).__init__(**kwargs)
self.code = code
self.message = message
self.target = target
self.inner_error = inner_error
self.details = details
class TextAnalyticsErrorException(HttpResponseError):
"""Server responsed with exception of type: 'TextAnalyticsError'.
:param deserialize: A deserializer
:param response: Server response to be deserialized.
"""
def __init__(self, response, deserialize, *args):
model_name = 'TextAnalyticsError'
self.error = deserialize(model_name, response)
if self.error is None:
self.error = deserialize.dependencies[model_name]()
super(TextAnalyticsErrorException, self).__init__(response=response)

Просмотреть файл

@ -0,0 +1,48 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from enum import Enum
class ErrorCodeValue(str, Enum):
invalid_request = "invalidRequest"
invalid_argument = "invalidArgument"
internal_server_error = "internalServerError"
service_unavailable = "serviceUnavailable"
class InnerErrorCodeValue(str, Enum):
invalid_parameter_value = "invalidParameterValue"
invalid_request_body_format = "invalidRequestBodyFormat"
empty_request = "emptyRequest"
missing_input_records = "missingInputRecords"
invalid_document = "invalidDocument"
model_version_incorrect = "modelVersionIncorrect"
invalid_document_batch = "invalidDocumentBatch"
unsupported_language_code = "unsupportedLanguageCode"
invalid_country_hint = "invalidCountryHint"
class DocumentSentimentValue(str, Enum):
positive = "positive"
neutral = "neutral"
negative = "negative"
mixed = "mixed"
class SentenceSentimentValue(str, Enum):
positive = "positive"
neutral = "neutral"
negative = "negative"

Просмотреть файл

@ -0,0 +1,16 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from ._text_analytics_client_operations import TextAnalyticsClientOperationsMixin
__all__ = [
'TextAnalyticsClientOperationsMixin',
]

Просмотреть файл

@ -0,0 +1,451 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from azure.core.exceptions import map_error
from .. import models
import uuid
class TextAnalyticsClientOperationsMixin(object):
def entities_recognition_general(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Named Entity Recognition.
The API returns a list of general named entities in a given document.
For the list of supported entity types, check <a
href="https://aka.ms/taner">Supported Entity Types in Text Analytics
API</a>. See the <a href="https://aka.ms/talangs">Supported languages
in Text Analytics API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntitiesResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntitiesResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_recognition_general.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntitiesResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_recognition_general.metadata = {'url': '/entities/recognition/general'}
def entities_recognition_pii(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Entities containing personal information.
The API returns a list of entities with personal information (\"SSN\",
\"Bank Account\" etc) in the document. For the list of supported entity
types, check <a href="https://aka.ms/tanerpii">Supported Entity Types
in Text Analytics API</a>. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntitiesResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntitiesResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_recognition_pii.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntitiesResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_recognition_pii.metadata = {'url': '/entities/recognition/pii'}
def entities_linking(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Linked entities from a well-known knowledge base.
The API returns a list of recognized entities with links to a
well-known knowledge base. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: EntityLinkingResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.EntityLinkingResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.entities_linking.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('EntityLinkingResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
entities_linking.metadata = {'url': '/entities/linking'}
def key_phrases(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Key Phrases.
The API returns a list of strings denoting the key phrases in the input
text. See the <a href="https://aka.ms/talangs">Supported languages in
Text Analytics API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: KeyPhraseResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.KeyPhraseResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.key_phrases.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('KeyPhraseResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
key_phrases.metadata = {'url': '/keyPhrases'}
def languages(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Detect Language.
The API returns the detected language and a numeric score between 0 and
1. Scores close to 1 indicate 100% certainty that the identified
language is true. See the <a href="https://aka.ms/talangs">Supported
languages in Text Analytics API</a> for the list of enabled languages.
:param documents:
:type documents: list[~azure.ai.textanalytics.models.LanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: LanguageResult or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.LanguageResult
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.LanguageBatchInput(documents=documents)
# Construct URL
url = self.languages.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'LanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('LanguageResult', response)
if cls:
return cls(response, deserialized, None)
return deserialized
languages.metadata = {'url': '/languages'}
def sentiment(self, documents, model_version=None, show_stats=None, cls=None, **kwargs):
"""Sentiment.
The API returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See the <a
href="https://aka.ms/talangs">Supported languages in Text Analytics
API</a> for the list of enabled languages.
:param documents: The set of documents to process as part of this
batch.
:type documents:
list[~azure.ai.textanalytics.models.MultiLanguageInput]
:param model_version: (Optional) This value indicates which model will
be used for scoring. If a model-version is not specified, the API
should default to the latest, non-preview version.
:type model_version: str
:param show_stats: (Optional) if set to true, response will contain
input and document level statistics.
:type show_stats: bool
:param callable cls: A custom type or function that will be passed the
direct response
:return: SentimentResponse or the result of cls(response)
:rtype: ~azure.ai.textanalytics.models.SentimentResponse
:raises:
:class:`TextAnalyticsErrorException<azure.ai.textanalytics.models.TextAnalyticsErrorException>`
"""
error_map = kwargs.pop('error_map', None)
input = models.MultiLanguageBatchInput(documents=documents)
# Construct URL
url = self.sentiment.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
if model_version is not None:
query_parameters['model-version'] = self._serialize.query("model_version", model_version, 'str')
if show_stats is not None:
query_parameters['showStats'] = self._serialize.query("show_stats", show_stats, 'bool')
# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if self._config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
# Construct body
body_content = self._serialize.body(input, 'MultiLanguageBatchInput')
# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.TextAnalyticsErrorException(response, self._deserialize)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('SentimentResponse', response)
if cls:
return cls(response, deserialized, None)
return deserialized
sentiment.metadata = {'url': '/sentiment'}

Просмотреть файл

@ -0,0 +1,610 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from ._generated.models._models import LanguageInput
from ._generated.models._models import MultiLanguageInput
class DictMixin(object):
def __setitem__(self, key, item):
self.__dict__[key] = item
def __getitem__(self, key):
return self.__dict__[key]
def __repr__(self):
return str(self)
def __len__(self):
return len(self.keys())
def __delitem__(self, key):
self.__dict__[key] = None
def __eq__(self, other):
"""Compare objects by comparing all attributes."""
if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__
return False
def __ne__(self, other):
"""Compare objects by comparing all attributes."""
return not self.__eq__(other)
def __str__(self):
return str({k: v for k, v in self.__dict__.items() if not k.startswith('_')})
def has_key(self, k):
return k in self.__dict__
def update(self, *args, **kwargs):
return self.__dict__.update(*args, **kwargs)
def keys(self):
return [k for k in self.__dict__ if not k.startswith('_')]
def values(self):
return [v for k, v in self.__dict__.items() if not k.startswith('_')]
def items(self):
return [(k, v) for k, v in self.__dict__.items() if not k.startswith('_')]
def get(self, key, default=None):
if key in self.__dict__:
return self.__dict__[key]
return default
class DetectedLanguage(DictMixin):
"""DetectedLanguage.
:param name: Long name of a detected language (e.g. English,
French).
:type name: str
:param iso6391_name: A two letter representation of the detected
language according to the ISO 639-1 standard (e.g. en, fr).
:type iso6391_name: str
:param score: A confidence score between 0 and 1. Scores close
to 1 indicate 100% certainty that the identified language is true.
:type score: float
"""
def __init__(self, **kwargs):
self.name = kwargs.get("name", None)
self.iso6391_name = kwargs.get("iso6391_name", None)
self.score = kwargs.get("score", None)
@classmethod
def _from_generated(cls, language):
return cls(
name=language.name, iso6391_name=language.iso6391_name, score=language.score
)
class RecognizeEntitiesResult(DictMixin):
"""RecognizeEntitiesResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param entities: Recognized entities in the document.
:type entities:
list[~azure.ai.textanalytics.NamedEntity]
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a RecognizeEntitiesResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.entities = kwargs.get("entities", None)
self.statistics = kwargs.get("statistics", None)
self.is_error = False
class RecognizePiiEntitiesResult(DictMixin):
"""RecognizePiiEntitiesResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param entities: Recognized entities in the document.
:type entities:
list[~azure.ai.textanalytics.NamedEntity]
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a RecognizePiiEntitiesResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.entities = kwargs.get("entities", None)
self.statistics = kwargs.get("statistics", None)
self.is_error = False
class DetectLanguageResult(DictMixin):
"""DetectLanguageResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param detected_languages: A list of extracted languages.
:type detected_languages:
list[~azure.ai.textanalytics.DetectedLanguage]
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a DetectLanguageResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.detected_languages = kwargs.get("detected_languages", None)
self.statistics = kwargs.get("statistics", None)
self.is_error = False
class NamedEntity(DictMixin):
"""NamedEntity.
:param text: Entity text as appears in the request.
:type text: str
:param type: Entity type, such as Person/Location/Org/SSN etc
:type type: str
:param subtype: Entity sub type, such as Age/Year/TimeRange etc
:type subtype: str
:param offset: Start position (in Unicode characters) for the
entity text.
:type offset: int
:param length: Length (in Unicode characters) for the entity
text.
:type length: int
:param score: Confidence score between 0 and 1 of the extracted
entity.
:type score: float
"""
def __init__(self, **kwargs):
self.text = kwargs.get('text', None)
self.type = kwargs.get('type', None)
self.subtype = kwargs.get('subtype', None)
self.offset = kwargs.get('offset', None)
self.length = kwargs.get('length', None)
self.score = kwargs.get('score', None)
@classmethod
def _from_generated(cls, entity):
return cls(
text=entity.text,
type=entity.type,
subtype=entity.subtype,
offset=entity.offset,
length=entity.length,
score=entity.score,
)
class TextAnalyticsError(DictMixin):
"""TextAnalyticsError.
:param code: Error code. Possible values include:
'invalidRequest', 'invalidArgument', 'internalServerError',
'serviceUnavailable'
:type code: str
:param message: Error message.
:type message: str
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.InnerError
:param details: Details about specific errors that led to this reported
error.
:type details: list[~azure.ai.textanalytics.TextAnalyticsError]
"""
def __init__(self, **kwargs):
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.target = kwargs.get('target', None)
self.inner_error = kwargs.get('inner_error', None)
self.details = kwargs.get('details', None)
@classmethod
def _from_generated(cls, err):
return cls(
code=err.code.value,
message=err.message,
target=err.target,
inner_error=InnerError._from_generated(err.inner_error), # pylint: disable=protected-access
details=err.details,
)
class InnerError(DictMixin):
"""InnerError.
:param code: Error code. Possible values include:
'invalidParameterValue', 'invalidRequestBodyFormat', 'emptyRequest',
'missingInputRecords', 'invalidDocument', 'modelVersionIncorrect',
'invalidDocumentBatch', 'unsupportedLanguageCode', 'invalidCountryHint'
:type code: str
:param message: Error message.
:type message: str
:param details: Error details.
:type details: dict[str, str]
:param target: Error target.
:type target: str
:param inner_error: Inner error contains more specific information.
:type inner_error: ~azure.ai.textanalytics.InnerError
"""
def __init__(self, **kwargs):
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.details = kwargs.get('details', None)
self.target = kwargs.get('target', None)
self.inner_error = kwargs.get('inner_error', None)
@classmethod
def _from_generated(cls, inner_err):
return cls(
code=inner_err.code.value,
message=inner_err.message,
details=inner_err.details,
target=inner_err.target,
inner_error=inner_err.inner_error
)
class ExtractKeyPhrasesResult(DictMixin):
"""ExtractKeyPhrasesResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param key_phrases: A list of representative words or phrases.
The number of key phrases returned is proportional to the number of words
in the input document.
:type key_phrases: list[str]
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a ExtractKeyPhrasesResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.key_phrases = kwargs.get("key_phrases", None)
self.statistics = kwargs.get("statistics", None)
self.is_error = False
class RecognizeLinkedEntitiesResult(DictMixin):
"""RecognizeLinkedEntitiesResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param entities: Recognized well-known entities in the document.
:type entities:
list[~azure.ai.textanalytics.LinkedEntity]
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a RecognizeLinkedEntitiesResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.entities = kwargs.get("entities", None)
self.statistics = kwargs.get("statistics", None)
self.is_error = False
class AnalyzeSentimentResult(DictMixin):
"""AnalyzeSentimentResult.
:param id: Unique, non-empty document identifier.
:type id: str
:param sentiment: Predicted sentiment for document (Negative,
Neutral, Positive, or Mixed). Possible values include: 'positive',
'neutral', 'negative', 'mixed'
:type sentiment: str
:param statistics: If show_stats=true was specified in the request this
field will contain information about the document payload.
:type statistics:
~azure.ai.textanalytics.TextDocumentStatistics
:param document_scores: Document level sentiment confidence
scores between 0 and 1 for each sentiment class.
:type document_scores:
~azure.ai.textanalytics.SentimentConfidenceScorePerLabel
:param sentences: Sentence level sentiment analysis.
:type sentences:
list[~azure.ai.textanalytics.SentenceSentiment]
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a AnalyzeSentimentResult.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.sentiment = kwargs.get("sentiment", None)
self.statistics = kwargs.get("statistics", None)
self.document_scores = kwargs.get("document_scores", None)
self.sentences = kwargs.get("sentences", None)
self.is_error = False
class TextDocumentStatistics(DictMixin):
"""If showStats=true was specified in the request this field will contain
information about the document payload.
:param character_count: Number of text elements recognized in
the document.
:type character_count: int
:param transaction_count: Number of transactions for the
document.
:type transaction_count: int
"""
def __init__(self, **kwargs):
self.character_count = kwargs.get("character_count", None)
self.transaction_count = kwargs.get("transaction_count", None)
@classmethod
def _from_generated(cls, stats):
if stats is None:
return None
return cls(
character_count=stats.characters_count,
transaction_count=stats.transactions_count,
)
class DocumentError(DictMixin):
"""DocumentError.
:param id: Document Id.
:type id: str
:param error: Document Error.
:type error: ~azure.ai.textanalytics.TextAnalyticsError
:param bool is_error: Boolean check for error item when iterating over list of
results. Always True for an instance of a DocumentError.
"""
def __init__(self, **kwargs):
self.id = kwargs.get("id", None)
self.error = kwargs.get("error", None)
self.is_error = True
@classmethod
def _from_generated(cls, doc_err):
return cls(
id=doc_err.id,
error=TextAnalyticsError._from_generated(doc_err.error), # pylint: disable=protected-access
is_error=True
)
class DetectLanguageInput(LanguageInput):
"""Contains an input document to be analyzed for type of language.
:param id: Required. Unique, non-empty document identifier.
:type id: str
:param text: Required. The input text to process.
:type text: str
:param country_hint: A country hint to help better detect
the language of the text. Accepts two letter country codes
specified by ISO 3166-1 alpha-2. Defaults to "US". Pass
in the empty string "" to not use a country_hint.
:type country_hint: str
"""
def __init__(self, **kwargs):
super(DetectLanguageInput, self).__init__(**kwargs)
self.id = kwargs.get("id", None)
self.text = kwargs.get("text", None)
self.country_hint = kwargs.get("country_hint", None)
class LinkedEntity(DictMixin):
"""LinkedEntity.
:param name: Entity Linking formal name.
:type name: str
:param matches: List of instances this entity appears in the
text.
:type matches:
list[~azure.ai.textanalytics.LinkedEntityMatch]
:param language: Language used in the data source.
:type language: str
:param id: Unique identifier of the recognized entity from the data
source.
:type id: str
:param url: URL for the entity's page from the data source.
:type url: str
:param data_source: Data source used to extract entity linking,
such as Wiki/Bing etc.
:type data_source: str
:param bool is_error: Boolean check for error item when iterating over list of
results. Always False for an instance of a LinkedEntity.
"""
def __init__(self, **kwargs):
self.name = kwargs.get("name", None)
self.matches = kwargs.get("matches", None)
self.language = kwargs.get("language", None)
self.id = kwargs.get("id", None)
self.url = kwargs.get("url", None)
self.data_source = kwargs.get("data_source", None)
self.is_error = False
@classmethod
def _from_generated(cls, entity):
return cls(
name=entity.name,
matches=[LinkedEntityMatch._from_generated(e) for e in entity.matches], # pylint: disable=protected-access
language=entity.language,
id=entity.id,
url=entity.url,
data_source=entity.data_source,
)
class LinkedEntityMatch(DictMixin):
"""LinkedEntityMatch.
:param score: If a well-known item is recognized, a
decimal number denoting the confidence level between 0 and 1 will be
returned.
:type score: float
:param text: Entity text as appears in the request.
:type text: str
:param offset: Start position (in Unicode characters) for the
entity match text.
:type offset: int
:param length: Length (in Unicode characters) for the entity
match text.
:type length: int
"""
def __init__(self, **kwargs):
self.score = kwargs.get("score", None)
self.text = kwargs.get("text", None)
self.offset = kwargs.get("offset", None)
self.length = kwargs.get("length", None)
@classmethod
def _from_generated(cls, match):
return cls(
score=match.score, text=match.text, offset=match.offset, length=match.length
)
class TextDocumentInput(MultiLanguageInput):
"""Contains an input document to be analyzed by the service.
:param id: Required. A unique, non-empty document identifier.
:type id: str
:param text: Required. The input text to process.
:type text: str
:param language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:type language: str
"""
def __init__(self, **kwargs):
super(TextDocumentInput, self).__init__(**kwargs)
self.id = kwargs.get("id", None)
self.text = kwargs.get("text", None)
self.language = kwargs.get("language", None)
class TextDocumentBatchStatistics(DictMixin):
"""If show_stats=true was specified in the request this field will contain
information about the request payload. Note: This object is not returned
in the response and needs to be retrieved by a response hook.
:param document_count: Number of documents submitted in the request.
:type document_count: int
:param valid_document_count: Number of valid documents. This
excludes empty, over-size limit or non-supported languages documents.
:type valid_document_count: int
:param erroneous_document_count: Number of invalid documents.
This includes empty, over-size limit or non-supported languages documents.
:type erroneous_document_count: int
:param transaction_count: Number of transactions for the request.
:type transaction_count: long
"""
def __init__(self, **kwargs):
self.document_count = kwargs.get("document_count", None)
self.valid_document_count = kwargs.get("valid_document_count", None)
self.erroneous_document_count = kwargs.get("erroneous_document_count", None)
self.transaction_count = kwargs.get("transaction_count", None)
@classmethod
def _from_generated(cls, statistics):
if statistics is None:
return None
return cls(
document_count=statistics["documentsCount"],
valid_document_count=statistics["validDocumentsCount"],
erroneous_document_count=statistics["erroneousDocumentsCount"],
transaction_count=statistics["transactionsCount"],
)
class SentenceSentiment(DictMixin):
"""SentenceSentiment.
:param sentiment: The predicted Sentiment for the sentence.
Possible values include: 'positive', 'neutral', 'negative'
:type sentiment: str
:param sentence_scores: The sentiment confidence score between 0
and 1 for the sentence for all classes.
:type sentence_scores:
~azure.ai.textanalytics.SentimentConfidenceScorePerLabel
:param offset: The sentence offset from the start of the
document.
:type offset: int
:param length: The length of the sentence by Unicode standard.
:type length: int
:param warnings: The warnings generated for the sentence.
:type warnings: list[str]
"""
def __init__(self, **kwargs):
self.sentiment = kwargs.get("sentiment", None)
self.sentence_scores = kwargs.get("sentence_scores", None)
self.offset = kwargs.get("offset", None)
self.length = kwargs.get("length", None)
self.warnings = kwargs.get("warnings", None)
@classmethod
def _from_generated(cls, sentence):
return cls(
sentiment=sentence.sentiment.value,
sentence_scores=SentimentConfidenceScorePerLabel._from_generated(sentence.sentence_scores), # pylint: disable=protected-access
offset=sentence.offset,
length=sentence.length,
warnings=sentence.warnings,
)
class SentimentConfidenceScorePerLabel(DictMixin):
"""Represents the confidence scores between 0 and 1 across all sentiment
classes: positive, neutral, negative.
:param positive: Positive score.
:type positive: float
:param neutral: Neutral score.
:type neutral: float
:param negative: Negative score.
:type negative: float
"""
def __init__(self, **kwargs):
self.positive = kwargs.get('positive', None)
self.neutral = kwargs.get('neutral', None)
self.negative = kwargs.get('negative', None)
@classmethod
def _from_generated(cls, score):
return cls(
positive=score.positive,
neutral=score.neutral,
negative=score.negative
)

Просмотреть файл

@ -0,0 +1,43 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline.policies import SansIOHTTPPolicy, HTTPPolicy
from ._models import TextDocumentBatchStatistics
class CognitiveServicesCredentialPolicy(SansIOHTTPPolicy):
def __init__(self, cognitiveservices_key):
self.cognitiveservices_key = cognitiveservices_key
super(CognitiveServicesCredentialPolicy, self).__init__()
def on_request(self, request):
request.http_request.headers[
"Ocp-Apim-Subscription-Key"
] = self.cognitiveservices_key
request.http_request.headers["X-BingApis-SDK-Client"] = "Python-SDK"
class TextAnalyticsResponseHook(HTTPPolicy):
def __init__(self, **kwargs):
self._response_callback = kwargs.get("response_hook")
super(TextAnalyticsResponseHook, self).__init__()
def send(self, request):
response_callback = request.context.options.pop("response_hook", self._response_callback)
if response_callback:
response = self.next.send(request)
data = ContentDecodePolicy.deserialize_from_http_generics(response.http_response)
statistics = data.get("statistics", None)
model_version = data.get("modelVersion", None)
batch_statistics = TextDocumentBatchStatistics._from_generated(statistics) # pylint: disable=protected-access
response.statistics = batch_statistics
response.model_version = model_version
response.raw_response = data
response_callback(response)
return response
return self.next.send(request)

Просмотреть файл

@ -0,0 +1,64 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import six
from ._models import (
DetectLanguageInput,
TextDocumentInput,
)
def _validate_single_input(text, hint, hint_value):
"""Validate text input is string. Let service handle
validity of hint and hint value.
:param str text: A single text document.
:param str hint: Could be country_hint or language
:param str hint_value: The user passed country_hint or language
:return: A DetectLanguageInput or TextDocumentInput
"""
if isinstance(text, six.string_types):
return [{"id": "0", hint: hint_value, "text": text}]
raise TypeError("Text parameter must be string.")
def _validate_batch_input(documents, hint, whole_batch_hint):
"""Validate that batch input has either all string docs
or dict/DetectLanguageInput/TextDocumentInput, not a mix of both.
Assign country and language hints on a whole batch or per-item
basis.
:param list documents: The input documents.
:return: A list of DetectLanguageInput or TextDocumentInput
"""
if not isinstance(documents, list):
raise TypeError("Documents parameter must be a list.")
if not all(isinstance(x, six.string_types) for x in documents):
if not all(isinstance(x, (dict, TextDocumentInput, DetectLanguageInput)) for x in documents):
raise TypeError("Mixing string and dictionary/object input unsupported.")
string_batch = []
for idx, doc in enumerate(documents):
if isinstance(doc, six.string_types):
document = {"id": str(idx), hint: whole_batch_hint, "text": doc}
string_batch.append(document)
if isinstance(doc, dict):
item_hint = doc.get(hint, None)
if item_hint is None:
doc[hint] = whole_batch_hint
if isinstance(doc, TextDocumentInput):
item_hint = doc.language
if item_hint is None:
doc.language = whole_batch_hint
if isinstance(doc, DetectLanguageInput):
item_hint = doc.country_hint
if item_hint is None:
doc.country_hint = whole_batch_hint
return string_batch if string_batch else documents

Просмотреть файл

@ -0,0 +1,162 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import json
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.exceptions import (
HttpResponseError,
ClientAuthenticationError,
DecodeError,
)
from ._models import (
RecognizeEntitiesResult,
NamedEntity,
TextDocumentStatistics,
RecognizeLinkedEntitiesResult,
RecognizePiiEntitiesResult,
LinkedEntity,
ExtractKeyPhrasesResult,
AnalyzeSentimentResult,
SentenceSentiment,
DetectLanguageResult,
DetectedLanguage,
DocumentError,
SentimentConfidenceScorePerLabel,
TextAnalyticsError
)
def process_single_error(error):
"""Configure and raise a DocumentError for single text operation errors.
"""
try:
error_message = error.error["inner_error"]["message"]
error_code = error.error["code"]
error_message += "\nErrorCode:{}".format(error_code)
except KeyError:
raise HttpResponseError(message="There was an unknown error with the request.")
error = HttpResponseError(message=error_message)
error.error_code = error_code
raise error
def process_batch_error(error):
"""Raise detailed error message for HttpResponseErrors
"""
raise_error = HttpResponseError
if error.status_code == 401:
raise_error = ClientAuthenticationError
error_message = error.message
error_code = error.status_code
error_body = None
try:
error_body = ContentDecodePolicy.deserialize_from_http_generics(error.response)
except DecodeError:
pass
try:
if error_body is not None:
error_resp = error_body["error"]
if "innerError" in error_resp:
error_resp = error_resp["innerError"]
error_message = error_resp["message"]
error_code = error_resp["code"]
error_message += "\nErrorCode:{}".format(error_code)
except KeyError:
raise HttpResponseError(message="There was an unknown error with the request.")
error = raise_error(message=error_message, response=error.response)
error.error_code = error_code
raise error
def order_results(response, combined):
"""Order results in the order the user passed them in.
:param response: Used to get the original documents in the request
:param combined: A combined list of the results | errors
:return: In order list of results | errors (if any)
"""
request = json.loads(response.request.body)["documents"]
mapping = {item.id: item for item in combined}
ordered_response = [mapping[item["id"]] for item in request]
return ordered_response
def prepare_result(func):
def wrapper(response, obj, response_headers): # pylint: disable=unused-argument
if obj.errors:
combined = obj.documents + obj.errors
results = order_results(response, combined)
else:
results = obj.documents
for idx, item in enumerate(results):
if hasattr(item, "error"):
results[idx] = DocumentError(id=item.id, error=TextAnalyticsError._from_generated(item.error)) # pylint: disable=protected-access
else:
results[idx] = func(item)
return results
return wrapper
@prepare_result
def language_result(language):
return DetectLanguageResult(
id=language.id,
detected_languages=[DetectedLanguage._from_generated(l) for l in language.detected_languages], # pylint: disable=protected-access
statistics=TextDocumentStatistics._from_generated(language.statistics), # pylint: disable=protected-access
)
@prepare_result
def entities_result(entity):
return RecognizeEntitiesResult(
id=entity.id,
entities=[NamedEntity._from_generated(e) for e in entity.entities], # pylint: disable=protected-access
statistics=TextDocumentStatistics._from_generated(entity.statistics), # pylint: disable=protected-access
)
@prepare_result
def pii_entities_result(entity):
return RecognizePiiEntitiesResult(
id=entity.id,
entities=[NamedEntity._from_generated(e) for e in entity.entities], # pylint: disable=protected-access
statistics=TextDocumentStatistics._from_generated(entity.statistics), # pylint: disable=protected-access
)
@prepare_result
def linked_entities_result(entity):
return RecognizeLinkedEntitiesResult(
id=entity.id,
entities=[LinkedEntity._from_generated(e) for e in entity.entities], # pylint: disable=protected-access
statistics=TextDocumentStatistics._from_generated(entity.statistics), # pylint: disable=protected-access
)
@prepare_result
def key_phrases_result(phrases):
return ExtractKeyPhrasesResult(
id=phrases.id,
key_phrases=phrases.key_phrases,
statistics=TextDocumentStatistics._from_generated(phrases.statistics), # pylint: disable=protected-access
)
@prepare_result
def sentiment_result(sentiment):
return AnalyzeSentimentResult(
id=sentiment.id,
sentiment=sentiment.sentiment.value,
statistics=TextDocumentStatistics._from_generated(sentiment.statistics), # pylint: disable=protected-access
document_scores=SentimentConfidenceScorePerLabel._from_generated(sentiment.document_scores), # pylint: disable=protected-access
sentences=[SentenceSentiment._from_generated(s) for s in sentiment.sentences], # pylint: disable=protected-access
)

Просмотреть файл

@ -0,0 +1,429 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import ( # pylint: disable=unused-import
Union,
Optional,
Any,
List,
Dict,
TYPE_CHECKING,
)
from azure.core.tracing.decorator import distributed_trace
from ._generated.models import TextAnalyticsErrorException
from ._generated._text_analytics_client import TextAnalyticsClient as TextAnalytics
from ._base_client import TextAnalyticsClientBase
from ._request_handlers import _validate_batch_input
from ._response_handlers import (
process_batch_error,
entities_result,
linked_entities_result,
key_phrases_result,
sentiment_result,
language_result,
pii_entities_result
)
if TYPE_CHECKING:
from ._models import (
DetectLanguageInput,
TextDocumentInput,
DetectLanguageResult,
RecognizeEntitiesResult,
RecognizeLinkedEntitiesResult,
ExtractKeyPhrasesResult,
AnalyzeSentimentResult,
RecognizePiiEntitiesResult,
DocumentError,
)
class TextAnalyticsClient(TextAnalyticsClientBase):
"""The Text Analytics API is a suite of text analytics web services built with best-in-class
Microsoft machine learning algorithms. The API can be used to analyze unstructured text for
tasks such as sentiment analysis, key phrase extraction, and language detection. No training data
is needed to use this API - just bring your text data. This API uses advanced natural language
processing techniques to deliver best in class predictions.
Further documentation can be found in
https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview
:param str endpoint: Supported Cognitive Services or Text Analytics resource
endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services/text analytics subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
.. admonition:: Example:
.. literalinclude:: ../samples/sample_authentication.py
:start-after: [START create_ta_client_with_key]
:end-before: [END create_ta_client_with_key]
:language: python
:dedent: 8
:caption: Creating the TextAnalyticsClient with endpoint and subscription key.
.. literalinclude:: ../samples/sample_authentication.py
:start-after: [START create_ta_client_with_aad]
:end-before: [END create_ta_client_with_aad]
:language: python
:dedent: 8
:caption: Creating the TextAnalyticsClient with endpoint and token credential from Azure Active Directory.
"""
def __init__(self, endpoint, credential, **kwargs):
# type: (str, Any, Any) -> None
super(TextAnalyticsClient, self).__init__(credential=credential, **kwargs)
self._client = TextAnalytics(
endpoint=endpoint, credentials=credential, pipeline=self._pipeline
)
@distributed_trace
def detect_languages( # type: ignore
self,
inputs, # type: Union[List[str], List[DetectLanguageInput], List[Dict[str, str]]]
country_hint="US", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[DetectLanguageResult, DocumentError]]
"""Detects Language for a batch of documents.
Returns the detected language and a numeric score between zero and
one. Scores close to one indicate 100% certainty that the identified
language is true. See https://aka.ms/talangs for the list of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and country_hint on a per-item basis you must
use as input a list[DetectLanguageInput] or a list of dict representations of
DetectLanguageInput, like `{"id": "1", "country_hint": "us", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.DetectLanguageInput]
:param str country_hint: A country hint for the entire batch. Accepts two
letter country codes specified by ISO 3166-1 alpha-2. Per-document
country hints will take precedence over whole batch hints. Defaults to
"US". If you don't want to use a country hint, pass the empty string "".
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document
level statistics.
:return: The combined list of DetectLanguageResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.DetectLanguageResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_languages.py
:start-after: [START batch_detect_languages]
:end-before: [END batch_detect_languages]
:language: python
:dedent: 8
:caption: Detecting language in a batch of documents.
"""
docs = _validate_batch_input(inputs, "country_hint", country_hint)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.languages(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=language_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace
def recognize_entities( # type: ignore
self,
inputs, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]]
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[RecognizeEntitiesResult, DocumentError]]
"""Named Entity Recognition for a batch of documents.
Returns a list of general named entities in a given document.
For a list of supported entity types, check: https://aka.ms/taner
For a list of enabled languages, check: https://aka.ms/talangs
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document
level statistics.
:return: The combined list of RecognizeEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizeEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_recognize_entities.py
:start-after: [START batch_recognize_entities]
:end-before: [END batch_recognize_entities]
:language: python
:dedent: 8
:caption: Recognize entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.entities_recognition_general(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace
def recognize_pii_entities( # type: ignore
self,
inputs, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]]
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[RecognizePiiEntitiesResult, DocumentError]]
"""Recognize entities containing personal information for a batch of documents.
Returns a list of personal information entities ("SSN",
"Bank Account", etc) in the document. For the list of supported entity types,
check https://aka.ms/tanerpii. See https://aka.ms/talangs
for the list of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of RecognizePiiEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizePiiEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_recognize_pii_entities.py
:start-after: [START batch_recognize_pii_entities]
:end-before: [END batch_recognize_pii_entities]
:language: python
:dedent: 8
:caption: Recognize personally identifiable information entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.entities_recognition_pii(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=pii_entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace
def recognize_linked_entities( # type: ignore
self,
inputs, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]]
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[RecognizeLinkedEntitiesResult, DocumentError]]
"""Recognize linked entities from a well-known knowledge base for a batch of documents.
Returns a list of recognized entities with links to a
well-known knowledge base. See https://aka.ms/talangs for
supported languages in Text Analytics API.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of RecognizeLinkedEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizeLinkedEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_recognize_linked_entities.py
:start-after: [START batch_recognize_linked_entities]
:end-before: [END batch_recognize_linked_entities]
:language: python
:dedent: 8
:caption: Recognize linked entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.entities_linking(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=linked_entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace
def extract_key_phrases( # type: ignore
self,
inputs, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]]
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[ExtractKeyPhrasesResult, DocumentError]]
"""Extract Key Phrases from a batch of documents.
Returns a list of strings denoting the key phrases in the input
text. See https://aka.ms/talangs for the list of enabled
languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of ExtractKeyPhrasesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.ExtractKeyPhrasesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_extract_key_phrases.py
:start-after: [START batch_extract_key_phrases]
:end-before: [END batch_extract_key_phrases]
:language: python
:dedent: 8
:caption: Extract the key phrases in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.key_phrases(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=key_phrases_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace
def analyze_sentiment( # type: ignore
self,
inputs, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]]
language="en", # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> List[Union[AnalyzeSentimentResult, DocumentError]]
"""Analyze sentiment for a batch of documents.
Returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See https://aka.ms/talangs for the list
of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of AnalyzeSentimentResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.AnalyzeSentimentResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/sample_analyze_sentiment.py
:start-after: [START batch_analyze_sentiment]
:end-before: [END batch_analyze_sentiment]
:language: python
:dedent: 8
:caption: Analyze sentiment in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return self._client.sentiment(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=sentiment_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)

Просмотреть файл

@ -0,0 +1,7 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
VERSION = "1.0.0b1"

Просмотреть файл

@ -0,0 +1,368 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import Any, Optional # pylint: disable=unused-import
from .._request_handlers import _validate_single_input
from .._response_handlers import process_single_error
from ._text_analytics_client_async import TextAnalyticsClient
from .._models import (
DetectLanguageResult,
RecognizeEntitiesResult,
RecognizePiiEntitiesResult,
RecognizeLinkedEntitiesResult,
ExtractKeyPhrasesResult,
AnalyzeSentimentResult,
)
__all__ = [
'TextAnalyticsClient',
'single_detect_language',
'single_recognize_entities',
'single_recognize_pii_entities',
'single_recognize_linked_entities',
'single_extract_key_phrases',
'single_analyze_sentiment',
]
async def single_detect_language(
endpoint: str,
credential: str,
input_text: str,
country_hint: Optional[str] = "US",
**kwargs: Any
) -> DetectLanguageResult:
"""Detect Language for a single document.
Returns the detected language and a numeric score between zero and
one. Scores close to one indicate 100% certainty that the identified
language is true. See https://aka.ms/talangs for the list of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to detect language from.
:param str country_hint: The country hint for the text. Accepts two
letter country codes specified by ISO 3166-1 alpha-2.
Defaults to "US". If you don't want to use a country hint,
pass the empty string "".
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of DetectLanguageResult.
:rtype: ~azure.ai.textanalytics.DetectLanguageResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_detect_language_async.py
:start-after: [START single_detect_language_async]
:end-before: [END single_detect_language_async]
:language: python
:dedent: 8
:caption: Detecting language in a single string.
"""
doc = _validate_single_input(input_text, "country_hint", country_hint)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.detect_languages(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # DetectLanguageResult
async def single_recognize_entities(
endpoint: str,
credential: str,
input_text: str,
language: Optional[str] = "en",
**kwargs: Any
) -> RecognizeEntitiesResult:
"""Named Entity Recognition for a single document.
Returns a list of general named entities in a given document.
For a list of supported entity types, check: https://aka.ms/taner
For a list of enabled languages, check: https://aka.ms/talangs
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizeEntitiesResult.
:rtype: ~azure.ai.textanalytics.RecognizeEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_recognize_entities_async.py
:start-after: [START single_recognize_entities_async]
:end-before: [END single_recognize_entities_async]
:language: python
:dedent: 8
:caption: Recognize entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.recognize_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizeEntitiesResult
async def single_recognize_pii_entities(
endpoint: str,
credential: str,
input_text: str,
language: Optional[str] = "en",
**kwargs: Any
) -> RecognizePiiEntitiesResult:
"""Recognize entities containing personal information for a single document.
Returns a list of personal information entities ("SSN",
"Bank Account", etc) in the document. For the list of supported entity types,
check https://aka.ms/tanerpii. See https://aka.ms/talangs
for the list of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizePiiEntitiesResult.
:rtype: ~azure.ai.textanalytics.RecognizePiiEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_recognize_pii_entities_async.py
:start-after: [START single_recognize_pii_entities_async]
:end-before: [END single_recognize_pii_entities_async]
:language: python
:dedent: 8
:caption: Recognize personally identifiable information entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.recognize_pii_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizePiiEntitiesResult
async def single_recognize_linked_entities(
endpoint: str,
credential: str,
input_text: str,
language: Optional[str] = "en",
**kwargs: Any
) -> RecognizeLinkedEntitiesResult:
"""Recognize linked entities from a well-known knowledge base
for a single document.
Returns a list of recognized entities with links to a
well-known knowledge base. See https://aka.ms/talangs for
supported languages in Text Analytics API.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to recognize entities from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of RecognizeLinkedEntitiesResult
:rtype: ~azure.ai.textanalytics.RecognizeLinkedEntitiesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_recognize_linked_entities_async.py
:start-after: [START single_recognize_linked_entities_async]
:end-before: [END single_recognize_linked_entities_async]
:language: python
:dedent: 8
:caption: Recognize linked entities in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.recognize_linked_entities(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # RecognizeLinkedEntitiesResult
async def single_extract_key_phrases(
endpoint: str,
credential: str,
input_text: str,
language: Optional[str] = "en",
**kwargs: Any
) -> ExtractKeyPhrasesResult:
"""Extract Key Phrases for a single document.
Returns a list of strings denoting the key phrases in the input
text. See https://aka.ms/talangs for the list of enabled
languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to extract key phrases from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of ExtractKeyPhrasesResult
:rtype: ~azure.ai.textanalytics.ExtractKeyPhrasesResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_extract_key_phrases_async.py
:start-after: [START single_extract_key_phrases_async]
:end-before: [END single_extract_key_phrases_async]
:language: python
:dedent: 8
:caption: Extract key phrases in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.extract_key_phrases(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # ExtractKeyPhrasesResult
async def single_analyze_sentiment(
endpoint: str,
credential: str,
input_text: str,
language: Optional[str] = "en",
**kwargs: Any
) -> AnalyzeSentimentResult:
"""Analyze sentiment in a single document.
Returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See https://aka.ms/talangs for the list
of enabled languages.
:param str endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
:param str input_text: The single string to analyze sentiment from.
:param str language: This is the 2 letter ISO 639-1 representation
of a language. For example, use "en" for English; "es" for Spanish etc. If
not set, uses "en" for English as default.
:keyword bool show_stats: If set to true, response will contain
document level statistics.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:return: An instance of AnalyzeSentimentResult
:rtype: ~azure.ai.textanalytics.AnalyzeSentimentResult
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_single_analyze_sentiment_async.py
:start-after: [START single_analyze_sentiment_async]
:end-before: [END single_analyze_sentiment_async]
:language: python
:dedent: 8
:caption: Analyze sentiment in a single string.
"""
doc = _validate_single_input(input_text, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
async with TextAnalyticsClient(endpoint, credential=credential, **kwargs) as client:
response = await client.analyze_sentiment(
inputs=doc,
model_version=model_version,
show_stats=show_stats,
**kwargs
)
if response[0].is_error:
return process_single_error(response[0]) # DocumentError
return response[0] # AnalyzeSentimentResult

Просмотреть файл

@ -0,0 +1,85 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import six
from azure.core.pipeline import AsyncPipeline
from azure.core.configuration import Configuration
from azure.core.pipeline.policies import (
UserAgentPolicy,
HeadersPolicy,
ProxyPolicy,
RequestIdPolicy,
NetworkTraceLoggingPolicy,
AsyncRetryPolicy,
AsyncRedirectPolicy,
AsyncBearerTokenCredentialPolicy,
HttpLoggingPolicy,
DistributedTracingPolicy
)
from .._policies import CognitiveServicesCredentialPolicy
from ._policies_async import AsyncTextAnalyticsResponseHook
from .._version import VERSION
class AsyncTextAnalyticsClientBase(object):
def __init__(self, credential, **kwargs):
self._pipeline = self._create_pipeline(credential, **kwargs)
def _create_pipeline(self, credential, **kwargs):
credential_policy = None
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
if hasattr(credential, "get_token"):
credential_policy = AsyncBearerTokenCredentialPolicy(
credential, "https://cognitiveservices.azure.com/.default"
)
elif isinstance(credential, six.string_types):
credential_policy = CognitiveServicesCredentialPolicy(credential)
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))
config = self._create_configuration(**kwargs)
config.transport = kwargs.get("transport") # type: ignore
if not config.transport:
try:
from azure.core.pipeline.transport import AioHttpTransport
except ImportError:
raise ImportError("Unable to create async transport. Please check aiohttp is installed.")
config.transport = AioHttpTransport(**kwargs)
config.user_agent_policy.add_user_agent(
'azsdk-python-azure-ai-textanalytics/{}'.format(VERSION)
)
policies = [
config.headers_policy,
config.user_agent_policy,
RequestIdPolicy(**kwargs),
config.proxy_policy,
AsyncRedirectPolicy(**kwargs),
AsyncRetryPolicy(**kwargs),
credential_policy,
config.logging_policy,
AsyncTextAnalyticsResponseHook(**kwargs),
DistributedTracingPolicy(**kwargs),
HttpLoggingPolicy(**kwargs)
]
return AsyncPipeline(config.transport, policies=policies)
def _create_configuration(self, **kwargs): # pylint: disable=no-self-use
config = Configuration(**kwargs)
config.user_agent_policy = kwargs.get('user_agent_policy') or UserAgentPolicy(**kwargs)
config.headers_policy = kwargs.get('headers_policy') or HeadersPolicy(**kwargs)
config.proxy_policy = kwargs.get('proxy_policy') or ProxyPolicy(**kwargs)
config.logging_policy = kwargs.get('logging_policy') or NetworkTraceLoggingPolicy(**kwargs)
return config
async def __aenter__(self):
await self._client.__aenter__() # pylint: disable=no-member
return self
async def __aexit__(self, *args):
await self._client.__aexit__(*args) # pylint: disable=no-member

Просмотреть файл

@ -0,0 +1,36 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import asyncio
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline.policies import AsyncHTTPPolicy
from .._models import TextDocumentBatchStatistics
class AsyncTextAnalyticsResponseHook(AsyncHTTPPolicy):
def __init__(self, **kwargs):
self._response_callback = kwargs.get('response_hook')
super(AsyncTextAnalyticsResponseHook, self).__init__()
async def send(self, request):
response_callback = request.context.options.pop("response_hook", self._response_callback)
if response_callback:
response = await self.next.send(request)
data = ContentDecodePolicy.deserialize_from_http_generics(response.http_response)
statistics = data.get("statistics", None)
model_version = data.get("modelVersion", None)
batch_statistics = TextDocumentBatchStatistics._from_generated(statistics) # pylint: disable=protected-access
response.statistics = batch_statistics
response.model_version = model_version
response.raw_response = data
if asyncio.iscoroutine(response_callback):
await response_callback(response)
else:
response_callback(response)
return response
return await self.next.send(request)

Просмотреть файл

@ -0,0 +1,419 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import ( # pylint: disable=unused-import
Union,
Optional,
Any,
List,
Dict,
)
from azure.core.tracing.decorator_async import distributed_trace_async
from .._generated.models import TextAnalyticsErrorException
from .._generated.aio._text_analytics_client_async import TextAnalyticsClient as TextAnalytics
from ._base_client_async import AsyncTextAnalyticsClientBase
from .._request_handlers import _validate_batch_input
from .._response_handlers import (
process_batch_error,
entities_result,
linked_entities_result,
key_phrases_result,
sentiment_result,
language_result,
pii_entities_result
)
from .._models import (
DetectLanguageInput,
TextDocumentInput,
DetectLanguageResult,
RecognizeEntitiesResult,
RecognizeLinkedEntitiesResult,
ExtractKeyPhrasesResult,
AnalyzeSentimentResult,
RecognizePiiEntitiesResult,
DocumentError,
)
class TextAnalyticsClient(AsyncTextAnalyticsClientBase):
"""The Text Analytics API is a suite of text analytics web services built with best-in-class
Microsoft machine learning algorithms. The API can be used to analyze unstructured text for
tasks such as sentiment analysis, key phrase extraction, and language detection. No training data
is needed to use this API - just bring your text data. This API uses advanced natural language
processing techniques to deliver best in class predictions.
Further documentation can be found in
https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview
:param str endpoint: Supported Cognitive Services or Text Analytics resource
endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
:param credential: Credentials needed for the client to connect to Azure.
This can be the cognitive services/text analytics subscription key or a token credential
from azure.identity.
:type credential: str or ~azure.core.credentials.TokenCredential
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_authentication_async.py
:start-after: [START create_ta_client_with_key_async]
:end-before: [END create_ta_client_with_key_async]
:language: python
:dedent: 8
:caption: Creating the TextAnalyticsClient with endpoint and subscription key.
.. literalinclude:: ../samples/async_samples/sample_authentication_async.py
:start-after: [START create_ta_client_with_aad_async]
:end-before: [END create_ta_client_with_aad_async]
:language: python
:dedent: 8
:caption: Creating the TextAnalyticsClient with endpoint and token credential from Azure Active Directory.
"""
def __init__(self, endpoint, credential, **kwargs):
# type: (str, Any, Any) -> None
super(TextAnalyticsClient, self).__init__(credential=credential, **kwargs)
self._client = TextAnalytics(
endpoint=endpoint, credentials=credential, pipeline=self._pipeline
)
@distributed_trace_async
async def detect_languages( # type: ignore
self,
inputs: Union[List[str], List[DetectLanguageInput], List[Dict[str, str]]],
country_hint: Optional[str] = "US",
**kwargs: Any
) -> List[Union[DetectLanguageResult, DocumentError]]:
"""Detects Language for a batch of documents.
Returns the detected language and a numeric score between zero and
one. Scores close to one indicate 100% certainty that the identified
language is true. See https://aka.ms/talangs for the list of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and country_hint on a per-item basis you must
use as input a list[DetectLanguageInput] or a list of dict representations of
DetectLanguageInput, like `{"id": "1", "country_hint": "us", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.DetectLanguageInput]
:param str country_hint: A country hint for the entire batch. Accepts two
letter country codes specified by ISO 3166-1 alpha-2. Per-document
country hints will take precedence over whole batch hints. Defaults to
"US". If you don't want to use a country hint, pass the empty string "".
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document
level statistics.
:return: The combined list of DetectLanguageResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.DetectLanguageResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_detect_languages_async.py
:start-after: [START batch_detect_languages_async]
:end-before: [END batch_detect_languages_async]
:language: python
:dedent: 8
:caption: Detecting language in a batch of documents.
"""
docs = _validate_batch_input(inputs, "country_hint", country_hint)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.languages(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=language_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace_async
async def recognize_entities( # type: ignore
self,
inputs: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
language: Optional[str] = "en",
**kwargs: Any
) -> List[Union[RecognizeEntitiesResult, DocumentError]]:
"""Named Entity Recognition for a batch of documents.
Returns a list of general named entities in a given document.
For the list of supported entity types, check: https://aka.ms/taner
For the list of enabled languages, check: https://aka.ms/talangs
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of RecognizeEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizeEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_recognize_entities_async.py
:start-after: [START batch_recognize_entities_async]
:end-before: [END batch_recognize_entities_async]
:language: python
:dedent: 8
:caption: Recognize entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.entities_recognition_general(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace_async
async def recognize_pii_entities( # type: ignore
self,
inputs: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
language: Optional[str] = "en",
**kwargs: Any
) -> List[Union[RecognizePiiEntitiesResult, DocumentError]]:
"""Recognize entities containing personal information for a batch of documents.
Returns a list of personal information entities ("SSN",
"Bank Account", etc) in the document. For the list of supported entity types,
check https://aka.ms/tanerpii. See https://aka.ms/talangs
for the list of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of RecognizePiiEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizePiiEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_recognize_pii_entities_async.py
:start-after: [START batch_recognize_pii_entities_async]
:end-before: [END batch_recognize_pii_entities_async]
:language: python
:dedent: 8
:caption: Recognize personally identifiable information entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.entities_recognition_pii(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=pii_entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace_async
async def recognize_linked_entities( # type: ignore
self,
inputs: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
language: Optional[str] = "en",
**kwargs: Any
) -> List[Union[RecognizeLinkedEntitiesResult, DocumentError]]:
"""Recognize linked entities from a well-known knowledge base for a batch of documents.
Returns a list of recognized entities with links to a
well-known knowledge base. See https://aka.ms/talangs for
supported languages in Text Analytics API.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of RecognizeLinkedEntitiesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.RecognizeLinkedEntitiesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_recognize_linked_entities_async.py
:start-after: [START batch_recognize_linked_entities_async]
:end-before: [END batch_recognize_linked_entities_async]
:language: python
:dedent: 8
:caption: Recognize linked entities in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.entities_linking(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=linked_entities_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace_async
async def extract_key_phrases( # type: ignore
self,
inputs: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
language: Optional[str] = "en",
**kwargs: Any
) -> List[Union[ExtractKeyPhrasesResult, DocumentError]]:
"""Extract Key Phrases from a batch of documents.
Returns a list of strings denoting the key phrases in the input
text. See https://aka.ms/talangs for the list of enabled
languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of ExtractKeyPhrasesResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.ExtractKeyPhrasesResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_extract_key_phrases_async.py
:start-after: [START batch_extract_key_phrases_async]
:end-before: [END batch_extract_key_phrases_async]
:language: python
:dedent: 8
:caption: Extract the key phrases in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.key_phrases(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=key_phrases_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)
@distributed_trace_async
async def analyze_sentiment( # type: ignore
self,
inputs: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
language: Optional[str] = "en",
**kwargs: Any
) -> List[Union[AnalyzeSentimentResult, DocumentError]]:
"""Analyze sentiment for a batch of documents.
Returns a sentiment prediction, as well as sentiment scores for
each sentiment class (Positive, Negative, and Neutral) for the document
and each sentence within it. See https://aka.ms/talangs for the list
of enabled languages.
:param inputs: The set of documents to process as part of this batch.
If you wish to specify the ID and language on a per-item basis you must
use as input a list[TextDocumentInput] or a list of dict representations of
TextDocumentInput, like `{"id": "1", "language": "en", "text": "hello world"}`.
:type inputs:
list[str] or list[~azure.ai.textanalytics.TextDocumentInput]
:param str language: The 2 letter ISO 639-1 representation of language for the
entire batch. For example, use "en" for English; "es" for Spanish etc.
If not set, uses "en" for English as default. Per-document language will
take precedence over whole batch language.
:keyword str model_version: This value indicates which model will
be used for scoring, e.g. "latest", "2019-10-01". If a model-version
is not specified, the API will default to the latest, non-preview version.
:keyword bool show_stats: If set to true, response will contain document level statistics.
:return: The combined list of AnalyzeSentimentResults and DocumentErrors in the order
the original documents were passed in.
:rtype: list[~azure.ai.textanalytics.AnalyzeSentimentResult,
~azure.ai.textanalytics.DocumentError]
:raises ~azure.core.exceptions.HttpResponseError:
.. admonition:: Example:
.. literalinclude:: ../samples/async_samples/sample_analyze_sentiment_async.py
:start-after: [START batch_analyze_sentiment_async]
:end-before: [END batch_analyze_sentiment_async]
:language: python
:dedent: 8
:caption: Analyze sentiment in a batch of documents.
"""
docs = _validate_batch_input(inputs, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
try:
return await self._client.sentiment(
documents=docs,
model_version=model_version,
show_stats=show_stats,
cls=sentiment_result,
**kwargs
)
except TextAnalyticsErrorException as error:
process_batch_error(error)

Просмотреть файл

@ -0,0 +1,11 @@
# ------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
import sys
# Ignore async tests for Python < 3.5
collect_ignore_glob = []
if sys.version_info < (3, 5):
collect_ignore_glob.append("tests/*_async.py")

Просмотреть файл

@ -0,0 +1,5 @@
-e ../../../tools/azure-sdk-tools
-e ../../cognitiveservices/azure-mgmt-cognitiveservices
../../core/azure-core
aiohttp>=3.0; python_version >= '3.5'
../azure-ai-nspkg

Просмотреть файл

@ -0,0 +1,12 @@
[mypy]
python_version = 3.6
warn_unused_configs = True
ignore_missing_imports = True
# Per-module options:
[mypy-azure.ai.textanalytics._generated.*]
ignore_errors = True
[mypy-azure.core.*]
ignore_errors = True

Просмотреть файл

@ -0,0 +1,60 @@
---
topic: sample
languages:
- python
products:
- azure
- azure-ai-textanalytics
---
# Samples for Azure Text Analytics client library for Python
These code samples show common scenario operations with the Azure Text Analytics client library.
The async versions of the samples (the python sample files appended with `_async`) show asynchronous operations
with Text Analytics and require Python 3.5 or later.
Authenticate the client with a Cognitive Services/Text Analytics subscription key or a token credential from [azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity):
* [sample_authentication.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_authentication.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_authentication_async.py))
In a batch of documents:
* Detect languages: [sample_detect_languages.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_detect_languages.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_detect_languages_async.py))
* Recognize entities: [sample_recognize_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_async.py))
* Recognize linked entities: [sample_recognize_linked_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_linked_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_linked_entities_async.py))
* Recognize personally identifiable information: [sample_recognize_pii_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_pii_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_pii_entities_async.py))
* Extract key phrases: [sample_extract_key_phrases.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_extract_key_phrases.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_async.py))
* Analyze sentiment: [sample_analyze_sentiment.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_async.py))
In a single string of text:
* Detect language: [sample_single_detect_language.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_detect_language.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_detect_language_async.py))
* Recognize entities: [sample_single_recognize_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_entities_async.py))
* Recognize linked entities: [sample_single_recognize_linked_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_linked_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_linked_entities_async.py))
* Recognize personally identifiable information: [sample_single_recognize_pii_entities.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_recognize_pii_entities.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_recognize_pii_entities_async.py))
* Extract key phrases: [sample_single_extract_key_phrases.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_extract_key_phrases.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_extract_key_phrases_async.py))
* Analyze sentiment: [sample_single_analyze_sentiment.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_single_analyze_sentiment.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_single_analyze_sentiment_async.py))
## Prerequisites
* Python 2.7, or 3.5 or later is required to use this package (3.5 or later if using asyncio)
* You must have an [Azure subscription](https://azure.microsoft.com/free/) and an
[Azure Text Analytics account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=singleservice%2Cwindows) to run these samples.
## Setup
1. Install the Azure Text Analytics client library for Python with [pip](https://pypi.org/project/pip/):
```bash
pip install azure-ai-textanalytics --pre
```
2. Clone or download this sample repository
3. Open the sample folder in Visual Studio Code or your IDE of choice.
## Running the samples
1. Open a terminal window and `cd` to the directory that the samples are saved in.
2. Set the environment variables specified in the sample file you wish to run.
3. Follow the usage described in the file, e.g. `python sample_detect_language.py`
## Next steps
Check out the [API reference documentation](https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-0-Preview-1/operations/Languages) to learn more about
what you can do with the Azure Text Analytics client library.

Просмотреть файл

@ -0,0 +1,166 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_async.py
DESCRIPTION:
This sample demonstrates how to analyze sentiment in a batch of documents.
An overall and per-sentence sentiment is returned.
USAGE:
python sample_analyze_sentiment_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: I had the best day of my life.
Overall sentiment: positive
Overall scores: positive=0.999; neutral=0.999; negative=0.999
Sentence 1 sentiment: positive
Sentence score: positive=0.999; neutral=0.999; negative=0.999
Offset: 0
Length: 30
------------------------------------
Document text: This was a waste of my time. The speaker put me to sleep.
Overall sentiment: negative
Overall scores: positive=0.061; neutral=0.061; negative=0.061
Sentence 1 sentiment: negative
Sentence score: positive=0.000; neutral=0.000; negative=0.000
Offset: 0
Length: 28
Sentence 2 sentiment: neutral
Sentence score: positive=0.122; neutral=0.122; negative=0.122
Offset: 29
Length: 28
------------------------------------
Document text: No tengo dinero ni nada que dar...
Overall sentiment: negative
Overall scores: positive=0.026; neutral=0.026; negative=0.026
Sentence 1 sentiment: negative
Sentence score: positive=0.026; neutral=0.026; negative=0.026
Offset: 0
Length: 34
------------------------------------
Document text: L'hôtel n'était pas très confortable. L'éclairage était trop sombre.
Overall sentiment: negative
Overall scores: positive=0.165; neutral=0.165; negative=0.165
Sentence 1 sentiment: negative
Sentence score: positive=0.186; neutral=0.186; negative=0.186
Offset: 0
Length: 37
Sentence 2 sentiment: negative
Sentence score: positive=0.143; neutral=0.143; negative=0.143
Offset: 38
Length: 30
------------------------------------
"""
import os
import asyncio
class AnalyzeSentimentSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def analyze_sentiment_async(self):
# [START batch_analyze_sentiment_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"I had the best day of my life.",
"This was a waste of my time. The speaker put me to sleep.",
"No tengo dinero ni nada que dar...",
"L'hôtel n'était pas très confortable. L'éclairage était trop sombre."
]
async with text_analytics_client:
result = await text_analytics_client.analyze_sentiment(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}".format(documents[idx]))
print("Overall sentiment: {}".format(doc.sentiment))
# [END batch_analyze_sentiment_async]
print("Overall scores: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
doc.document_scores.positive,
doc.document_scores.neutral,
doc.document_scores.negative,
))
for idx, sentence in enumerate(doc.sentences):
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
print("Sentence score: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f}".format(
sentence.sentence_scores.positive,
sentence.sentence_scores.neutral,
sentence.sentence_scores.negative,
))
print("Offset: {}".format(sentence.offset))
print("Length: {}\n".format(sentence.length))
print("------------------------------------")
async def alternative_scenario_analyze_sentiment_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "I had the best day of my life."},
{"id": "1", "language": "en",
"text": "This was a waste of my time. The speaker put me to sleep."},
{"id": "2", "language": "es", "text": "No tengo dinero ni nada que dar..."},
{"id": "3", "language": "fr",
"text": "L'hôtel n'était pas très confortable. L'éclairage était trop sombre."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.analyze_sentiment(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = AnalyzeSentimentSampleAsync()
await sample.analyze_sentiment_async()
await sample.alternative_scenario_analyze_sentiment_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,84 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_authentication_async.py
DESCRIPTION:
This sample demonstrates how to authenticate with the text analytics service.
There are two supported methods of authentication:
1) Use a cognitive services subscription key
2) Use a token credential to authenticate with Azure Active Directory
See more details about authentication here:
https://docs.microsoft.com/azure/cognitive-services/authentication
USAGE:
python sample_authentication_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
3) AZURE_CLIENT_ID - the client ID of your active directory application.
4) AZURE_TENANT_ID - the tenant ID of your active directory application.
5) AZURE_CLIENT_SECRET - the secret of your active directory application.
"""
import os
import asyncio
class AuthenticationSampleAsync(object):
async def authentication_with_subscription_key_async(self):
# [START create_ta_client_with_key_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
text_analytics_client = TextAnalyticsClient(endpoint, key)
# [END create_ta_client_with_key_async]
doc = ["I need to take my cat to the veterinarian."]
async with text_analytics_client:
result = await text_analytics_client.detect_languages(doc)
print("Language detected: {}".format(result[0].detected_languages[0].name))
print("Confidence score: {}".format(result[0].detected_languages[0].score))
async def authentication_with_azure_active_directory_async(self):
"""DefaultAzureCredential will use the values from the environment
variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
"""
# [START create_ta_client_with_aad_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
from azure.identity.aio import DefaultAzureCredential
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
credential = DefaultAzureCredential()
text_analytics_client = TextAnalyticsClient(endpoint, credential=credential)
# [END create_ta_client_with_aad_async]
doc = ["I need to take my cat to the veterinarian."]
async with text_analytics_client:
result = await text_analytics_client.detect_languages(doc)
print("Language detected: {}".format(result[0].detected_languages[0].name))
print("Confidence score: {}".format(result[0].detected_languages[0].score))
async def main():
sample = AuthenticationSampleAsync()
await sample.authentication_with_subscription_key_async()
await sample.authentication_with_azure_active_directory_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,126 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_detect_languages_async.py
DESCRIPTION:
This sample demonstrates how to detect language in a batch of different
documents.
USAGE:
python sample_detect_languages_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: This is a document written in English.
Language detected: English
ISO6391 name: en
Confidence score: 1.0
Document text: Este es un document escrito en Español.
Language detected: Spanish
ISO6391 name: es
Confidence score: 1.0
Document text: 这是一个用中文写的文件
Language detected: Chinese_Simplified
ISO6391 name: zh_chs
Confidence score: 1.0
Document text: Dies ist ein Dokument in englischer Sprache.
Language detected: German
ISO6391 name: de
Confidence score: 1.0
Document text: Detta är ett dokument skrivet engelska.
Language detected: Swedish
ISO6391 name: sv
Confidence score: 1.0
"""
import os
import asyncio
class DetectLanguagesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def detect_languages_async(self):
# [START batch_detect_languages_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"This document is written in English.",
"Este es un document escrito en Español.",
"这是一个用中文写的文件",
"Dies ist ein Dokument in englischer Sprache.",
"Detta är ett dokument skrivet på engelska."
]
async with text_analytics_client:
result = await text_analytics_client.detect_languages(documents)
for idx, doc in enumerate(result):
if not doc.is_error:
print("Document text: {}".format(documents[idx]))
print("Language detected: {}".format(doc.detected_languages[0].name))
print("ISO6391 name: {}".format(doc.detected_languages[0].iso6391_name))
print("Confidence score: {}\n".format(doc.detected_languages[0].score))
if doc.is_error:
print(doc.id, doc.error)
# [END batch_detect_languages_async]
async def alternative_scenario_detect_languages_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[DetectLanguageInput] and supplying your own IDs and country hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "country_hint": "US", "text": "This is a document written in English."},
{"id": "1", "country_hint": "MX", "text": "Este es un document escrito en Español."},
{"id": "2", "country_hint": "CN", "text": "这是一个用中文写的文件"},
{"id": "3", "country_hint": "DE", "text": "Dies ist ein Dokument in englischer Sprache."},
{"id": "4", "country_hint": "SE", "text": "Detta är ett dokument skrivet på engelska."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.detect_languages(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = DetectLanguagesSampleAsync()
await sample.detect_languages_async()
await sample.alternative_scenario_detect_languages_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,99 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_async.py
DESCRIPTION:
This sample demonstrates how to extract key talking points from a batch of documents.
USAGE:
python sample_extract_key_phrases_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
['King County', 'United States', 'Washington', 'city', 'miles', 'Redmond', 'Seattle']
['cat', 'veterinarian']
['South America', 'summer']
"""
import os
import asyncio
class ExtractKeyPhrasesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def extract_key_phrases_async(self):
# [START batch_extract_key_phrases_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
"I need to take my cat to the veterinarian.",
"I will travel to South America in the summer.",
]
async with text_analytics_client:
result = await text_analytics_client.extract_key_phrases(documents)
for doc in result:
if not doc.is_error:
print(doc.key_phrases)
if doc.is_error:
print(doc.id, doc.error)
# [END batch_extract_key_phrases_async]
async def alternative_scenario_extract_key_phrases_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en",
"text": "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle."},
{"id": "1", "language": "en",
"text": "I need to take my cat to the veterinarian."},
{"id": "2", "language": "en", "text": "I will travel to South America in the summer."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.extract_key_phrases(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = ExtractKeyPhrasesSampleAsync()
await sample.extract_key_phrases_async()
await sample.alternative_scenario_extract_key_phrases_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,110 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_async.py
DESCRIPTION:
This sample demonstrates how to recognize named entities in a batch of documents.
USAGE:
python sample_recognize_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: Microsoft was founded by Bill Gates and Paul Allen.
Entity: Microsoft Type: Organization Confidence Score: 1.0
Entity: Bill Gates Type: Person Confidence Score: 1.0
Entity: Paul Allen Type: Person Confidence Score: 1.0
Document text: I had a wonderful trip to Seattle last week.
Entity: Seattle Type: Location Confidence Score: 0.806
Entity: last week Type: DateTime Confidence Score: 0.8
Document text: I visited the Space Needle 2 times.
Entity: Space Needle Type: Organization Confidence Score: 0.922
Entity: 2 Type: Quantity Confidence Score: 0.8
"""
import os
import asyncio
class RecognizeEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_entities_async(self):
# [START batch_recognize_entities_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Microsoft was founded by Bill Gates and Paul Allen.",
"I had a wonderful trip to Seattle last week.",
"I visited the Space Needle 2 times.",
]
async with text_analytics_client:
result = await text_analytics_client.recognize_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("\nDocument text: {}".format(documents[idx]))
for entity in doc.entities:
print("Entity: \t", entity.text, "\tType: \t", entity.type,
"\tConfidence Score: \t", round(entity.score, 3))
# [END batch_recognize_entities_async]
async def alternative_scenario_recognize_entities_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "Microsoft was founded by Bill Gates and Paul Allen."},
{"id": "1", "language": "de", "text": "I had a wonderful trip to Seattle last week."},
{"id": "2", "language": "es", "text": "I visited the Space Needle 2 times."},
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.recognize_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = RecognizeEntitiesSampleAsync()
await sample.recognize_entities_async()
await sample.alternative_scenario_recognize_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,177 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_linked_entities_async.py
DESCRIPTION:
This sample demonstrates how to detect linked entities in a batch of documents.
Each entity found in the document will have a link associated with it from a
data source.
USAGE:
python sample_recognize_linked_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: Microsoft moved its headquarters to Bellevue, Washington in January 1979.
Entity: Bellevue, Washington
Url: https://en.wikipedia.org/wiki/Bellevue,_Washington
Data Source: Wikipedia
Score: 0.698
Offset: 36
Length: 20
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.159
Offset: 0
Length: 9
Entity: January
Url: https://en.wikipedia.org/wiki/January
Data Source: Wikipedia
Score: 0.007
Offset: 60
Length: 7
------------------------------------------
Document text: Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.
Entity: Steve Ballmer
Url: https://en.wikipedia.org/wiki/Steve_Ballmer
Data Source: Wikipedia
Score: 0.672
Offset: 0
Length: 13
Entity: Satya Nadella
Url: https://en.wikipedia.org/wiki/Satya_Nadella
Data Source: Wikipedia
Score: 0.681
Offset: 68
Length: 13
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.164
Offset: 37
Length: 9
Entity: Chief executive officer
Url: https://en.wikipedia.org/wiki/Chief_executive_officer
Data Source: Wikipedia
Score: 0.074
Offset: 30
Length: 3
------------------------------------------
Document text: Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo.
Entity: Apple Inc.
Url: https://en.wikipedia.org/wiki/Apple_Inc.
Data Source: Wikipedia
Score: 0.677
Offset: 19
Length: 10
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.132
Offset: 0
Length: 9
------------------------------------------
"""
import os
import asyncio
class RecognizeLinkedEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_linked_entities_async(self):
# [START batch_recognize_linked_entities_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Microsoft moved its headquarters to Bellevue, Washington in January 1979.",
"Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.",
"Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo.",
]
async with text_analytics_client:
result = await text_analytics_client.recognize_linked_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}\n".format(documents[idx]))
for entity in doc.entities:
print("Entity: {}".format(entity.name))
print("Url: {}".format(entity.url))
print("Data Source: {}".format(entity.data_source))
for match in entity.matches:
print("Score: {0:.3f}".format(match.score))
print("Offset: {}".format(match.offset))
print("Length: {}\n".format(match.length))
print("------------------------------------------")
# [END batch_recognize_linked_entities_async]
async def alternative_scenario_recognize_linked_entities_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "Microsoft moved its headquarters to Bellevue, Washington in January 1979."},
{"id": "1", "language": "en", "text": "Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella."},
{"id": "2", "language": "es", "text": "Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo."},
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.recognize_linked_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = RecognizeLinkedEntitiesSampleAsync()
await sample.recognize_linked_entities_async()
await sample.alternative_scenario_recognize_linked_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,111 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_pii_entities_async.py
DESCRIPTION:
This sample demonstrates how to recognize personally identifiable information in a batch of documents.
USAGE:
python sample_recognize_pii_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: The employee's SSN is 555-55-5555.
Entity: 555-55-5555
Type: U.S. Social Security Number (SSN)
Confidence Score: 0.85
Document text: Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check.
Entity: 111000025
Type: ABA Routing Number
Confidence Score: 0.75
Document text: Is 998.214.865-68 your Brazilian CPF number?
Entity: 998.214.865-68
Type: Brazil CPF Number
Confidence Score: 0.85
"""
import os
import asyncio
class RecognizePiiEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_pii_entities_async(self):
# [START batch_recognize_pii_entities_async]
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"The employee's SSN is 555-55-5555.",
"Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check.",
"Is 998.214.865-68 your Brazilian CPF number?"
]
async with text_analytics_client:
result = await text_analytics_client.recognize_pii_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}".format(documents[idx]))
for entity in doc.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {}\n".format(entity.score))
# [END batch_recognize_pii_entities_async]
async def alternative_scenario_recognize_pii_entities_async(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics.aio import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "The employee's SSN is 555-55-5555."},
{"id": "1", "language": "en", "text": "Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check."},
{"id": "2", "language": "en", "text": "Is 998.214.865-68 your Brazilian CPF number?"}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
async with text_analytics_client:
result = await text_analytics_client.recognize_pii_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
async def main():
sample = RecognizePiiEntitiesSampleAsync()
await sample.recognize_pii_entities_async()
await sample.alternative_scenario_recognize_pii_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,94 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_analyze_sentiment_async.py
DESCRIPTION:
This sample demonstrates how to analyze sentiment from a single string.
An overall sentiment and a per-sentence sentiment is returned.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_analyze_sentiment_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Overall sentiment: mixed
Overall scores: positive=0.338; neutral=0.338; negative=0.338
Sentence 1 sentiment: neutral
Offset: 0
Length: 35
Sentence score: positive=0.006; neutral=0.006; negative=0.006
Sentence 2 sentiment: positive
Offset: 36
Length: 32
Sentence score: positive=0.999; neutral=0.999; negative=0.999
Sentence 3 sentiment: negative
Offset: 69
Length: 39
Sentence score: positive=0.010; neutral=0.010; negative=0.010
"""
import os
import asyncio
class SingleAnalyzeSentimentSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def analyze_sentiment_async(self):
# [START single_analyze_sentiment_async]
from azure.ai.textanalytics.aio import single_analyze_sentiment
text = "I visited the restaurant last week. The portions were very generous. However, I did not like what " \
"I ordered."
result = await single_analyze_sentiment(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
print("Overall sentiment: {}".format(result.sentiment))
print("Overall scores: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
result.document_scores.positive,
result.document_scores.neutral,
result.document_scores.negative,
))
for idx, sentence in enumerate(result.sentences):
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
print("Offset: {}".format(sentence.offset))
print("Length: {}".format(sentence.length))
print("Sentence score: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
sentence.sentence_scores.positive,
sentence.sentence_scores.neutral,
sentence.sentence_scores.negative,
))
# [END single_analyze_sentiment_async]
async def main():
sample = SingleAnalyzeSentimentSampleAsync()
await sample.analyze_sentiment_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,72 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_detect_language_async.py
DESCRIPTION:
This sample demonstrates how to detect the language of a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_detect_language_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Language detected: English
Confidence score: 1.0
Document Statistics:
Text character count: 42
Transactions count: 1
"""
import os
import asyncio
class SingleDetectLanguageSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def detect_language_async(self):
# [START single_detect_language_async]
from azure.ai.textanalytics.aio import single_detect_language
text = "I need to take my cat to the veterinarian."
result = await single_detect_language(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
country_hint="US",
show_stats=True
)
print("Language detected: {}".format(result.detected_languages[0].name))
print("Confidence score: {}\n".format(result.detected_languages[0].score))
print("Document Statistics:")
print("Text character count: {}".format(result.statistics.character_count))
print("Transactions count: {}".format(result.statistics.transaction_count))
# [END single_detect_language_async]
async def main():
sample = SingleDetectLanguageSampleAsync()
await sample.detect_language_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,72 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_extract_key_phrases_async.py
DESCRIPTION:
This sample demonstrates how to extract key phrases from a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_extract_key_phrases_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Key phrases found:
King County
United States
Washington
city
miles
Redmond
Seattle
"""
import os
import asyncio
class SingleExtractKeyPhrasesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def extract_key_phrases_async(self):
# [START single_extract_key_phrases_async]
from azure.ai.textanalytics.aio import single_extract_key_phrases
text = "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle."
result = await single_extract_key_phrases(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
print("Key phrases found:\n")
for phrase in result.key_phrases:
print(phrase)
# [END single_extract_key_phrases_async]
async def main():
sample = SingleExtractKeyPhrasesSampleAsync()
await sample.extract_key_phrases_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,88 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_entities_async.py
DESCRIPTION:
This sample demonstrates how to recognize entities in a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: Microsoft
Type: Organization
Confidence Score: 1.000
Entity: Bill Gates
Type: Person
Confidence Score: 1.000
Entity: Paul Allen
Type: Person
Confidence Score: 0.999
Entity: April 4, 1975
Type: DateTime
Confidence Score: 0.800
Entity: Altair
Type: Organization
Confidence Score: 0.525
Entity: 8800
Type: Quantity
Confidence Score: 0.80
"""
import os
import asyncio
class SingleRecognizeEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_entities_async(self):
# [START single_recognize_entities_async]
from azure.ai.textanalytics.aio import single_recognize_entities
text = "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975," \
" to develop and sell BASIC interpreters for the Altair 8800."
result = await single_recognize_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {0:.3f}\n".format(entity.score))
# [END single_recognize_entities_async]
async def main():
sample = SingleRecognizeEntitiesSampleAsync()
await sample.recognize_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,107 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_linked_entities_async.py
DESCRIPTION:
This sample demonstrates how to recognize entities in a single string
and returns links to the entities from a well-known knowledge base.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_linked_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: Easter Island
Url: https://en.wikipedia.org/wiki/Easter_Island
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Easter Island
Score: 0.272
Offset: 0
Length: 13
Match 2: Rapa Nui
Score: 0.054
Offset: 97
Length: 8
Entity: Polynesia
Url: https://en.wikipedia.org/wiki/Polynesia
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Polynesia
Score: 0.163
Offset: 67
Length: 9
Entity: Chile
Url: https://en.wikipedia.org/wiki/Chile
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Chilean
Score: 0.045
Offset: 17
Length: 7
"""
import os
import asyncio
class SingleRecognizeLinkedEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_linked_entities_async(self):
# [START single_recognize_linked_entities_async]
from azure.ai.textanalytics.aio import single_recognize_linked_entities
text = "Easter Island, a Chilean territory, is a remote volcanic island in Polynesia. " \
"Its native name is Rapa Nui."
result = await single_recognize_linked_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.name))
print("Url: {}".format(entity.url))
print("Data Source: {}\n".format(entity.data_source))
print("Where this entity appears in the text:")
for idx, match in enumerate(entity.matches):
print("Match {}: {}".format(idx+1, match.text))
print("Score: {0:.3f}".format(match.score))
print("Offset: {}".format(match.offset))
print("Length: {}\n".format(match.length))
# [END single_recognize_linked_entities_async]
async def main():
sample = SingleRecognizeLinkedEntitiesSampleAsync()
await sample.recognize_linked_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,73 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_pii_entities_async.py
DESCRIPTION:
This sample demonstrates how to recognize personally identifiable
information in a single string. For the list of supported entity types,
see https://aka.ms/tanerpii
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_pii_entities_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: 111000025
Type: ABA Routing Number
Confidence Score: 0.75
Entity: 555-55-5555
Type: U.S. Social Security Number (SSN)
Confidence Score: 0.85
"""
import os
import asyncio
class SingleRecognizePiiEntitiesSampleAsync(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
async def recognize_pii_entities_async(self):
# [START single_recognize_pii_entities_async]
from azure.ai.textanalytics.aio import single_recognize_pii_entities
text = "The employee's ABA number is 111000025 and his SSN is 555-55-5555."
result = await single_recognize_pii_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {}\n".format(entity.score))
# [END single_recognize_pii_entities_async]
async def main():
sample = SingleRecognizePiiEntitiesSampleAsync()
await sample.recognize_pii_entities_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Просмотреть файл

@ -0,0 +1,157 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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.py
DESCRIPTION:
This sample demonstrates how to analyze sentiment in a batch of documents.
An overall and per-sentence sentiment is returned.
USAGE:
python sample_analyze_sentiment.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: I had the best day of my life.
Overall sentiment: positive
Overall scores: positive=0.999; neutral=0.999; negative=0.999
Sentence 1 sentiment: positive
Sentence score: positive=0.999; neutral=0.999; negative=0.999
Offset: 0
Length: 30
------------------------------------
Document text: This was a waste of my time. The speaker put me to sleep.
Overall sentiment: negative
Overall scores: positive=0.061; neutral=0.061; negative=0.061
Sentence 1 sentiment: negative
Sentence score: positive=0.000; neutral=0.000; negative=0.000
Offset: 0
Length: 28
Sentence 2 sentiment: neutral
Sentence score: positive=0.122; neutral=0.122; negative=0.122
Offset: 29
Length: 28
------------------------------------
Document text: No tengo dinero ni nada que dar...
Overall sentiment: negative
Overall scores: positive=0.026; neutral=0.026; negative=0.026
Sentence 1 sentiment: negative
Sentence score: positive=0.026; neutral=0.026; negative=0.026
Offset: 0
Length: 34
------------------------------------
Document text: L'hôtel n'était pas très confortable. L'éclairage était trop sombre.
Overall sentiment: negative
Overall scores: positive=0.165; neutral=0.165; negative=0.165
Sentence 1 sentiment: negative
Sentence score: positive=0.186; neutral=0.186; negative=0.186
Offset: 0
Length: 37
Sentence 2 sentiment: negative
Sentence score: positive=0.143; neutral=0.143; negative=0.143
Offset: 38
Length: 30
------------------------------------
"""
import os
class AnalyzeSentimentSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def analyze_sentiment(self):
# [START batch_analyze_sentiment]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"I had the best day of my life.",
"This was a waste of my time. The speaker put me to sleep.",
"No tengo dinero ni nada que dar...",
"L'hôtel n'était pas très confortable. L'éclairage était trop sombre."
]
result = text_analytics_client.analyze_sentiment(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}".format(documents[idx]))
print("Overall sentiment: {}".format(doc.sentiment))
# [END batch_analyze_sentiment]
print("Overall scores: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
doc.document_scores.positive,
doc.document_scores.neutral,
doc.document_scores.negative,
))
for idx, sentence in enumerate(doc.sentences):
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
print("Sentence score: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f}".format(
sentence.sentence_scores.positive,
sentence.sentence_scores.neutral,
sentence.sentence_scores.negative,
))
print("Offset: {}".format(sentence.offset))
print("Length: {}\n".format(sentence.length))
print("------------------------------------")
def alternative_scenario_analyze_sentiment(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "I had the best day of my life."},
{"id": "1", "language": "en",
"text": "This was a waste of my time. The speaker put me to sleep."},
{"id": "2", "language": "es", "text": "No tengo dinero ni nada que dar..."},
{"id": "3", "language": "fr",
"text": "L'hôtel n'était pas très confortable. L'éclairage était trop sombre."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.analyze_sentiment(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = AnalyzeSentimentSample()
sample.analyze_sentiment()
sample.alternative_scenario_analyze_sentiment()

Просмотреть файл

@ -0,0 +1,77 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_authentication.py
DESCRIPTION:
This sample demonstrates how to authenticate with the text analytics service.
There are two supported methods of authentication:
1) Use a cognitive services subscription key
2) Use a token credential to authenticate with Azure Active Directory
See more details about authentication here:
https://docs.microsoft.com/azure/cognitive-services/authentication
USAGE:
python sample_authentication.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
3) AZURE_CLIENT_ID - the client ID of your active directory application.
4) AZURE_TENANT_ID - the tenant ID of your active directory application.
5) AZURE_CLIENT_SECRET - the secret of your active directory application.
"""
import os
class AuthenticationSample(object):
def authentication_with_subscription_key(self):
# [START create_ta_client_with_key]
from azure.ai.textanalytics import TextAnalyticsClient
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
text_analytics_client = TextAnalyticsClient(endpoint, key)
# [END create_ta_client_with_key]
doc = ["I need to take my cat to the veterinarian."]
result = text_analytics_client.detect_languages(doc)
print("Language detected: {}".format(result[0].detected_languages[0].name))
print("Confidence score: {}".format(result[0].detected_languages[0].score))
def authentication_with_azure_active_directory(self):
"""DefaultAzureCredential will use the values from the environment
variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
"""
# [START create_ta_client_with_aad]
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import DefaultAzureCredential
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
credential = DefaultAzureCredential()
text_analytics_client = TextAnalyticsClient(endpoint, credential=credential)
# [END create_ta_client_with_aad]
doc = ["I need to take my cat to the veterinarian."]
result = text_analytics_client.detect_languages(doc)
print("Language detected: {}".format(result[0].detected_languages[0].name))
print("Confidence score: {}".format(result[0].detected_languages[0].score))
if __name__ == '__main__':
sample = AuthenticationSample()
sample.authentication_with_subscription_key()
sample.authentication_with_azure_active_directory()

Просмотреть файл

@ -0,0 +1,119 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_detect_languages.py
DESCRIPTION:
This sample demonstrates how to detect language in a batch of different
documents.
USAGE:
python sample_detect_languages.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: This is a document written in English.
Language detected: English
ISO6391 name: en
Confidence score: 1.0
Document text: Este es un document escrito en Español.
Language detected: Spanish
ISO6391 name: es
Confidence score: 1.0
Document text: 这是一个用中文写的文件
Language detected: Chinese_Simplified
ISO6391 name: zh_chs
Confidence score: 1.0
Document text: Dies ist ein Dokument in englischer Sprache.
Language detected: German
ISO6391 name: de
Confidence score: 1.0
Document text: Detta är ett dokument skrivet engelska.
Language detected: Swedish
ISO6391 name: sv
Confidence score: 1.0
"""
import os
class DetectLanguagesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def detect_languages(self):
# [START batch_detect_languages]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"This document is written in English.",
"Este es un document escrito en Español.",
"这是一个用中文写的文件",
"Dies ist ein Dokument in englischer Sprache.",
"Detta är ett dokument skrivet på engelska."
]
result = text_analytics_client.detect_languages(documents)
for idx, doc in enumerate(result):
if not doc.is_error:
print("Document text: {}".format(documents[idx]))
print("Language detected: {}".format(doc.detected_languages[0].name))
print("ISO6391 name: {}".format(doc.detected_languages[0].iso6391_name))
print("Confidence score: {}\n".format(doc.detected_languages[0].score))
if doc.is_error:
print(doc.id, doc.error)
# [END batch_detect_languages]
def alternative_scenario_detect_languages(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[DetectLanguageInput] and supplying your own IDs and country hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "country_hint": "US", "text": "This is a document written in English."},
{"id": "1", "country_hint": "MX", "text": "Este es un document escrito en Español."},
{"id": "2", "country_hint": "CN", "text": "这是一个用中文写的文件"},
{"id": "3", "country_hint": "DE", "text": "Dies ist ein Dokument in englischer Sprache."},
{"id": "4", "country_hint": "SE", "text": "Detta är ett dokument skrivet på engelska."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.detect_languages(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = DetectLanguagesSample()
sample.detect_languages()
sample.alternative_scenario_detect_languages()

Просмотреть файл

@ -0,0 +1,90 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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.py
DESCRIPTION:
This sample demonstrates how to extract key talking points from a batch of documents.
USAGE:
python sample_extract_key_phrases.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
['King County', 'United States', 'Washington', 'city', 'miles', 'Redmond', 'Seattle']
['cat', 'veterinarian']
['South America', 'summer']
"""
import os
class ExtractKeyPhrasesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def extract_key_phrases(self):
# [START batch_extract_key_phrases]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
"I need to take my cat to the veterinarian.",
"I will travel to South America in the summer.",
]
result = text_analytics_client.extract_key_phrases(documents)
for doc in result:
if not doc.is_error:
print(doc.key_phrases)
if doc.is_error:
print(doc.id, doc.error)
# [END batch_extract_key_phrases]
def alternative_scenario_extract_key_phrases(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en",
"text": "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle."},
{"id": "1", "language": "en",
"text": "I need to take my cat to the veterinarian."},
{"id": "2", "language": "en", "text": "I will travel to South America in the summer."}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.extract_key_phrases(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = ExtractKeyPhrasesSample()
sample.extract_key_phrases()
sample.alternative_scenario_extract_key_phrases()

Просмотреть файл

@ -0,0 +1,100 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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.py
DESCRIPTION:
This sample demonstrates how to recognize named entities in a batch of documents.
USAGE:
python sample_recognize_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: Microsoft was founded by Bill Gates and Paul Allen.
Entity: Microsoft Type: Organization Confidence Score: 1.0
Entity: Bill Gates Type: Person Confidence Score: 1.0
Entity: Paul Allen Type: Person Confidence Score: 1.0
Document text: I had a wonderful trip to Seattle last week.
Entity: Seattle Type: Location Confidence Score: 0.806
Entity: last week Type: DateTime Confidence Score: 0.8
Document text: I visited the Space Needle 2 times.
Entity: Space Needle Type: Organization Confidence Score: 0.922
Entity: 2 Type: Quantity Confidence Score: 0.8
"""
import os
class RecognizeEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_entities(self):
# [START batch_recognize_entities]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Microsoft was founded by Bill Gates and Paul Allen.",
"I had a wonderful trip to Seattle last week.",
"I visited the Space Needle 2 times.",
]
result = text_analytics_client.recognize_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("\nDocument text: {}".format(documents[idx]))
for entity in doc.entities:
print("Entity: \t", entity.text, "\tType: \t", entity.type,
"\tConfidence Score: \t", round(entity.score, 3))
# [END batch_recognize_entities]
def alternative_scenario_recognize_entities(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "Microsoft was founded by Bill Gates and Paul Allen."},
{"id": "1", "language": "de", "text": "I had a wonderful trip to Seattle last week."},
{"id": "2", "language": "es", "text": "I visited the Space Needle 2 times."},
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.recognize_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = RecognizeEntitiesSample()
sample.recognize_entities()
sample.alternative_scenario_recognize_entities()

Просмотреть файл

@ -0,0 +1,169 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_linked_entities.py
DESCRIPTION:
This sample demonstrates how to detect linked entities in a batch of documents.
Each entity found in the document will have a link associated with it from a
data source.
USAGE:
python sample_recognize_linked_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: Microsoft moved its headquarters to Bellevue, Washington in January 1979.
Entity: Bellevue, Washington
Url: https://en.wikipedia.org/wiki/Bellevue,_Washington
Data Source: Wikipedia
Score: 0.698
Offset: 36
Length: 20
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.159
Offset: 0
Length: 9
Entity: January
Url: https://en.wikipedia.org/wiki/January
Data Source: Wikipedia
Score: 0.007
Offset: 60
Length: 7
------------------------------------------
Document text: Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.
Entity: Steve Ballmer
Url: https://en.wikipedia.org/wiki/Steve_Ballmer
Data Source: Wikipedia
Score: 0.672
Offset: 0
Length: 13
Entity: Satya Nadella
Url: https://en.wikipedia.org/wiki/Satya_Nadella
Data Source: Wikipedia
Score: 0.681
Offset: 68
Length: 13
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.164
Offset: 37
Length: 9
Entity: Chief executive officer
Url: https://en.wikipedia.org/wiki/Chief_executive_officer
Data Source: Wikipedia
Score: 0.074
Offset: 30
Length: 3
------------------------------------------
Document text: Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo.
Entity: Apple Inc.
Url: https://en.wikipedia.org/wiki/Apple_Inc.
Data Source: Wikipedia
Score: 0.677
Offset: 19
Length: 10
Entity: Microsoft
Url: https://en.wikipedia.org/wiki/Microsoft
Data Source: Wikipedia
Score: 0.132
Offset: 0
Length: 9
------------------------------------------
"""
import os
class RecognizeLinkedEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_linked_entities(self):
# [START batch_recognize_linked_entities]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"Microsoft moved its headquarters to Bellevue, Washington in January 1979.",
"Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.",
"Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo.",
]
result = text_analytics_client.recognize_linked_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}\n".format(documents[idx]))
for entity in doc.entities:
print("Entity: {}".format(entity.name))
print("Url: {}".format(entity.url))
print("Data Source: {}".format(entity.data_source))
for match in entity.matches:
print("Score: {0:.3f}".format(match.score))
print("Offset: {}".format(match.offset))
print("Length: {}\n".format(match.length))
print("------------------------------------------")
# [END batch_recognize_linked_entities]
def alternative_scenario_recognize_linked_entities(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "Microsoft moved its headquarters to Bellevue, Washington in January 1979."},
{"id": "1", "language": "en", "text": "Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella."},
{"id": "2", "language": "es", "text": "Microsoft superó a Apple Inc. como la compañía más valiosa que cotiza en bolsa en el mundo."},
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.recognize_linked_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = RecognizeLinkedEntitiesSample()
sample.recognize_linked_entities()
sample.alternative_scenario_recognize_linked_entities()

Просмотреть файл

@ -0,0 +1,103 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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_pii_entities.py
DESCRIPTION:
This sample demonstrates how to recognize personally identifiable information in a batch of documents.
USAGE:
python sample_recognize_pii_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Document text: The employee's SSN is 555-55-5555.
Entity: 555-55-5555
Type: U.S. Social Security Number (SSN)
Confidence Score: 0.85
Document text: Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check.
Entity: 111000025
Type: ABA Routing Number
Confidence Score: 0.75
Document text: Is 998.214.865-68 your Brazilian CPF number?
Entity: 998.214.865-68
Type: Brazil CPF Number
Confidence Score: 0.85
"""
import os
class RecognizePiiEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_pii_entities(self):
# [START batch_recognize_pii_entities]
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
"The employee's SSN is 555-55-5555.",
"Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check.",
"Is 998.214.865-68 your Brazilian CPF number?"
]
result = text_analytics_client.recognize_pii_entities(documents)
docs = [doc for doc in result if not doc.is_error]
for idx, doc in enumerate(docs):
print("Document text: {}".format(documents[idx]))
for entity in doc.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {}\n".format(entity.score))
# [END batch_recognize_pii_entities]
def alternative_scenario_recognize_pii_entities(self):
"""This sample demonstrates how to retrieve batch statistics, the
model version used, and the raw response returned from the service.
It additionally shows an alternative way to pass in the input documents
using a list[TextDocumentInput] and supplying your own IDs and language hints along
with the text.
"""
from azure.ai.textanalytics import TextAnalyticsClient
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=self.key)
documents = [
{"id": "0", "language": "en", "text": "The employee's SSN is 555-55-5555."},
{"id": "1", "language": "en", "text": "Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check."},
{"id": "2", "language": "en", "text": "Is 998.214.865-68 your Brazilian CPF number?"}
]
extras = []
def callback(resp):
extras.append(resp.statistics)
extras.append(resp.model_version)
extras.append(resp.raw_response)
result = text_analytics_client.recognize_pii_entities(
documents,
show_stats=True,
model_version="latest",
response_hook=callback
)
if __name__ == '__main__':
sample = RecognizePiiEntitiesSample()
sample.recognize_pii_entities()
sample.alternative_scenario_recognize_pii_entities()

Просмотреть файл

@ -0,0 +1,91 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_analyze_sentiment.py
DESCRIPTION:
This sample demonstrates how to analyze sentiment from a single string.
An overall sentiment and a per-sentence sentiment is returned.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_analyze_sentiment.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Overall sentiment: mixed
Overall scores: positive=0.338; neutral=0.338; negative=0.338
Sentence 1 sentiment: neutral
Offset: 0
Length: 35
Sentence score: positive=0.006; neutral=0.006; negative=0.006
Sentence 2 sentiment: positive
Offset: 36
Length: 32
Sentence score: positive=0.999; neutral=0.999; negative=0.999
Sentence 3 sentiment: negative
Offset: 69
Length: 39
Sentence score: positive=0.010; neutral=0.010; negative=0.010
"""
import os
class SingleAnalyzeSentimentSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def analyze_sentiment(self):
# [START single_analyze_sentiment]
from azure.ai.textanalytics import single_analyze_sentiment
text = "I visited the restaurant last week. The portions were very generous. However, I did not like what " \
"I ordered."
result = single_analyze_sentiment(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
print("Overall sentiment: {}".format(result.sentiment))
print("Overall scores: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
result.document_scores.positive,
result.document_scores.neutral,
result.document_scores.negative,
))
for idx, sentence in enumerate(result.sentences):
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
print("Offset: {}".format(sentence.offset))
print("Length: {}".format(sentence.length))
print("Sentence score: positive={0:.3f}; neutral={0:.3f}; negative={0:.3f} \n".format(
sentence.sentence_scores.positive,
sentence.sentence_scores.neutral,
sentence.sentence_scores.negative,
))
# [END single_analyze_sentiment]
if __name__ == '__main__':
sample = SingleAnalyzeSentimentSample()
sample.analyze_sentiment()

Просмотреть файл

@ -0,0 +1,67 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_detect_language.py
DESCRIPTION:
This sample demonstrates how to detect the language of a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_detect_language.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Language detected: English
Confidence score: 1.0
Document Statistics:
Text character count: 42
Transactions count: 1
"""
import os
class SingleDetectLanguageSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def detect_language(self):
# [START single_detect_language]
from azure.ai.textanalytics import single_detect_language
text = "I need to take my cat to the veterinarian."
result = single_detect_language(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
country_hint="US",
show_stats=True
)
print("Language detected: {}".format(result.detected_languages[0].name))
print("Confidence score: {}\n".format(result.detected_languages[0].score))
print("Document Statistics:")
print("Text character count: {}".format(result.statistics.character_count))
print("Transactions count: {}".format(result.statistics.transaction_count))
# [END single_detect_language]
if __name__ == '__main__':
sample = SingleDetectLanguageSample()
sample.detect_language()

Просмотреть файл

@ -0,0 +1,67 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_extract_key_phrases.py
DESCRIPTION:
This sample demonstrates how to extract key phrases from a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_extract_key_phrases.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Key phrases found:
King County
United States
Washington
city
miles
Redmond
Seattle
"""
import os
class SingleExtractKeyPhrasesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def extract_key_phrases(self):
# [START single_extract_key_phrases]
from azure.ai.textanalytics import single_extract_key_phrases
text = "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle."
result = single_extract_key_phrases(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
print("Key phrases found:\n")
for phrase in result.key_phrases:
print(phrase)
# [END single_extract_key_phrases]
if __name__ == '__main__':
sample = SingleExtractKeyPhrasesSample()
sample.extract_key_phrases()

Просмотреть файл

@ -0,0 +1,84 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_entities.py
DESCRIPTION:
This sample demonstrates how to recognize entities in a single string.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: Microsoft
Type: Organization
Confidence Score: 1.000
Entity: Bill Gates
Type: Person
Confidence Score: 1.000
Entity: Paul Allen
Type: Person
Confidence Score: 0.999
Entity: April 4, 1975
Type: DateTime
Confidence Score: 0.800
Entity: Altair
Type: Organization
Confidence Score: 0.525
Entity: 8800
Type: Quantity
Confidence Score: 0.80
"""
import os
class SingleRecognizeEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_entities(self):
# [START single_recognize_entities]
from azure.ai.textanalytics import single_recognize_entities
text = "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975," \
" to develop and sell BASIC interpreters for the Altair 8800."
result = single_recognize_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {0:.3f}\n".format(entity.score))
# [END single_recognize_entities]
if __name__ == '__main__':
sample = SingleRecognizeEntitiesSample()
sample.recognize_entities()

Просмотреть файл

@ -0,0 +1,102 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_linked_entities.py
DESCRIPTION:
This sample demonstrates how to recognize entities in a single string
and returns links to the entities from a well-known knowledge base.
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_linked_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: Easter Island
Url: https://en.wikipedia.org/wiki/Easter_Island
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Easter Island
Score: 0.272
Offset: 0
Length: 13
Match 2: Rapa Nui
Score: 0.054
Offset: 97
Length: 8
Entity: Polynesia
Url: https://en.wikipedia.org/wiki/Polynesia
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Polynesia
Score: 0.163
Offset: 67
Length: 9
Entity: Chile
Url: https://en.wikipedia.org/wiki/Chile
Data Source: Wikipedia
Where this entity appears in the text:
Match 1: Chilean
Score: 0.045
Offset: 17
Length: 7
"""
import os
class SingleRecognizeLinkedEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_linked_entities(self):
# [START single_recognize_linked_entities]
from azure.ai.textanalytics import single_recognize_linked_entities
text = "Easter Island, a Chilean territory, is a remote volcanic island in Polynesia. " \
"Its native name is Rapa Nui."
result = single_recognize_linked_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.name))
print("Url: {}".format(entity.url))
print("Data Source: {}\n".format(entity.data_source))
print("Where this entity appears in the text:")
for idx, match in enumerate(entity.matches):
print("Match {}: {}".format(idx+1, match.text))
print("Score: {0:.3f}".format(match.score))
print("Offset: {}".format(match.offset))
print("Length: {}\n".format(match.length))
# [END single_recognize_linked_entities]
if __name__ == '__main__':
sample = SingleRecognizeLinkedEntitiesSample()
sample.recognize_linked_entities()

Просмотреть файл

@ -0,0 +1,68 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_single_recognize_pii_entities.py
DESCRIPTION:
This sample demonstrates how to recognize personally identifiable
information in a single string. For the list of supported entity types,
see https://aka.ms/tanerpii
This module-level, single method is meant to be used as an introduction
for new users of the text analytics service. For optimum use of the service,
use the methods that support batching documents.
USAGE:
python sample_single_recognize_pii_entities.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your cognitive services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your text analytics subscription key
OUTPUT:
Entity: 111000025
Type: ABA Routing Number
Confidence Score: 0.75
Entity: 555-55-5555
Type: U.S. Social Security Number (SSN)
Confidence Score: 0.85
"""
import os
class SingleRecognizePiiEntitiesSample(object):
endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")
def recognize_pii_entities(self):
# [START single_recognize_pii_entities]
from azure.ai.textanalytics import single_recognize_pii_entities
text = "The employee's ABA number is 111000025 and his SSN is 555-55-5555."
result = single_recognize_pii_entities(
endpoint=self.endpoint,
credential=self.key,
input_text=text,
language="en"
)
for entity in result.entities:
print("Entity: {}".format(entity.text))
print("Type: {}".format(entity.type))
print("Confidence Score: {}\n".format(entity.score))
# [END single_recognize_pii_entities]
if __name__ == '__main__':
sample = SingleRecognizePiiEntitiesSample()
sample.recognize_pii_entities()

Просмотреть файл

@ -0,0 +1,8 @@
[packaging]
package_name = "azure-ai-textanalytics"
package_nspkg = "azure-ai-nspkg"
package_pprint_name = "Azure Text Analytics"
package_doc_id = ""
is_stable = false
is_arm = false
need_msrestazure = false

Просмотреть файл

@ -0,0 +1,2 @@
[bdist_wheel]
universal=1

Просмотреть файл

@ -0,0 +1,90 @@
#!/usr/bin/env python
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------
import re
import os.path
from io import open
from setuptools import find_packages, setup
# Change the PACKAGE_NAME only to change folder and different name
PACKAGE_NAME = "azure-ai-textanalytics"
PACKAGE_PPRINT_NAME = "Azure Text Analytics"
# a-b-c => a/b/c
package_folder_path = PACKAGE_NAME.replace('-', '/')
# a-b-c => a.b.c
namespace_name = PACKAGE_NAME.replace('-', '.')
# azure v0.x is not compatible with this package
# azure v0.x used to have a __version__ attribute (newer versions don't)
try:
import azure
try:
ver = azure.__version__
raise Exception(
'This package is incompatible with azure=={}. '.format(ver) +
'Uninstall it with "pip uninstall azure".'
)
except AttributeError:
pass
except ImportError:
pass
# Version extraction inspired from 'requests'
with open(os.path.join(package_folder_path, '_version.py'), 'r') as fd:
version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)
if not version:
raise RuntimeError('Cannot find version information')
with open('README.md', encoding='utf-8') as f:
readme = f.read()
with open('HISTORY.md', encoding='utf-8') as f:
history = f.read()
setup(
name=PACKAGE_NAME,
version=version,
description='Microsoft {} Client Library for Python'.format(PACKAGE_PPRINT_NAME),
long_description=readme + "\n\n" + history,
long_description_content_type='text/markdown',
license='MIT License',
author='Microsoft Corporation',
author_email='azpysdkhelp@microsoft.com',
url='https://github.com/Azure/azure-sdk-for-python',
classifiers=[
'Development Status :: 4 - Beta',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
],
zip_safe=False,
packages=find_packages(exclude=[
'tests',
# Exclude packages that will be covered by PEP420 or nspkg
'azure',
'azure.ai',
]),
install_requires=[
"azure-core<2.0.0,>=1.1.0",
"msrest>=0.6.0",
'azure-common~=1.1',
'six>=1.6',
],
extras_require={
":python_version<'3.0'": ['azure-ai-nspkg'],
":python_version<'3.5'": ['typing'],
}
)

Просмотреть файл

@ -0,0 +1,56 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import asyncio
import functools
from devtools_testutils.cognitiveservices_testcase import CognitiveServiceTest
from azure.core.credentials import AccessToken
LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'
class AsyncFakeTokenCredential(object):
"""Protocol for classes able to provide OAuth tokens.
:param str scopes: Lets you specify the type of access needed.
"""
def __init__(self):
self.token = AccessToken("YOU SHALL NOT PASS", 0)
async def get_token(self, *args):
return self.token
class AsyncCognitiveServiceTestCase(CognitiveServiceTest):
@staticmethod
def await_prepared_test(test_fn):
"""Synchronous wrapper for async test methods. Used to avoid making changes
upstream to AbstractPreparer (which doesn't await the functions it wraps)
"""
@functools.wraps(test_fn)
def run(test_class_instance, *args, **kwargs):
loop = asyncio.get_event_loop()
return loop.run_until_complete(test_fn(test_class_instance, **kwargs))
return run
def get_oauth_endpoint(self):
return self.get_settings_value("TEXT_ANALYTICS_ACCOUNT_NAME")
def generate_oauth_token(self):
if self.is_live:
from azure.identity.aio import ClientSecretCredential
return ClientSecretCredential(
self.get_settings_value("AZURE_TENANT_ID"),
self.get_settings_value("AZURE_CLIENT_ID"),
self.get_settings_value("AZURE_CLIENT_SECRET"),
)
return self.generate_fake_token()
def generate_fake_token(self):
return AsyncFakeTokenCredential()

Просмотреть файл

@ -0,0 +1,52 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "", "language": "en"}, {"id": "2", "text":
"I did not like the hotel we stayed it. It was too expensive.", "language":
"english"}, {"id": "3", "text": "", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '209'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: de,en,es,fr,it,ja,nl,pt-PT,zh-Hans,zh-Hant"},"message":"Invalid
Language Code."}},{"id":"3","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 37146e18-1cea-4e45-a33b-19904d0229dd
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=0
date:
- Fri, 15 Nov 2019 19:47:01 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- c761a44f-dda3-4df6-9c3a-c7b455b1e21d
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '6'
status:
code: 200
message: OK
version: 1

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,51 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen", "language": "English"}, {"id": "2", "text": "", "language":
"es"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '156'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/keyPhrases?showStats=false
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: da,de,en,es,fi,fr,it,ja,ko,nl,no,pl,pt-BR,pt-PT,ru,sv"},"message":"Invalid
Language Code."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 05b3e2b4-cbf8-41c0-85e7-160838ab97ca
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=0
date:
- Thu, 14 Nov 2019 21:38:55 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- b48e96ce-aa34-4664-a79f-b10d671f4961
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '564'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": ""}, {"id": "2", "text": "Hola", "language":
"Spanish"}, {"id": "3", "text": "", "language": "de"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '135'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: ar,cs,da,de,en,es,fi,fr,hu,it,ja,ko,nl,no,pl,pt-BR,pt-PT,ru,sv,tr,zh-Hans"},"message":"Invalid
Language Code."}},{"id":"3","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 8cb4d850-0e5e-481b-bac8-5b9d7a992b0b
content-type:
- application/json; charset=utf-8
date:
- Mon, 18 Nov 2019 17:03:07 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- db27920c-554c-490c-aa7d-060fad4b755f
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '7'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,48 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": ""}, {"id": "2", "text": "Microsoft
fue fundado por Bill Gates y Paul Allen", "language": "Spanish"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '137'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/linking?showStats=false
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: en,es"},"message":"Invalid Language
Code."}}],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 791b3a3c-9387-4d9c-821c-c08d336fb65e
content-type:
- application/json; charset=utf-8
date:
- Mon, 18 Nov 2019 17:04:06 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 5af4cc62-8fbe-45f4-baa5-b6052cbf96e7
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '20'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,47 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "hola", "language": "es"}, {"id": "2",
"text": ""}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '87'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/pii?showStats=false
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: en"},"message":"Invalid Language Code."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 2e89973b-e734-4e2c-b907-10ff1aab2492
content-type:
- application/json; charset=utf-8
date:
- Mon, 18 Nov 2019 17:03:36 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 4b24f056-0635-4855-a4b9-7002c1af6272
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '17'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,566 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "hello world"}, {"id": "1", "text":
"hello world"}, {"id": "2", "text": "hello world"}, {"id": "3", "text": "hello
world"}, {"id": "4", "text": "hello world"}, {"id": "5", "text": "hello world"},
{"id": "6", "text": "hello world"}, {"id": "7", "text": "hello world"}, {"id":
"8", "text": "hello world"}, {"id": "9", "text": "hello world"}, {"id": "10",
"text": "hello world"}, {"id": "11", "text": "hello world"}, {"id": "12", "text":
"hello world"}, {"id": "13", "text": "hello world"}, {"id": "14", "text": "hello
world"}, {"id": "15", "text": "hello world"}, {"id": "16", "text": "hello world"},
{"id": "17", "text": "hello world"}, {"id": "18", "text": "hello world"}, {"id":
"19", "text": "hello world"}, {"id": "20", "text": "hello world"}, {"id": "21",
"text": "hello world"}, {"id": "22", "text": "hello world"}, {"id": "23", "text":
"hello world"}, {"id": "24", "text": "hello world"}, {"id": "25", "text": "hello
world"}, {"id": "26", "text": "hello world"}, {"id": "27", "text": "hello world"},
{"id": "28", "text": "hello world"}, {"id": "29", "text": "hello world"}, {"id":
"30", "text": "hello world"}, {"id": "31", "text": "hello world"}, {"id": "32",
"text": "hello world"}, {"id": "33", "text": "hello world"}, {"id": "34", "text":
"hello world"}, {"id": "35", "text": "hello world"}, {"id": "36", "text": "hello
world"}, {"id": "37", "text": "hello world"}, {"id": "38", "text": "hello world"},
{"id": "39", "text": "hello world"}, {"id": "40", "text": "hello world"}, {"id":
"41", "text": "hello world"}, {"id": "42", "text": "hello world"}, {"id": "43",
"text": "hello world"}, {"id": "44", "text": "hello world"}, {"id": "45", "text":
"hello world"}, {"id": "46", "text": "hello world"}, {"id": "47", "text": "hello
world"}, {"id": "48", "text": "hello world"}, {"id": "49", "text": "hello world"},
{"id": "50", "text": "hello world"}, {"id": "51", "text": "hello world"}, {"id":
"52", "text": "hello world"}, {"id": "53", "text": "hello world"}, {"id": "54",
"text": "hello world"}, {"id": "55", "text": "hello world"}, {"id": "56", "text":
"hello world"}, {"id": "57", "text": "hello world"}, {"id": "58", "text": "hello
world"}, {"id": "59", "text": "hello world"}, {"id": "60", "text": "hello world"},
{"id": "61", "text": "hello world"}, {"id": "62", "text": "hello world"}, {"id":
"63", "text": "hello world"}, {"id": "64", "text": "hello world"}, {"id": "65",
"text": "hello world"}, {"id": "66", "text": "hello world"}, {"id": "67", "text":
"hello world"}, {"id": "68", "text": "hello world"}, {"id": "69", "text": "hello
world"}, {"id": "70", "text": "hello world"}, {"id": "71", "text": "hello world"},
{"id": "72", "text": "hello world"}, {"id": "73", "text": "hello world"}, {"id":
"74", "text": "hello world"}, {"id": "75", "text": "hello world"}, {"id": "76",
"text": "hello world"}, {"id": "77", "text": "hello world"}, {"id": "78", "text":
"hello world"}, {"id": "79", "text": "hello world"}, {"id": "80", "text": "hello
world"}, {"id": "81", "text": "hello world"}, {"id": "82", "text": "hello world"},
{"id": "83", "text": "hello world"}, {"id": "84", "text": "hello world"}, {"id":
"85", "text": "hello world"}, {"id": "86", "text": "hello world"}, {"id": "87",
"text": "hello world"}, {"id": "88", "text": "hello world"}, {"id": "89", "text":
"hello world"}, {"id": "90", "text": "hello world"}, {"id": "91", "text": "hello
world"}, {"id": "92", "text": "hello world"}, {"id": "93", "text": "hello world"},
{"id": "94", "text": "hello world"}, {"id": "95", "text": "hello world"}, {"id":
"96", "text": "hello world"}, {"id": "97", "text": "hello world"}, {"id": "98",
"text": "hello world"}, {"id": "99", "text": "hello world"}, {"id": "100", "text":
"hello world"}, {"id": "101", "text": "hello world"}, {"id": "102", "text":
"hello world"}, {"id": "103", "text": "hello world"}, {"id": "104", "text":
"hello world"}, {"id": "105", "text": "hello world"}, {"id": "106", "text":
"hello world"}, {"id": "107", "text": "hello world"}, {"id": "108", "text":
"hello world"}, {"id": "109", "text": "hello world"}, {"id": "110", "text":
"hello world"}, {"id": "111", "text": "hello world"}, {"id": "112", "text":
"hello world"}, {"id": "113", "text": "hello world"}, {"id": "114", "text":
"hello world"}, {"id": "115", "text": "hello world"}, {"id": "116", "text":
"hello world"}, {"id": "117", "text": "hello world"}, {"id": "118", "text":
"hello world"}, {"id": "119", "text": "hello world"}, {"id": "120", "text":
"hello world"}, {"id": "121", "text": "hello world"}, {"id": "122", "text":
"hello world"}, {"id": "123", "text": "hello world"}, {"id": "124", "text":
"hello world"}, {"id": "125", "text": "hello world"}, {"id": "126", "text":
"hello world"}, {"id": "127", "text": "hello world"}, {"id": "128", "text":
"hello world"}, {"id": "129", "text": "hello world"}, {"id": "130", "text":
"hello world"}, {"id": "131", "text": "hello world"}, {"id": "132", "text":
"hello world"}, {"id": "133", "text": "hello world"}, {"id": "134", "text":
"hello world"}, {"id": "135", "text": "hello world"}, {"id": "136", "text":
"hello world"}, {"id": "137", "text": "hello world"}, {"id": "138", "text":
"hello world"}, {"id": "139", "text": "hello world"}, {"id": "140", "text":
"hello world"}, {"id": "141", "text": "hello world"}, {"id": "142", "text":
"hello world"}, {"id": "143", "text": "hello world"}, {"id": "144", "text":
"hello world"}, {"id": "145", "text": "hello world"}, {"id": "146", "text":
"hello world"}, {"id": "147", "text": "hello world"}, {"id": "148", "text":
"hello world"}, {"id": "149", "text": "hello world"}, {"id": "150", "text":
"hello world"}, {"id": "151", "text": "hello world"}, {"id": "152", "text":
"hello world"}, {"id": "153", "text": "hello world"}, {"id": "154", "text":
"hello world"}, {"id": "155", "text": "hello world"}, {"id": "156", "text":
"hello world"}, {"id": "157", "text": "hello world"}, {"id": "158", "text":
"hello world"}, {"id": "159", "text": "hello world"}, {"id": "160", "text":
"hello world"}, {"id": "161", "text": "hello world"}, {"id": "162", "text":
"hello world"}, {"id": "163", "text": "hello world"}, {"id": "164", "text":
"hello world"}, {"id": "165", "text": "hello world"}, {"id": "166", "text":
"hello world"}, {"id": "167", "text": "hello world"}, {"id": "168", "text":
"hello world"}, {"id": "169", "text": "hello world"}, {"id": "170", "text":
"hello world"}, {"id": "171", "text": "hello world"}, {"id": "172", "text":
"hello world"}, {"id": "173", "text": "hello world"}, {"id": "174", "text":
"hello world"}, {"id": "175", "text": "hello world"}, {"id": "176", "text":
"hello world"}, {"id": "177", "text": "hello world"}, {"id": "178", "text":
"hello world"}, {"id": "179", "text": "hello world"}, {"id": "180", "text":
"hello world"}, {"id": "181", "text": "hello world"}, {"id": "182", "text":
"hello world"}, {"id": "183", "text": "hello world"}, {"id": "184", "text":
"hello world"}, {"id": "185", "text": "hello world"}, {"id": "186", "text":
"hello world"}, {"id": "187", "text": "hello world"}, {"id": "188", "text":
"hello world"}, {"id": "189", "text": "hello world"}, {"id": "190", "text":
"hello world"}, {"id": "191", "text": "hello world"}, {"id": "192", "text":
"hello world"}, {"id": "193", "text": "hello world"}, {"id": "194", "text":
"hello world"}, {"id": "195", "text": "hello world"}, {"id": "196", "text":
"hello world"}, {"id": "197", "text": "hello world"}, {"id": "198", "text":
"hello world"}, {"id": "199", "text": "hello world"}, {"id": "200", "text":
"hello world"}, {"id": "201", "text": "hello world"}, {"id": "202", "text":
"hello world"}, {"id": "203", "text": "hello world"}, {"id": "204", "text":
"hello world"}, {"id": "205", "text": "hello world"}, {"id": "206", "text":
"hello world"}, {"id": "207", "text": "hello world"}, {"id": "208", "text":
"hello world"}, {"id": "209", "text": "hello world"}, {"id": "210", "text":
"hello world"}, {"id": "211", "text": "hello world"}, {"id": "212", "text":
"hello world"}, {"id": "213", "text": "hello world"}, {"id": "214", "text":
"hello world"}, {"id": "215", "text": "hello world"}, {"id": "216", "text":
"hello world"}, {"id": "217", "text": "hello world"}, {"id": "218", "text":
"hello world"}, {"id": "219", "text": "hello world"}, {"id": "220", "text":
"hello world"}, {"id": "221", "text": "hello world"}, {"id": "222", "text":
"hello world"}, {"id": "223", "text": "hello world"}, {"id": "224", "text":
"hello world"}, {"id": "225", "text": "hello world"}, {"id": "226", "text":
"hello world"}, {"id": "227", "text": "hello world"}, {"id": "228", "text":
"hello world"}, {"id": "229", "text": "hello world"}, {"id": "230", "text":
"hello world"}, {"id": "231", "text": "hello world"}, {"id": "232", "text":
"hello world"}, {"id": "233", "text": "hello world"}, {"id": "234", "text":
"hello world"}, {"id": "235", "text": "hello world"}, {"id": "236", "text":
"hello world"}, {"id": "237", "text": "hello world"}, {"id": "238", "text":
"hello world"}, {"id": "239", "text": "hello world"}, {"id": "240", "text":
"hello world"}, {"id": "241", "text": "hello world"}, {"id": "242", "text":
"hello world"}, {"id": "243", "text": "hello world"}, {"id": "244", "text":
"hello world"}, {"id": "245", "text": "hello world"}, {"id": "246", "text":
"hello world"}, {"id": "247", "text": "hello world"}, {"id": "248", "text":
"hello world"}, {"id": "249", "text": "hello world"}, {"id": "250", "text":
"hello world"}, {"id": "251", "text": "hello world"}, {"id": "252", "text":
"hello world"}, {"id": "253", "text": "hello world"}, {"id": "254", "text":
"hello world"}, {"id": "255", "text": "hello world"}, {"id": "256", "text":
"hello world"}, {"id": "257", "text": "hello world"}, {"id": "258", "text":
"hello world"}, {"id": "259", "text": "hello world"}, {"id": "260", "text":
"hello world"}, {"id": "261", "text": "hello world"}, {"id": "262", "text":
"hello world"}, {"id": "263", "text": "hello world"}, {"id": "264", "text":
"hello world"}, {"id": "265", "text": "hello world"}, {"id": "266", "text":
"hello world"}, {"id": "267", "text": "hello world"}, {"id": "268", "text":
"hello world"}, {"id": "269", "text": "hello world"}, {"id": "270", "text":
"hello world"}, {"id": "271", "text": "hello world"}, {"id": "272", "text":
"hello world"}, {"id": "273", "text": "hello world"}, {"id": "274", "text":
"hello world"}, {"id": "275", "text": "hello world"}, {"id": "276", "text":
"hello world"}, {"id": "277", "text": "hello world"}, {"id": "278", "text":
"hello world"}, {"id": "279", "text": "hello world"}, {"id": "280", "text":
"hello world"}, {"id": "281", "text": "hello world"}, {"id": "282", "text":
"hello world"}, {"id": "283", "text": "hello world"}, {"id": "284", "text":
"hello world"}, {"id": "285", "text": "hello world"}, {"id": "286", "text":
"hello world"}, {"id": "287", "text": "hello world"}, {"id": "288", "text":
"hello world"}, {"id": "289", "text": "hello world"}, {"id": "290", "text":
"hello world"}, {"id": "291", "text": "hello world"}, {"id": "292", "text":
"hello world"}, {"id": "293", "text": "hello world"}, {"id": "294", "text":
"hello world"}, {"id": "295", "text": "hello world"}, {"id": "296", "text":
"hello world"}, {"id": "297", "text": "hello world"}, {"id": "298", "text":
"hello world"}, {"id": "299", "text": "hello world"}, {"id": "300", "text":
"hello world"}, {"id": "301", "text": "hello world"}, {"id": "302", "text":
"hello world"}, {"id": "303", "text": "hello world"}, {"id": "304", "text":
"hello world"}, {"id": "305", "text": "hello world"}, {"id": "306", "text":
"hello world"}, {"id": "307", "text": "hello world"}, {"id": "308", "text":
"hello world"}, {"id": "309", "text": "hello world"}, {"id": "310", "text":
"hello world"}, {"id": "311", "text": "hello world"}, {"id": "312", "text":
"hello world"}, {"id": "313", "text": "hello world"}, {"id": "314", "text":
"hello world"}, {"id": "315", "text": "hello world"}, {"id": "316", "text":
"hello world"}, {"id": "317", "text": "hello world"}, {"id": "318", "text":
"hello world"}, {"id": "319", "text": "hello world"}, {"id": "320", "text":
"hello world"}, {"id": "321", "text": "hello world"}, {"id": "322", "text":
"hello world"}, {"id": "323", "text": "hello world"}, {"id": "324", "text":
"hello world"}, {"id": "325", "text": "hello world"}, {"id": "326", "text":
"hello world"}, {"id": "327", "text": "hello world"}, {"id": "328", "text":
"hello world"}, {"id": "329", "text": "hello world"}, {"id": "330", "text":
"hello world"}, {"id": "331", "text": "hello world"}, {"id": "332", "text":
"hello world"}, {"id": "333", "text": "hello world"}, {"id": "334", "text":
"hello world"}, {"id": "335", "text": "hello world"}, {"id": "336", "text":
"hello world"}, {"id": "337", "text": "hello world"}, {"id": "338", "text":
"hello world"}, {"id": "339", "text": "hello world"}, {"id": "340", "text":
"hello world"}, {"id": "341", "text": "hello world"}, {"id": "342", "text":
"hello world"}, {"id": "343", "text": "hello world"}, {"id": "344", "text":
"hello world"}, {"id": "345", "text": "hello world"}, {"id": "346", "text":
"hello world"}, {"id": "347", "text": "hello world"}, {"id": "348", "text":
"hello world"}, {"id": "349", "text": "hello world"}, {"id": "350", "text":
"hello world"}, {"id": "351", "text": "hello world"}, {"id": "352", "text":
"hello world"}, {"id": "353", "text": "hello world"}, {"id": "354", "text":
"hello world"}, {"id": "355", "text": "hello world"}, {"id": "356", "text":
"hello world"}, {"id": "357", "text": "hello world"}, {"id": "358", "text":
"hello world"}, {"id": "359", "text": "hello world"}, {"id": "360", "text":
"hello world"}, {"id": "361", "text": "hello world"}, {"id": "362", "text":
"hello world"}, {"id": "363", "text": "hello world"}, {"id": "364", "text":
"hello world"}, {"id": "365", "text": "hello world"}, {"id": "366", "text":
"hello world"}, {"id": "367", "text": "hello world"}, {"id": "368", "text":
"hello world"}, {"id": "369", "text": "hello world"}, {"id": "370", "text":
"hello world"}, {"id": "371", "text": "hello world"}, {"id": "372", "text":
"hello world"}, {"id": "373", "text": "hello world"}, {"id": "374", "text":
"hello world"}, {"id": "375", "text": "hello world"}, {"id": "376", "text":
"hello world"}, {"id": "377", "text": "hello world"}, {"id": "378", "text":
"hello world"}, {"id": "379", "text": "hello world"}, {"id": "380", "text":
"hello world"}, {"id": "381", "text": "hello world"}, {"id": "382", "text":
"hello world"}, {"id": "383", "text": "hello world"}, {"id": "384", "text":
"hello world"}, {"id": "385", "text": "hello world"}, {"id": "386", "text":
"hello world"}, {"id": "387", "text": "hello world"}, {"id": "388", "text":
"hello world"}, {"id": "389", "text": "hello world"}, {"id": "390", "text":
"hello world"}, {"id": "391", "text": "hello world"}, {"id": "392", "text":
"hello world"}, {"id": "393", "text": "hello world"}, {"id": "394", "text":
"hello world"}, {"id": "395", "text": "hello world"}, {"id": "396", "text":
"hello world"}, {"id": "397", "text": "hello world"}, {"id": "398", "text":
"hello world"}, {"id": "399", "text": "hello world"}, {"id": "400", "text":
"hello world"}, {"id": "401", "text": "hello world"}, {"id": "402", "text":
"hello world"}, {"id": "403", "text": "hello world"}, {"id": "404", "text":
"hello world"}, {"id": "405", "text": "hello world"}, {"id": "406", "text":
"hello world"}, {"id": "407", "text": "hello world"}, {"id": "408", "text":
"hello world"}, {"id": "409", "text": "hello world"}, {"id": "410", "text":
"hello world"}, {"id": "411", "text": "hello world"}, {"id": "412", "text":
"hello world"}, {"id": "413", "text": "hello world"}, {"id": "414", "text":
"hello world"}, {"id": "415", "text": "hello world"}, {"id": "416", "text":
"hello world"}, {"id": "417", "text": "hello world"}, {"id": "418", "text":
"hello world"}, {"id": "419", "text": "hello world"}, {"id": "420", "text":
"hello world"}, {"id": "421", "text": "hello world"}, {"id": "422", "text":
"hello world"}, {"id": "423", "text": "hello world"}, {"id": "424", "text":
"hello world"}, {"id": "425", "text": "hello world"}, {"id": "426", "text":
"hello world"}, {"id": "427", "text": "hello world"}, {"id": "428", "text":
"hello world"}, {"id": "429", "text": "hello world"}, {"id": "430", "text":
"hello world"}, {"id": "431", "text": "hello world"}, {"id": "432", "text":
"hello world"}, {"id": "433", "text": "hello world"}, {"id": "434", "text":
"hello world"}, {"id": "435", "text": "hello world"}, {"id": "436", "text":
"hello world"}, {"id": "437", "text": "hello world"}, {"id": "438", "text":
"hello world"}, {"id": "439", "text": "hello world"}, {"id": "440", "text":
"hello world"}, {"id": "441", "text": "hello world"}, {"id": "442", "text":
"hello world"}, {"id": "443", "text": "hello world"}, {"id": "444", "text":
"hello world"}, {"id": "445", "text": "hello world"}, {"id": "446", "text":
"hello world"}, {"id": "447", "text": "hello world"}, {"id": "448", "text":
"hello world"}, {"id": "449", "text": "hello world"}, {"id": "450", "text":
"hello world"}, {"id": "451", "text": "hello world"}, {"id": "452", "text":
"hello world"}, {"id": "453", "text": "hello world"}, {"id": "454", "text":
"hello world"}, {"id": "455", "text": "hello world"}, {"id": "456", "text":
"hello world"}, {"id": "457", "text": "hello world"}, {"id": "458", "text":
"hello world"}, {"id": "459", "text": "hello world"}, {"id": "460", "text":
"hello world"}, {"id": "461", "text": "hello world"}, {"id": "462", "text":
"hello world"}, {"id": "463", "text": "hello world"}, {"id": "464", "text":
"hello world"}, {"id": "465", "text": "hello world"}, {"id": "466", "text":
"hello world"}, {"id": "467", "text": "hello world"}, {"id": "468", "text":
"hello world"}, {"id": "469", "text": "hello world"}, {"id": "470", "text":
"hello world"}, {"id": "471", "text": "hello world"}, {"id": "472", "text":
"hello world"}, {"id": "473", "text": "hello world"}, {"id": "474", "text":
"hello world"}, {"id": "475", "text": "hello world"}, {"id": "476", "text":
"hello world"}, {"id": "477", "text": "hello world"}, {"id": "478", "text":
"hello world"}, {"id": "479", "text": "hello world"}, {"id": "480", "text":
"hello world"}, {"id": "481", "text": "hello world"}, {"id": "482", "text":
"hello world"}, {"id": "483", "text": "hello world"}, {"id": "484", "text":
"hello world"}, {"id": "485", "text": "hello world"}, {"id": "486", "text":
"hello world"}, {"id": "487", "text": "hello world"}, {"id": "488", "text":
"hello world"}, {"id": "489", "text": "hello world"}, {"id": "490", "text":
"hello world"}, {"id": "491", "text": "hello world"}, {"id": "492", "text":
"hello world"}, {"id": "493", "text": "hello world"}, {"id": "494", "text":
"hello world"}, {"id": "495", "text": "hello world"}, {"id": "496", "text":
"hello world"}, {"id": "497", "text": "hello world"}, {"id": "498", "text":
"hello world"}, {"id": "499", "text": "hello world"}, {"id": "500", "text":
"hello world"}, {"id": "501", "text": "hello world"}, {"id": "502", "text":
"hello world"}, {"id": "503", "text": "hello world"}, {"id": "504", "text":
"hello world"}, {"id": "505", "text": "hello world"}, {"id": "506", "text":
"hello world"}, {"id": "507", "text": "hello world"}, {"id": "508", "text":
"hello world"}, {"id": "509", "text": "hello world"}, {"id": "510", "text":
"hello world"}, {"id": "511", "text": "hello world"}, {"id": "512", "text":
"hello world"}, {"id": "513", "text": "hello world"}, {"id": "514", "text":
"hello world"}, {"id": "515", "text": "hello world"}, {"id": "516", "text":
"hello world"}, {"id": "517", "text": "hello world"}, {"id": "518", "text":
"hello world"}, {"id": "519", "text": "hello world"}, {"id": "520", "text":
"hello world"}, {"id": "521", "text": "hello world"}, {"id": "522", "text":
"hello world"}, {"id": "523", "text": "hello world"}, {"id": "524", "text":
"hello world"}, {"id": "525", "text": "hello world"}, {"id": "526", "text":
"hello world"}, {"id": "527", "text": "hello world"}, {"id": "528", "text":
"hello world"}, {"id": "529", "text": "hello world"}, {"id": "530", "text":
"hello world"}, {"id": "531", "text": "hello world"}, {"id": "532", "text":
"hello world"}, {"id": "533", "text": "hello world"}, {"id": "534", "text":
"hello world"}, {"id": "535", "text": "hello world"}, {"id": "536", "text":
"hello world"}, {"id": "537", "text": "hello world"}, {"id": "538", "text":
"hello world"}, {"id": "539", "text": "hello world"}, {"id": "540", "text":
"hello world"}, {"id": "541", "text": "hello world"}, {"id": "542", "text":
"hello world"}, {"id": "543", "text": "hello world"}, {"id": "544", "text":
"hello world"}, {"id": "545", "text": "hello world"}, {"id": "546", "text":
"hello world"}, {"id": "547", "text": "hello world"}, {"id": "548", "text":
"hello world"}, {"id": "549", "text": "hello world"}, {"id": "550", "text":
"hello world"}, {"id": "551", "text": "hello world"}, {"id": "552", "text":
"hello world"}, {"id": "553", "text": "hello world"}, {"id": "554", "text":
"hello world"}, {"id": "555", "text": "hello world"}, {"id": "556", "text":
"hello world"}, {"id": "557", "text": "hello world"}, {"id": "558", "text":
"hello world"}, {"id": "559", "text": "hello world"}, {"id": "560", "text":
"hello world"}, {"id": "561", "text": "hello world"}, {"id": "562", "text":
"hello world"}, {"id": "563", "text": "hello world"}, {"id": "564", "text":
"hello world"}, {"id": "565", "text": "hello world"}, {"id": "566", "text":
"hello world"}, {"id": "567", "text": "hello world"}, {"id": "568", "text":
"hello world"}, {"id": "569", "text": "hello world"}, {"id": "570", "text":
"hello world"}, {"id": "571", "text": "hello world"}, {"id": "572", "text":
"hello world"}, {"id": "573", "text": "hello world"}, {"id": "574", "text":
"hello world"}, {"id": "575", "text": "hello world"}, {"id": "576", "text":
"hello world"}, {"id": "577", "text": "hello world"}, {"id": "578", "text":
"hello world"}, {"id": "579", "text": "hello world"}, {"id": "580", "text":
"hello world"}, {"id": "581", "text": "hello world"}, {"id": "582", "text":
"hello world"}, {"id": "583", "text": "hello world"}, {"id": "584", "text":
"hello world"}, {"id": "585", "text": "hello world"}, {"id": "586", "text":
"hello world"}, {"id": "587", "text": "hello world"}, {"id": "588", "text":
"hello world"}, {"id": "589", "text": "hello world"}, {"id": "590", "text":
"hello world"}, {"id": "591", "text": "hello world"}, {"id": "592", "text":
"hello world"}, {"id": "593", "text": "hello world"}, {"id": "594", "text":
"hello world"}, {"id": "595", "text": "hello world"}, {"id": "596", "text":
"hello world"}, {"id": "597", "text": "hello world"}, {"id": "598", "text":
"hello world"}, {"id": "599", "text": "hello world"}, {"id": "600", "text":
"hello world"}, {"id": "601", "text": "hello world"}, {"id": "602", "text":
"hello world"}, {"id": "603", "text": "hello world"}, {"id": "604", "text":
"hello world"}, {"id": "605", "text": "hello world"}, {"id": "606", "text":
"hello world"}, {"id": "607", "text": "hello world"}, {"id": "608", "text":
"hello world"}, {"id": "609", "text": "hello world"}, {"id": "610", "text":
"hello world"}, {"id": "611", "text": "hello world"}, {"id": "612", "text":
"hello world"}, {"id": "613", "text": "hello world"}, {"id": "614", "text":
"hello world"}, {"id": "615", "text": "hello world"}, {"id": "616", "text":
"hello world"}, {"id": "617", "text": "hello world"}, {"id": "618", "text":
"hello world"}, {"id": "619", "text": "hello world"}, {"id": "620", "text":
"hello world"}, {"id": "621", "text": "hello world"}, {"id": "622", "text":
"hello world"}, {"id": "623", "text": "hello world"}, {"id": "624", "text":
"hello world"}, {"id": "625", "text": "hello world"}, {"id": "626", "text":
"hello world"}, {"id": "627", "text": "hello world"}, {"id": "628", "text":
"hello world"}, {"id": "629", "text": "hello world"}, {"id": "630", "text":
"hello world"}, {"id": "631", "text": "hello world"}, {"id": "632", "text":
"hello world"}, {"id": "633", "text": "hello world"}, {"id": "634", "text":
"hello world"}, {"id": "635", "text": "hello world"}, {"id": "636", "text":
"hello world"}, {"id": "637", "text": "hello world"}, {"id": "638", "text":
"hello world"}, {"id": "639", "text": "hello world"}, {"id": "640", "text":
"hello world"}, {"id": "641", "text": "hello world"}, {"id": "642", "text":
"hello world"}, {"id": "643", "text": "hello world"}, {"id": "644", "text":
"hello world"}, {"id": "645", "text": "hello world"}, {"id": "646", "text":
"hello world"}, {"id": "647", "text": "hello world"}, {"id": "648", "text":
"hello world"}, {"id": "649", "text": "hello world"}, {"id": "650", "text":
"hello world"}, {"id": "651", "text": "hello world"}, {"id": "652", "text":
"hello world"}, {"id": "653", "text": "hello world"}, {"id": "654", "text":
"hello world"}, {"id": "655", "text": "hello world"}, {"id": "656", "text":
"hello world"}, {"id": "657", "text": "hello world"}, {"id": "658", "text":
"hello world"}, {"id": "659", "text": "hello world"}, {"id": "660", "text":
"hello world"}, {"id": "661", "text": "hello world"}, {"id": "662", "text":
"hello world"}, {"id": "663", "text": "hello world"}, {"id": "664", "text":
"hello world"}, {"id": "665", "text": "hello world"}, {"id": "666", "text":
"hello world"}, {"id": "667", "text": "hello world"}, {"id": "668", "text":
"hello world"}, {"id": "669", "text": "hello world"}, {"id": "670", "text":
"hello world"}, {"id": "671", "text": "hello world"}, {"id": "672", "text":
"hello world"}, {"id": "673", "text": "hello world"}, {"id": "674", "text":
"hello world"}, {"id": "675", "text": "hello world"}, {"id": "676", "text":
"hello world"}, {"id": "677", "text": "hello world"}, {"id": "678", "text":
"hello world"}, {"id": "679", "text": "hello world"}, {"id": "680", "text":
"hello world"}, {"id": "681", "text": "hello world"}, {"id": "682", "text":
"hello world"}, {"id": "683", "text": "hello world"}, {"id": "684", "text":
"hello world"}, {"id": "685", "text": "hello world"}, {"id": "686", "text":
"hello world"}, {"id": "687", "text": "hello world"}, {"id": "688", "text":
"hello world"}, {"id": "689", "text": "hello world"}, {"id": "690", "text":
"hello world"}, {"id": "691", "text": "hello world"}, {"id": "692", "text":
"hello world"}, {"id": "693", "text": "hello world"}, {"id": "694", "text":
"hello world"}, {"id": "695", "text": "hello world"}, {"id": "696", "text":
"hello world"}, {"id": "697", "text": "hello world"}, {"id": "698", "text":
"hello world"}, {"id": "699", "text": "hello world"}, {"id": "700", "text":
"hello world"}, {"id": "701", "text": "hello world"}, {"id": "702", "text":
"hello world"}, {"id": "703", "text": "hello world"}, {"id": "704", "text":
"hello world"}, {"id": "705", "text": "hello world"}, {"id": "706", "text":
"hello world"}, {"id": "707", "text": "hello world"}, {"id": "708", "text":
"hello world"}, {"id": "709", "text": "hello world"}, {"id": "710", "text":
"hello world"}, {"id": "711", "text": "hello world"}, {"id": "712", "text":
"hello world"}, {"id": "713", "text": "hello world"}, {"id": "714", "text":
"hello world"}, {"id": "715", "text": "hello world"}, {"id": "716", "text":
"hello world"}, {"id": "717", "text": "hello world"}, {"id": "718", "text":
"hello world"}, {"id": "719", "text": "hello world"}, {"id": "720", "text":
"hello world"}, {"id": "721", "text": "hello world"}, {"id": "722", "text":
"hello world"}, {"id": "723", "text": "hello world"}, {"id": "724", "text":
"hello world"}, {"id": "725", "text": "hello world"}, {"id": "726", "text":
"hello world"}, {"id": "727", "text": "hello world"}, {"id": "728", "text":
"hello world"}, {"id": "729", "text": "hello world"}, {"id": "730", "text":
"hello world"}, {"id": "731", "text": "hello world"}, {"id": "732", "text":
"hello world"}, {"id": "733", "text": "hello world"}, {"id": "734", "text":
"hello world"}, {"id": "735", "text": "hello world"}, {"id": "736", "text":
"hello world"}, {"id": "737", "text": "hello world"}, {"id": "738", "text":
"hello world"}, {"id": "739", "text": "hello world"}, {"id": "740", "text":
"hello world"}, {"id": "741", "text": "hello world"}, {"id": "742", "text":
"hello world"}, {"id": "743", "text": "hello world"}, {"id": "744", "text":
"hello world"}, {"id": "745", "text": "hello world"}, {"id": "746", "text":
"hello world"}, {"id": "747", "text": "hello world"}, {"id": "748", "text":
"hello world"}, {"id": "749", "text": "hello world"}, {"id": "750", "text":
"hello world"}, {"id": "751", "text": "hello world"}, {"id": "752", "text":
"hello world"}, {"id": "753", "text": "hello world"}, {"id": "754", "text":
"hello world"}, {"id": "755", "text": "hello world"}, {"id": "756", "text":
"hello world"}, {"id": "757", "text": "hello world"}, {"id": "758", "text":
"hello world"}, {"id": "759", "text": "hello world"}, {"id": "760", "text":
"hello world"}, {"id": "761", "text": "hello world"}, {"id": "762", "text":
"hello world"}, {"id": "763", "text": "hello world"}, {"id": "764", "text":
"hello world"}, {"id": "765", "text": "hello world"}, {"id": "766", "text":
"hello world"}, {"id": "767", "text": "hello world"}, {"id": "768", "text":
"hello world"}, {"id": "769", "text": "hello world"}, {"id": "770", "text":
"hello world"}, {"id": "771", "text": "hello world"}, {"id": "772", "text":
"hello world"}, {"id": "773", "text": "hello world"}, {"id": "774", "text":
"hello world"}, {"id": "775", "text": "hello world"}, {"id": "776", "text":
"hello world"}, {"id": "777", "text": "hello world"}, {"id": "778", "text":
"hello world"}, {"id": "779", "text": "hello world"}, {"id": "780", "text":
"hello world"}, {"id": "781", "text": "hello world"}, {"id": "782", "text":
"hello world"}, {"id": "783", "text": "hello world"}, {"id": "784", "text":
"hello world"}, {"id": "785", "text": "hello world"}, {"id": "786", "text":
"hello world"}, {"id": "787", "text": "hello world"}, {"id": "788", "text":
"hello world"}, {"id": "789", "text": "hello world"}, {"id": "790", "text":
"hello world"}, {"id": "791", "text": "hello world"}, {"id": "792", "text":
"hello world"}, {"id": "793", "text": "hello world"}, {"id": "794", "text":
"hello world"}, {"id": "795", "text": "hello world"}, {"id": "796", "text":
"hello world"}, {"id": "797", "text": "hello world"}, {"id": "798", "text":
"hello world"}, {"id": "799", "text": "hello world"}, {"id": "800", "text":
"hello world"}, {"id": "801", "text": "hello world"}, {"id": "802", "text":
"hello world"}, {"id": "803", "text": "hello world"}, {"id": "804", "text":
"hello world"}, {"id": "805", "text": "hello world"}, {"id": "806", "text":
"hello world"}, {"id": "807", "text": "hello world"}, {"id": "808", "text":
"hello world"}, {"id": "809", "text": "hello world"}, {"id": "810", "text":
"hello world"}, {"id": "811", "text": "hello world"}, {"id": "812", "text":
"hello world"}, {"id": "813", "text": "hello world"}, {"id": "814", "text":
"hello world"}, {"id": "815", "text": "hello world"}, {"id": "816", "text":
"hello world"}, {"id": "817", "text": "hello world"}, {"id": "818", "text":
"hello world"}, {"id": "819", "text": "hello world"}, {"id": "820", "text":
"hello world"}, {"id": "821", "text": "hello world"}, {"id": "822", "text":
"hello world"}, {"id": "823", "text": "hello world"}, {"id": "824", "text":
"hello world"}, {"id": "825", "text": "hello world"}, {"id": "826", "text":
"hello world"}, {"id": "827", "text": "hello world"}, {"id": "828", "text":
"hello world"}, {"id": "829", "text": "hello world"}, {"id": "830", "text":
"hello world"}, {"id": "831", "text": "hello world"}, {"id": "832", "text":
"hello world"}, {"id": "833", "text": "hello world"}, {"id": "834", "text":
"hello world"}, {"id": "835", "text": "hello world"}, {"id": "836", "text":
"hello world"}, {"id": "837", "text": "hello world"}, {"id": "838", "text":
"hello world"}, {"id": "839", "text": "hello world"}, {"id": "840", "text":
"hello world"}, {"id": "841", "text": "hello world"}, {"id": "842", "text":
"hello world"}, {"id": "843", "text": "hello world"}, {"id": "844", "text":
"hello world"}, {"id": "845", "text": "hello world"}, {"id": "846", "text":
"hello world"}, {"id": "847", "text": "hello world"}, {"id": "848", "text":
"hello world"}, {"id": "849", "text": "hello world"}, {"id": "850", "text":
"hello world"}, {"id": "851", "text": "hello world"}, {"id": "852", "text":
"hello world"}, {"id": "853", "text": "hello world"}, {"id": "854", "text":
"hello world"}, {"id": "855", "text": "hello world"}, {"id": "856", "text":
"hello world"}, {"id": "857", "text": "hello world"}, {"id": "858", "text":
"hello world"}, {"id": "859", "text": "hello world"}, {"id": "860", "text":
"hello world"}, {"id": "861", "text": "hello world"}, {"id": "862", "text":
"hello world"}, {"id": "863", "text": "hello world"}, {"id": "864", "text":
"hello world"}, {"id": "865", "text": "hello world"}, {"id": "866", "text":
"hello world"}, {"id": "867", "text": "hello world"}, {"id": "868", "text":
"hello world"}, {"id": "869", "text": "hello world"}, {"id": "870", "text":
"hello world"}, {"id": "871", "text": "hello world"}, {"id": "872", "text":
"hello world"}, {"id": "873", "text": "hello world"}, {"id": "874", "text":
"hello world"}, {"id": "875", "text": "hello world"}, {"id": "876", "text":
"hello world"}, {"id": "877", "text": "hello world"}, {"id": "878", "text":
"hello world"}, {"id": "879", "text": "hello world"}, {"id": "880", "text":
"hello world"}, {"id": "881", "text": "hello world"}, {"id": "882", "text":
"hello world"}, {"id": "883", "text": "hello world"}, {"id": "884", "text":
"hello world"}, {"id": "885", "text": "hello world"}, {"id": "886", "text":
"hello world"}, {"id": "887", "text": "hello world"}, {"id": "888", "text":
"hello world"}, {"id": "889", "text": "hello world"}, {"id": "890", "text":
"hello world"}, {"id": "891", "text": "hello world"}, {"id": "892", "text":
"hello world"}, {"id": "893", "text": "hello world"}, {"id": "894", "text":
"hello world"}, {"id": "895", "text": "hello world"}, {"id": "896", "text":
"hello world"}, {"id": "897", "text": "hello world"}, {"id": "898", "text":
"hello world"}, {"id": "899", "text": "hello world"}, {"id": "900", "text":
"hello world"}, {"id": "901", "text": "hello world"}, {"id": "902", "text":
"hello world"}, {"id": "903", "text": "hello world"}, {"id": "904", "text":
"hello world"}, {"id": "905", "text": "hello world"}, {"id": "906", "text":
"hello world"}, {"id": "907", "text": "hello world"}, {"id": "908", "text":
"hello world"}, {"id": "909", "text": "hello world"}, {"id": "910", "text":
"hello world"}, {"id": "911", "text": "hello world"}, {"id": "912", "text":
"hello world"}, {"id": "913", "text": "hello world"}, {"id": "914", "text":
"hello world"}, {"id": "915", "text": "hello world"}, {"id": "916", "text":
"hello world"}, {"id": "917", "text": "hello world"}, {"id": "918", "text":
"hello world"}, {"id": "919", "text": "hello world"}, {"id": "920", "text":
"hello world"}, {"id": "921", "text": "hello world"}, {"id": "922", "text":
"hello world"}, {"id": "923", "text": "hello world"}, {"id": "924", "text":
"hello world"}, {"id": "925", "text": "hello world"}, {"id": "926", "text":
"hello world"}, {"id": "927", "text": "hello world"}, {"id": "928", "text":
"hello world"}, {"id": "929", "text": "hello world"}, {"id": "930", "text":
"hello world"}, {"id": "931", "text": "hello world"}, {"id": "932", "text":
"hello world"}, {"id": "933", "text": "hello world"}, {"id": "934", "text":
"hello world"}, {"id": "935", "text": "hello world"}, {"id": "936", "text":
"hello world"}, {"id": "937", "text": "hello world"}, {"id": "938", "text":
"hello world"}, {"id": "939", "text": "hello world"}, {"id": "940", "text":
"hello world"}, {"id": "941", "text": "hello world"}, {"id": "942", "text":
"hello world"}, {"id": "943", "text": "hello world"}, {"id": "944", "text":
"hello world"}, {"id": "945", "text": "hello world"}, {"id": "946", "text":
"hello world"}, {"id": "947", "text": "hello world"}, {"id": "948", "text":
"hello world"}, {"id": "949", "text": "hello world"}, {"id": "950", "text":
"hello world"}, {"id": "951", "text": "hello world"}, {"id": "952", "text":
"hello world"}, {"id": "953", "text": "hello world"}, {"id": "954", "text":
"hello world"}, {"id": "955", "text": "hello world"}, {"id": "956", "text":
"hello world"}, {"id": "957", "text": "hello world"}, {"id": "958", "text":
"hello world"}, {"id": "959", "text": "hello world"}, {"id": "960", "text":
"hello world"}, {"id": "961", "text": "hello world"}, {"id": "962", "text":
"hello world"}, {"id": "963", "text": "hello world"}, {"id": "964", "text":
"hello world"}, {"id": "965", "text": "hello world"}, {"id": "966", "text":
"hello world"}, {"id": "967", "text": "hello world"}, {"id": "968", "text":
"hello world"}, {"id": "969", "text": "hello world"}, {"id": "970", "text":
"hello world"}, {"id": "971", "text": "hello world"}, {"id": "972", "text":
"hello world"}, {"id": "973", "text": "hello world"}, {"id": "974", "text":
"hello world"}, {"id": "975", "text": "hello world"}, {"id": "976", "text":
"hello world"}, {"id": "977", "text": "hello world"}, {"id": "978", "text":
"hello world"}, {"id": "979", "text": "hello world"}, {"id": "980", "text":
"hello world"}, {"id": "981", "text": "hello world"}, {"id": "982", "text":
"hello world"}, {"id": "983", "text": "hello world"}, {"id": "984", "text":
"hello world"}, {"id": "985", "text": "hello world"}, {"id": "986", "text":
"hello world"}, {"id": "987", "text": "hello world"}, {"id": "988", "text":
"hello world"}, {"id": "989", "text": "hello world"}, {"id": "990", "text":
"hello world"}, {"id": "991", "text": "hello world"}, {"id": "992", "text":
"hello world"}, {"id": "993", "text": "hello world"}, {"id": "994", "text":
"hello world"}, {"id": "995", "text": "hello world"}, {"id": "996", "text":
"hello world"}, {"id": "997", "text": "hello world"}, {"id": "998", "text":
"hello world"}, {"id": "999", "text": "hello world"}, {"id": "1000", "text":
"hello world"}, {"id": "1001", "text": "hello world"}, {"id": "1002", "text":
"hello world"}, {"id": "1003", "text": "hello world"}, {"id": "1004", "text":
"hello world"}, {"id": "1005", "text": "hello world"}, {"id": "1006", "text":
"hello world"}, {"id": "1007", "text": "hello world"}, {"id": "1008", "text":
"hello world"}, {"id": "1009", "text": "hello world"}, {"id": "1010", "text":
"hello world"}, {"id": "1011", "text": "hello world"}, {"id": "1012", "text":
"hello world"}, {"id": "1013", "text": "hello world"}, {"id": "1014", "text":
"hello world"}, {"id": "1015", "text": "hello world"}, {"id": "1016", "text":
"hello world"}, {"id": "1017", "text": "hello world"}, {"id": "1018", "text":
"hello world"}, {"id": "1019", "text": "hello world"}, {"id": "1020", "text":
"hello world"}, {"id": "1021", "text": "hello world"}, {"id": "1022", "text":
"hello world"}, {"id": "1023", "text": "hello world"}, {"id": "1024", "text":
"hello world"}, {"id": "1025", "text": "hello world"}, {"id": "1026", "text":
"hello world"}, {"id": "1027", "text": "hello world"}, {"id": "1028", "text":
"hello world"}, {"id": "1029", "text": "hello world"}, {"id": "1030", "text":
"hello world"}, {"id": "1031", "text": "hello world"}, {"id": "1032", "text":
"hello world"}, {"id": "1033", "text": "hello world"}, {"id": "1034", "text":
"hello world"}, {"id": "1035", "text": "hello world"}, {"id": "1036", "text":
"hello world"}, {"id": "1037", "text": "hello world"}, {"id": "1038", "text":
"hello world"}, {"id": "1039", "text": "hello world"}, {"id": "1040", "text":
"hello world"}, {"id": "1041", "text": "hello world"}, {"id": "1042", "text":
"hello world"}, {"id": "1043", "text": "hello world"}, {"id": "1044", "text":
"hello world"}, {"id": "1045", "text": "hello world"}, {"id": "1046", "text":
"hello world"}, {"id": "1047", "text": "hello world"}, {"id": "1048", "text":
"hello world"}, {"id": "1049", "text": "hello world"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '39855'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
response:
body:
string: '{"error":{"code":"InvalidRequest","innerError":{"code":"InvalidDocumentBatch","message":"Batch
request contains too many records. Max 1000 records are permitted."},"message":"Invalid
document in request."}}'
headers:
apim-request-id:
- 915bd2bc-8f30-4890-aed4-e308a3ec9a6b
content-type:
- application/json; charset=utf-8
date:
- Wed, 20 Nov 2019 01:46:46 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 2a14b626-0522-4220-8e5e-3abe1e1a5cf9
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '22'
status:
code: 400
message: Bad Request
version: 1

Просмотреть файл

@ -0,0 +1,48 @@
interactions:
- request:
body: '{"documents": [{"id": "56", "text": ":)"}, {"id": "0", "text": ":("}, {"id":
"22", "text": ""}, {"id": "19", "text": ":P"}, {"id": "1", "text": ":D"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '151'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"56","sentiment":"positive","documentScores":{"positive":0.79595094919204712,"neutral":0.181293323636055,"negative":0.0227557774633169},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.79595094919204712,"neutral":0.181293323636055,"negative":0.0227557774633169},"offset":0,"length":2}]},{"id":"0","sentiment":"negative","documentScores":{"positive":0.0299581550061703,"neutral":0.20621491968631739,"negative":0.76382696628570557},"sentences":[{"sentiment":"negative","sentenceScores":{"positive":0.0299581550061703,"neutral":0.20621491968631739,"negative":0.76382696628570557},"offset":0,"length":2}]},{"id":"19","sentiment":"positive","documentScores":{"positive":0.46800261735916138,"neutral":0.46502783894538879,"negative":0.0669695809483528},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.46800261735916138,"neutral":0.46502783894538879,"negative":0.0669695809483528},"offset":0,"length":2}]},{"id":"1","sentiment":"positive","documentScores":{"positive":0.79595112800598145,"neutral":0.18129308521747589,"negative":0.0227557606995106},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.79595112800598145,"neutral":0.18129308521747589,"negative":0.0227557606995106},"offset":0,"length":2}]}],"errors":[{"id":"22","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 28172281-2a22-46c5-bb7f-7faccdd0fda1
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=4
date:
- Thu, 14 Nov 2019 21:39:35 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 6268c03f-9eaf-405d-a49c-74f31d6aa3f4
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '65'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "I will go to the park.", "countryHint":
""}, {"id": "2", "text": "I did not like the hotel we stayed it.", "countryHint":
""}, {"id": "3", "text": "The restaurant had really good food.", "countryHint":
"US"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '245'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"1","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]},{"id":"2","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]},{"id":"3","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 641894c1-d263-458b-b573-f5045d27283b
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Mon, 02 Dec 2019 22:06:08 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- cd4700f0-bf5d-4b26-b74e-1d9b8a2fc278
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '4'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "I will go to the park.", "language":
""}, {"id": "2", "text": "I did not like the hotel we stayed it.", "language":
""}, {"id": "3", "text": "The restaurant had really good food.", "language":
"en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '236'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","documentScores":{"positive":0.088280625641346,"neutral":0.8992583155632019,"negative":0.012460995465517},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.088280625641346,"neutral":0.8992583155632019,"negative":0.012460995465517},"offset":0,"length":22}]},{"id":"2","sentiment":"negative","documentScores":{"positive":0.0186765696853399,"neutral":0.41426131129264832,"negative":0.56706219911575317},"sentences":[{"sentiment":"negative","sentenceScores":{"positive":0.0186765696853399,"neutral":0.41426131129264832,"negative":0.56706219911575317},"offset":0,"length":38}]},{"id":"3","sentiment":"positive","documentScores":{"positive":0.99868422746658325,"neutral":0.0004790813545696,"negative":0.0008366378606297},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.99868422746658325,"neutral":0.0004790813545696,"negative":0.0008366378606297},"offset":0,"length":36}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- f72061e8-155d-49ea-828f-fbb3f81c4bb5
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Mon, 02 Dec 2019 22:28:34 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 6d203e8c-197e-4c62-a500-10f2229f771a
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '66'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,48 @@
interactions:
- request:
body: '{"documents": [{"id": "56", "text": ":)"}, {"id": "0", "text": ":("}, {"id":
"22", "text": ""}, {"id": "19", "text": ":P"}, {"id": "1", "text": ":D"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '151'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?model-version=latest&showStats=true
response:
body:
string: '{"statistics":{"documentsCount":5,"validDocumentsCount":4,"erroneousDocumentsCount":1,"transactionsCount":4},"documents":[{"id":"56","sentiment":"positive","statistics":{"charactersCount":2,"transactionsCount":1},"documentScores":{"positive":0.89192992448806763,"neutral":0.0956294015049934,"negative":0.012440700083971},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.89192992448806763,"neutral":0.0956294015049934,"negative":0.012440700083971},"offset":0,"length":2}]},{"id":"0","sentiment":"negative","statistics":{"charactersCount":2,"transactionsCount":1},"documentScores":{"positive":0.0032547216396779,"neutral":0.0184039268642664,"negative":0.97834134101867676},"sentences":[{"sentiment":"negative","sentenceScores":{"positive":0.0032547216396779,"neutral":0.0184039268642664,"negative":0.97834134101867676},"offset":0,"length":2}]},{"id":"19","sentiment":"neutral","statistics":{"charactersCount":2,"transactionsCount":1},"documentScores":{"positive":0.29791706800460821,"neutral":0.666125476360321,"negative":0.035957433283329},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.29791706800460821,"neutral":0.666125476360321,"negative":0.035957433283329},"offset":0,"length":2}]},{"id":"1","sentiment":"positive","statistics":{"charactersCount":2,"transactionsCount":1},"documentScores":{"positive":0.8919297456741333,"neutral":0.0956295132637024,"negative":0.0124407093971968},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.8919297456741333,"neutral":0.0956295132637024,"negative":0.0124407093971968},"offset":0,"length":2}]}],"errors":[{"id":"22","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 2ba82b46-86e5-4927-a789-90a03335c99c
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=4
date:
- Mon, 18 Nov 2019 19:53:37 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- b6c7c99b-ce5c-4ca5-8fbb-ea6f388688f6
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '81'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,52 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "", "language": "en"}, {"id": "2", "text":
"I did not like the hotel we stayed it. It was too expensive.", "language":
"english"}, {"id": "3", "text": "The restaurant had really good food. I recommend
you try it.", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '269'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"3","sentiment":"positive","documentScores":{"positive":0.99577021598815918,"neutral":0.0020832819864154,"negative":0.0021464885212481},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.99423426389694214,"neutral":0.0028649375308305,"negative":0.0029007578268647},"offset":0,"length":36},{"sentiment":"positive","sentenceScores":{"positive":0.99730610847473145,"neutral":0.0013016263255849,"negative":0.0013922193320468},"offset":37,"length":23}]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: de,en,es,fr,it,ja,nl,pt-PT,zh-Hans,zh-Hant"},"message":"Invalid
Language Code."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 396f50c5-78d6-48bd-a710-57cbd34d2abd
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=1
date:
- Thu, 14 Nov 2019 21:39:24 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 6be9ae68-74cc-4448-9de7-0e2946d924df
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '71'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,52 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "I should take my cat to the veterinarian.",
"countryHint": "United States"}, {"id": "2", "text": "Este es un document escrito
en Espa\u00f1ol."}, {"id": "3", "text": ""}, {"id": "4", "text": "Fahrt nach
Stuttgart und dann zum Hotel zu Fu."}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '278'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"2","detectedLanguages":[{"name":"Spanish","iso6391Name":"es","score":1.0}]},{"id":"4","detectedLanguages":[{"name":"German","iso6391Name":"de","score":1.0}]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidCountryHint","message":"Country
hint is not valid. Please specify an ISO 3166-1 alpha-2 two letter country
code."},"message":"Invalid Country Hint."}},{"id":"3","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 46251a36-6508-4baa-957c-a5496e343549
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=2
date:
- Mon, 18 Nov 2019 17:02:31 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 3a381707-8632-478a-88c0-392bcb69339a
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '6'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen", "language": "English"}, {"id": "2", "text": "Microsoft fue
fundado por Bill Gates y Paul Allen", "language": "es"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '205'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/keyPhrases?showStats=false
response:
body:
string: '{"documents":[{"id":"2","keyPhrases":["Bill Gates","Paul Allen","Microsoft"]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: da,de,en,es,fi,fr,it,ja,ko,nl,no,pl,pt-BR,pt-PT,ru,sv"},"message":"Invalid
Language Code."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- c29e508a-ffa4-4ec1-8e1e-ab0fa58fd3b1
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=1
date:
- Thu, 14 Nov 2019 21:39:37 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- b4a7adb6-1813-4a14-9f38-ea3b9cb85971
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '500'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,54 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen on April 4, 1975.", "language": "en"}, {"id": "2", "text": "Hola",
"language": "Spanish"}, {"id": "3", "text": "", "language": "de"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '221'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[{"id":"1","entities":[{"text":"Microsoft","type":"Organization","offset":0,"length":9,"score":1.0},{"text":"Bill
Gates","type":"Person","offset":25,"length":10,"score":0.999755859375},{"text":"Paul
Allen","type":"Person","offset":40,"length":10,"score":0.99876481294631958},{"text":"April
4, 1975","type":"DateTime","subtype":"Date","offset":54,"length":13,"score":0.8}]}],"errors":[{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: ar,cs,da,de,en,es,fi,fr,hu,it,ja,ko,nl,no,pl,pt-BR,pt-PT,ru,sv,tr,zh-Hans"},"message":"Invalid
Language Code."}},{"id":"3","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 1bfb86ce-50d1-4014-bc3b-f14ed88647b0
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=1
date:
- Thu, 14 Nov 2019 21:39:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 0ffe2721-d047-4b33-8f25-b1c0b8442c92
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '135'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,52 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": ""}, {"id": "2", "text": "Microsoft
fue fundado por Bill Gates y Paul Allen", "language": "es"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '132'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/linking?showStats=false
response:
body:
string: '{"documents":[{"id":"2","entities":[{"name":"Bill Gates","matches":[{"text":"Bill
Gates","offset":26,"length":10,"score":0.31967461235530847}],"language":"es","id":"Bill
Gates","url":"https://es.wikipedia.org/wiki/Bill_Gates","dataSource":"Wikipedia"},{"name":"Paul
Allen","matches":[{"text":"Paul Allen","offset":39,"length":10,"score":0.80318090811651288}],"language":"es","id":"Paul
Allen","url":"https://es.wikipedia.org/wiki/Paul_Allen","dataSource":"Wikipedia"},{"name":"Microsoft","matches":[{"text":"Microsoft","offset":0,"length":9,"score":0.30594656354495253}],"language":"es","id":"Microsoft","url":"https://es.wikipedia.org/wiki/Microsoft","dataSource":"Wikipedia"}]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 102574a2-5040-45e6-8bd8-6a6c7c5f4400
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=1
date:
- Thu, 14 Nov 2019 21:39:53 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 47ede846-e730-485d-8e5c-3884f6eac368
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '1615'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "hola", "language": "es"}, {"id": "2",
"text": ""}, {"id": "3", "text": "Is 998.214.865-68 your Brazilian CPF number?"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '156'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/pii?showStats=false
response:
body:
string: '{"documents":[{"id":"3","entities":[{"text":"998.214.865-68","type":"Brazil
CPF Number","subtype":"","offset":3,"length":14,"score":0.85}]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
language not supported. Pass in one of: en"},"message":"Invalid Language Code."}},{"id":"2","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- 05270e98-77b1-4ff6-abf5-d2895a7b6bc4
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=1
date:
- Thu, 14 Nov 2019 21:39:51 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 028d9c64-adb9-41cb-932b-b6cfc8d5dc52
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '30'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen.", "language": "en"}, {"id": "2", "text": "I did not like the
hotel we stayed it. It was too expensive.", "language": "en"}, {"id": "3", "text":
"The restaurant had really good food. I recommend you try it.", "language":
"en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '315'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":3,"validDocumentsCount":3,"erroneousDocumentsCount":0,"transactionsCount":3},"documents":[{"id":"1","sentiment":"neutral","statistics":{"charactersCount":51,"transactionsCount":1},"documentScores":{"positive":0.0065773287788033,"neutral":0.98863190412521362,"negative":0.004790797829628},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.0065773287788033,"neutral":0.98863190412521362,"negative":0.004790797829628},"offset":0,"length":51}]},{"id":"2","sentiment":"negative","statistics":{"charactersCount":60,"transactionsCount":1},"documentScores":{"positive":0.0094401380047202,"neutral":0.20717787742614749,"negative":0.78338205814361572},"sentences":[{"sentiment":"negative","sentenceScores":{"positive":0.0186765640974045,"neutral":0.41426122188568121,"negative":0.567062258720398},"offset":0,"length":38},{"sentiment":"negative","sentenceScores":{"positive":0.0002037113154074,"neutral":9.45370848058E-05,"negative":0.99970179796218872},"offset":39,"length":21}]},{"id":"3","sentiment":"positive","statistics":{"charactersCount":60,"transactionsCount":1},"documentScores":{"positive":0.98069894313812256,"neutral":0.0163726881146431,"negative":0.002928314730525},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.99868422746658325,"neutral":0.0004790813545696,"negative":0.0008366370457225},"offset":0,"length":36},{"sentiment":"positive","sentenceScores":{"positive":0.96271371841430664,"neutral":0.0322662964463234,"negative":0.0050199925899506},"offset":37,"length":23}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 5b4d6c4a-48d9-48c5-8be4-3856cddbe29d
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Thu, 05 Dec 2019 01:57:30 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 8c834f04-11e6-448b-b9b6-451f1ee27659
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '73'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "I should take my cat to the veterinarian.",
"countryHint": "US"}, {"id": "2", "text": "Este es un document escrito en Espa\u00f1ol.",
"countryHint": "US"}, {"id": "3", "text": "\u732b\u306f\u5e78\u305b", "countryHint":
"US"}, {"id": "4", "text": "Fahrt nach Stuttgart und dann zum Hotel zu Fu.",
"countryHint": "US"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '354'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":4,"validDocumentsCount":4,"erroneousDocumentsCount":0,"transactionsCount":4},"documents":[{"id":"1","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}],"statistics":{"charactersCount":41,"transactionsCount":1}},{"id":"2","detectedLanguages":[{"name":"Spanish","iso6391Name":"es","score":1.0}],"statistics":{"charactersCount":39,"transactionsCount":1}},{"id":"3","detectedLanguages":[{"name":"Japanese","iso6391Name":"ja","score":1.0}],"statistics":{"charactersCount":4,"transactionsCount":1}},{"id":"4","detectedLanguages":[{"name":"German","iso6391Name":"de","score":1.0}],"statistics":{"charactersCount":46,"transactionsCount":1}}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- ea11419e-11d5-4aa1-9fe0-3a86ecbc329c
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=4
date:
- Wed, 04 Dec 2019 21:48:27 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- ff6d2d1b-2626-41d5-9cfd-43ea20ab5574
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '8'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen", "language": "en"}, {"id": "2", "text": "Microsoft fue fundado
por Bill Gates y Paul Allen", "language": "es"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '200'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/keyPhrases?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":2,"validDocumentsCount":2,"erroneousDocumentsCount":0,"transactionsCount":2},"documents":[{"id":"1","keyPhrases":["Bill
Gates","Paul Allen","Microsoft"],"statistics":{"charactersCount":50,"transactionsCount":1}},{"id":"2","keyPhrases":["Bill
Gates","Paul Allen","Microsoft"],"statistics":{"charactersCount":49,"transactionsCount":1}}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- d3795787-20b8-4e01-ad93-8c1444061d05
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=2
date:
- Thu, 05 Dec 2019 01:55:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- d6257c67-f412-47d5-be13-8fb9f535935e
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '45'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,59 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen on April 4, 1975.", "language": "en"}, {"id": "2", "text": "Microsoft
fue fundado por Bill Gates y Paul Allen el 4 de abril de 1975.", "language":
"es"}, {"id": "3", "text": "Microsoft wurde am 4. April 1975 von Bill Gates
und Paul Allen gegr\u00fcndet.", "language": "de"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '362'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/general?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":3,"validDocumentsCount":3,"erroneousDocumentsCount":0,"transactionsCount":3},"documents":[{"id":"1","statistics":{"charactersCount":68,"transactionsCount":1},"entities":[{"text":"Microsoft","type":"Organization","offset":0,"length":9,"score":1.0},{"text":"Bill
Gates","type":"Person","offset":25,"length":10,"score":0.999755859375},{"text":"Paul
Allen","type":"Person","offset":40,"length":10,"score":0.99876481294631958},{"text":"April
4, 1975","type":"DateTime","subtype":"Date","offset":54,"length":13,"score":0.8}]},{"id":"2","statistics":{"charactersCount":72,"transactionsCount":1},"entities":[{"text":"Microsoft","type":"Organization","offset":0,"length":9,"score":0.99482542276382446},{"text":"Bill
Gates","type":"Person","offset":26,"length":10,"score":0.99993896484375},{"text":"Paul
Allen","type":"Person","offset":39,"length":10,"score":0.99963384866714478},{"text":"4
de abril de 1975","type":"DateTime","subtype":"Date","offset":53,"length":18,"score":0.8}]},{"id":"3","statistics":{"charactersCount":73,"transactionsCount":1},"entities":[{"text":"Microsoft","type":"Organization","offset":0,"length":9,"score":0.999847412109375},{"text":"4.
April 1975","type":"DateTime","subtype":"Date","offset":19,"length":13,"score":0.8},{"text":"Bill
Gates","type":"Person","offset":37,"length":10,"score":0.99951183795928955},{"text":"Paul
Allen","type":"Person","offset":52,"length":10,"score":0.99981689453125}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 9226def1-8ba4-419f-8826-25ef35fd9cdd
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Thu, 05 Dec 2019 01:42:48 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 62742469-a264-465e-a4f8-77d23f9f13db
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '3974'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,56 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen", "language": "en"}, {"id": "2", "text": "Microsoft fue fundado
por Bill Gates y Paul Allen", "language": "es"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '200'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/linking?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":2,"validDocumentsCount":2,"erroneousDocumentsCount":0,"transactionsCount":2},"documents":[{"id":"1","statistics":{"charactersCount":50,"transactionsCount":1},"entities":[{"name":"Bill
Gates","matches":[{"text":"Bill Gates","offset":25,"length":10,"score":0.22778968418472689}],"language":"en","id":"Bill
Gates","url":"https://en.wikipedia.org/wiki/Bill_Gates","dataSource":"Wikipedia"},{"name":"Paul
Allen","matches":[{"text":"Paul Allen","offset":40,"length":10,"score":0.1552051480609411}],"language":"en","id":"Paul
Allen","url":"https://en.wikipedia.org/wiki/Paul_Allen","dataSource":"Wikipedia"},{"name":"Microsoft","matches":[{"text":"Microsoft","offset":0,"length":9,"score":0.18863350409792545}],"language":"en","id":"Microsoft","url":"https://en.wikipedia.org/wiki/Microsoft","dataSource":"Wikipedia"}]},{"id":"2","statistics":{"charactersCount":49,"transactionsCount":1},"entities":[{"name":"Bill
Gates","matches":[{"text":"Bill Gates","offset":26,"length":10,"score":0.31967461235530847}],"language":"es","id":"Bill
Gates","url":"https://es.wikipedia.org/wiki/Bill_Gates","dataSource":"Wikipedia"},{"name":"Paul
Allen","matches":[{"text":"Paul Allen","offset":39,"length":10,"score":0.80318090811651288}],"language":"es","id":"Paul
Allen","url":"https://es.wikipedia.org/wiki/Paul_Allen","dataSource":"Wikipedia"},{"name":"Microsoft","matches":[{"text":"Microsoft","offset":0,"length":9,"score":0.30594656354495253}],"language":"es","id":"Microsoft","url":"https://es.wikipedia.org/wiki/Microsoft","dataSource":"Wikipedia"}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 868259a9-6342-4317-96e9-c2163083948d
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=2
date:
- Thu, 05 Dec 2019 01:54:03 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 96e1b4f2-41f8-4fa4-a5b1-9bb79adcfbd0
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '21'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,52 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "My SSN is 555-55-5555.", "language":
"en"}, {"id": "2", "text": "Your ABA number - 111000025 - is the first 9 digits
in the lower left hand corner of your personal check.", "language": "en"}, {"id":
"3", "text": "Is 998.214.865-68 your Brazilian CPF number?", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '315'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-azure-cognitiveservices-language-textanalytics/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/pii?showStats=true
response:
body:
string: '{"statistics":{"documentsCount":3,"validDocumentsCount":3,"erroneousDocumentsCount":0,"transactionsCount":3},"documents":[{"id":"1","statistics":{"charactersCount":22,"transactionsCount":1},"entities":[{"text":"555-55-5555","type":"U.S.
Social Security Number (SSN)","subtype":"","offset":10,"length":11,"score":0.85}]},{"id":"2","statistics":{"charactersCount":105,"transactionsCount":1},"entities":[{"text":"111000025","type":"ABA
Routing Number","subtype":"","offset":18,"length":9,"score":0.75}]},{"id":"3","statistics":{"charactersCount":44,"transactionsCount":1},"entities":[{"text":"998.214.865-68","type":"Brazil
CPF Number","subtype":"","offset":3,"length":14,"score":0.85}]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- a888d892-7832-4c54-87b4-3b27c01dd763
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Thu, 05 Dec 2019 01:44:48 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 8d313678-1ba5-4e2b-afea-27fba01b9f68
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '528'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,50 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "I should take my cat to the veterinarian."},
{"id": "1", "text": "Este es un document escrito en Espa\u00f1ol."}, {"id":
"2", "text": "\u732b\u306f\u5e78\u305b"}, {"id": "3", "text": "Fahrt nach Stuttgart
und dann zum Hotel zu Fu."}, {"id": "4", "text": ""}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"0","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]},{"id":"1","detectedLanguages":[{"name":"Spanish","iso6391Name":"es","score":1.0}]},{"id":"2","detectedLanguages":[{"name":"Japanese","iso6391Name":"ja","score":1.0}]},{"id":"3","detectedLanguages":[{"name":"German","iso6391Name":"de","score":1.0}]}],"errors":[{"id":"4","error":{"code":"InvalidArgument","innerError":{"code":"InvalidDocument","message":"Document
text is empty."},"message":"Invalid document in request."}}],"modelVersion":"latest"}'
headers:
apim-request-id:
- f24b4ed7-5c55-4e8f-a3b3-d135b3ad05ad
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=4
date:
- Thu, 14 Nov 2019 21:40:33 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 6ae69f7b-f39f-4854-ad72-11a9e2c33080
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '18'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "I should take my cat to the veterinarian."},
{"id": "2", "text": "Este es un document escrito en Espa\u00f1ol."}, {"id":
"3", "text": "\u732b\u306f\u5e78\u305b"}, {"id": "4", "text": "Fahrt nach Stuttgart
und dann zum Hotel zu Fu."}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '270'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"1","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]},{"id":"2","detectedLanguages":[{"name":"Spanish","iso6391Name":"es","score":1.0}]},{"id":"3","detectedLanguages":[{"name":"Japanese","iso6391Name":"ja","score":1.0}]},{"id":"4","detectedLanguages":[{"name":"German","iso6391Name":"de","score":1.0}]}],"errors":[],"modelVersion":"latest"}'
headers:
apim-request-id:
- 52d82504-88c7-4a95-a237-647b3f16ff0f
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=4
date:
- Thu, 14 Nov 2019 21:40:33 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 8dabfb1a-f4f9-4d1f-b5fc-89447310a817
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '4'
status:
code: 200
message: OK
version: 1

Просмотреть файл

@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "1", "text": "Microsoft was founded by Bill Gates
and Paul Allen."}, {"id": "2", "text": "I did not like the hotel we stayed it.
It was too expensive."}, {"id": "3", "text": "The restaurant had really good
food. I recommend you try it."}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '261'
Content-Type:
- application/json; charset=utf-8
User-Agent:
- azsdk-python-core/1.1.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0) azsdk-python-textanalyticsclient/3.0.0b1
X-BingApis-SDK-Client:
- Python-SDK
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","documentScores":{"positive":0.0145784495398402,"neutral":0.97402292490005493,"negative":0.0113986236974597},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.0145784495398402,"neutral":0.97402292490005493,"negative":0.0113986236974597},"offset":0,"length":51}]},{"id":"2","sentiment":"negative","documentScores":{"positive":0.0160302110016346,"neutral":0.21421422064304349,"negative":0.76975554227828979},"sentences":[{"sentiment":"negative","sentenceScores":{"positive":0.0317745991051197,"neutral":0.42806893587112432,"negative":0.54015642404556274},"offset":0,"length":38},{"sentiment":"negative","sentenceScores":{"positive":0.0002858212974388,"neutral":0.0003595057642087,"negative":0.99935466051101685},"offset":39,"length":21}]},{"id":"3","sentiment":"positive","documentScores":{"positive":0.99577021598815918,"neutral":0.0020832826849073,"negative":0.002146489918232},"sentences":[{"sentiment":"positive","sentenceScores":{"positive":0.99423426389694214,"neutral":0.0028649389278144,"negative":0.0029007606208324},"offset":0,"length":36},{"sentiment":"positive","sentenceScores":{"positive":0.99730610847473145,"neutral":0.0013016263255849,"negative":0.0013922193320468},"offset":37,"length":23}]}],"errors":[],"modelVersion":"latest"}'
headers:
apim-request-id:
- ab099c31-b6d3-4f8d-89a3-50c543cd6e32
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Thu, 14 Nov 2019 21:40:36 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-aml-ta-request-id:
- 3b3b2849-d68b-4e3b-b8d0-0130411e0bdf
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '80'
status:
code: 200
message: OK
version: 1

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше