Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[text analytics] add string-index-type support #13378

Merged
merged 8 commits into from
Aug 28, 2020
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, endpoint, credential, **kwargs):
)
self._default_language = kwargs.pop("default_language", "en")
self._default_country_hint = kwargs.pop("default_country_hint", "US")
self._string_index_type = None if kwargs.get("api_version") == "v3.0" else "UnicodeCodePoint"
iscai-msft marked this conversation as resolved.
Show resolved Hide resolved

@distributed_trace
def detect_language( # type: ignore
Expand Down Expand Up @@ -213,6 +214,8 @@ def recognize_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
maririos marked this conversation as resolved.
Show resolved Hide resolved
kwargs.update({"string_index_type": self._string_index_type})
try:
return self._client.entities_recognition_general(
documents=docs,
Expand Down Expand Up @@ -278,6 +281,8 @@ def recognize_pii_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})
try:
return self._client.entities_recognition_pii(
documents=docs,
Expand Down Expand Up @@ -350,6 +355,8 @@ def recognize_linked_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})
try:
return self._client.entities_linking(
documents=docs,
Expand Down Expand Up @@ -490,6 +497,8 @@ def analyze_sentiment( # type: ignore
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
show_opinion_mining = kwargs.pop("show_opinion_mining", None)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})

if show_opinion_mining is not None:
kwargs.update({"opinion_mining": show_opinion_mining})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__( # type: ignore
)
self._default_language = kwargs.pop("default_language", "en")
self._default_country_hint = kwargs.pop("default_country_hint", "US")
self._string_index_type = None if kwargs.get("api_version") == "v3.0" else "UnicodeCodePoint"

@distributed_trace_async
async def detect_language( # type: ignore
Expand Down Expand Up @@ -216,6 +217,8 @@ async def recognize_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})
try:
return await self._client.entities_recognition_general(
documents=docs,
Expand Down Expand Up @@ -280,6 +283,8 @@ async def recognize_pii_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})
try:
return await self._client.entities_recognition_pii(
documents=docs,
Expand Down Expand Up @@ -351,6 +356,8 @@ async def recognize_linked_entities( # type: ignore
docs = _validate_input(documents, "language", language)
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})
try:
return await self._client.entities_linking(
documents=docs,
Expand Down Expand Up @@ -489,6 +496,8 @@ async def analyze_sentiment( # type: ignore
model_version = kwargs.pop("model_version", None)
show_stats = kwargs.pop("show_stats", False)
show_opinion_mining = kwargs.pop("show_opinion_mining", None)
if self._string_index_type:
kwargs.update({"string_index_type": self._string_index_type})

if show_opinion_mining is not None:
kwargs.update({"opinion_mining": show_opinion_mining})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=true&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=true&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"statistics":{"documentsCount":3,"validDocumentsCount":3,"erroneousDocumentsCount":0,"transactionsCount":3},"documents":[{"id":"1","sentiment":"neutral","statistics":{"charactersCount":51,"transactionsCount":1},"confidenceScores":{"positive":0.01,"neutral":0.99,"negative":0.0},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.99,"negative":0.0},"offset":0,"length":51,"text":"Microsoft
Expand All @@ -30,21 +30,21 @@ interactions:
recommend you try it."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- b1e4352f-1e0f-46e3-9f6e-5a82195726b5
- 546ef146-2055-49be-945d-8b4d95870565
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Wed, 26 Aug 2020 21:20:39 GMT
- Thu, 27 Aug 2020 19:31:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '91'
- '84'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.99,"negative":0.0},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.99,"negative":0.0},"offset":0,"length":51,"text":"Microsoft
Expand All @@ -30,21 +30,21 @@ interactions:
recommend you try it."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- 36f47b42-b805-4655-9cc9-ed373487b586
- ee67d363-828c-4a5b-92ee-4a943a9aa020
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '83'
- '95'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"error":{"code":"401","message":"Access denied due to invalid subscription
Expand All @@ -26,7 +26,7 @@ interactions:
content-length:
- '224'
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:56 GMT
status:
code: 401
message: PermissionDenied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?model-version=bad&showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?model-version=bad&showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"error":{"code":"InvalidRequest","message":"Invalid Request.","innererror":{"code":"ModelVersionIncorrect","message":"Invalid
model version. Possible values are: latest,2019-10-01,2020-04-01"}}}'
headers:
apim-request-id:
- e98c3279-f8c4-49ce-b25c-f51289330fdd
- 600cfe88-8c7b-4017-a50e-ef0c30a546a4
content-type:
- application/json; charset=utf-8
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:56 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '10'
- '4'
status:
code: 400
message: Bad Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,26 +760,26 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"error":{"code":"InvalidRequest","message":"Invalid document in request.","innererror":{"code":"InvalidDocumentBatch","message":"Batch
request contains too many records. Max 10 records are permitted."}}}'
headers:
apim-request-id:
- 5bcf6f2d-8a67-4bf7-a552-67c0c0ce9f9b
- e63eddb4-ac2c-4b1d-bfa8-ff78dc65076f
content-type:
- application/json; charset=utf-8
date:
- Wed, 26 Aug 2020 21:20:36 GMT
- Thu, 27 Aug 2020 19:31:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '13'
- '12'
status:
code: 400
message: Bad Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,18 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"error":{"code":"InvalidRequest","message":"Invalid document in request.","innererror":{"code":"InvalidDocumentBatch","message":"Batch
request contains too many records. Max 10 records are permitted."}}}'
headers:
apim-request-id:
- 35aa5189-c6e8-46c5-9339-607d86aef6a1
- 22ce0f08-e152-4611-bf63-9cc9ae125568
content-type:
- application/json; charset=utf-8
date:
- Wed, 26 Aug 2020 21:20:39 GMT
- Thu, 27 Aug 2020 19:31:50 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.04,"neutral":0.95,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.04,"neutral":0.95,"negative":0.01},"offset":0,"length":22,"text":"I
Expand All @@ -27,21 +27,21 @@ interactions:
restaurant had really good food."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- 56db4bc5-e1c1-4fed-ad17-24abcacb6ed4
- f43fb317-26ff-4149-b5bc-d56d11c8854a
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:51 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '105'
- '102'
status:
code: 200
message: OK
Expand All @@ -64,7 +64,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.09,"neutral":0.9,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.09,"neutral":0.9,"negative":0.01},"offset":0,"length":22,"text":"I
Expand All @@ -73,21 +73,21 @@ interactions:
restaurant had really good food."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- df18061f-f96b-41c3-a690-08384e7195e8
- 774b2e78-39be-49f0-8fd9-0aa021a39f2f
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:51 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '83'
- '93'
status:
code: 200
message: OK
Expand All @@ -110,7 +110,7 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"documents":[{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.04,"neutral":0.95,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.04,"neutral":0.95,"negative":0.01},"offset":0,"length":22,"text":"I
Expand All @@ -119,21 +119,21 @@ interactions:
restaurant had really good food."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- d9626bd3-bfec-4395-b0a0-ab11cfa7dab8
- 6538bfb7-2e2e-488f-b935-ead59d26f8d8
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=3
date:
- Wed, 26 Aug 2020 21:20:36 GMT
- Thu, 27 Aug 2020 19:31:52 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '113'
- '111'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ interactions:
User-Agent:
- azsdk-python-ai-textanalytics/5.0.1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=TextElements_v8
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.1/sentiment?showStats=false&stringIndexType=UnicodeCodePoint
response:
body:
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
document in request.","innererror":{"code":"InvalidDocument","message":"Document
text is empty."}}}],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- 82077cd7-952f-404b-b519-24e97f7dcd63
- 7f10c39c-4c45-4b6f-a4a9-d842331d000b
content-type:
- application/json; charset=utf-8
date:
- Wed, 26 Aug 2020 21:20:35 GMT
- Thu, 27 Aug 2020 19:31:56 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '12'
- '2'
status:
code: 200
message: OK
Expand Down
Loading