-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 domain_filter param #13451
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
20a2bd0
add domain_filter param
iscai-msft 7340c60
add tests
iscai-msft fe2aea4
fix docstrings based off krista's comments
iscai-msft 00f56b2
fix docstrings based off mari's comments
iscai-msft 4847718
switch PHI -> PROTECTED_HEALTH_INFORMATION
iscai-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,6 +260,10 @@ def recognize_pii_entities( # type: ignore | |
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. | ||
:keyword domain_filter: Filters the response entities to ones only included in your specified domain. | ||
iscai-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
I.e., if set to 'PHI', will only return entities in the Personal Healthcare Information domain. | ||
iscai-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Currently only supports 'PHI'. See https://aka.ms/tanerpii for more information. | ||
iscai-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:paramtype domain_filter: str or ~azure.ai.textanalytics.PiiEntityDomainType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the same :versionadded: directive here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, they had it on v3.1-preview.1, just never supported it |
||
:return: The combined list of :class:`~azure.ai.textanalytics.RecognizePiiEntitiesResult` | ||
and :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents | ||
were passed in. | ||
|
@@ -281,13 +285,15 @@ 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) | ||
domain_filter = kwargs.pop("domain_filter", None) | ||
if self._string_code_unit: | ||
kwargs.update({"string_index_type": self._string_code_unit}) | ||
try: | ||
return self._client.entities_recognition_pii( | ||
documents=docs, | ||
model_version=model_version, | ||
show_stats=show_stats, | ||
domain=domain_filter, | ||
cls=kwargs.pop("cls", pii_entities_result), | ||
**kwargs | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ai-textanalytics/tests/recordings/test_recognize_pii_entities.test_phi_domain_filter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
interactions: | ||
- request: | ||
body: '{"documents": [{"id": "0", "text": "I work at Microsoft and my phone number | ||
is 333-333-3333", "language": "en"}]}' | ||
headers: | ||
Accept: | ||
- application/json, text/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '113' | ||
Content-Type: | ||
- application/json | ||
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/entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=UnicodeCodePoint | ||
response: | ||
body: | ||
string: '{"documents":[{"id":"0","entities":[{"text":"333-333-3333","category":"Phone | ||
Number","offset":43,"length":12,"confidenceScore":0.8}],"warnings":[]}],"errors":[],"modelVersion":"2020-07-01"}' | ||
headers: | ||
apim-request-id: | ||
- c2319b95-6fd2-46c9-80e3-06c8f2701825 | ||
content-type: | ||
- application/json; charset=utf-8 | ||
csp-billing-usage: | ||
- CognitiveServices.TextAnalytics.BatchScoring=1 | ||
date: | ||
- Mon, 31 Aug 2020 20:32:54 GMT | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains; preload | ||
transfer-encoding: | ||
- chunked | ||
x-content-type-options: | ||
- nosniff | ||
x-envoy-upstream-service-time: | ||
- '79' | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
33 changes: 33 additions & 0 deletions
33
...tanalytics/tests/recordings/test_recognize_pii_entities_async.test_phi_domain_filter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
interactions: | ||
- request: | ||
body: '{"documents": [{"id": "0", "text": "I work at Microsoft and my phone number | ||
is 333-333-3333", "language": "en"}]}' | ||
headers: | ||
Accept: | ||
- application/json, text/json | ||
Content-Length: | ||
- '113' | ||
Content-Type: | ||
- application/json | ||
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/entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=UnicodeCodePoint | ||
response: | ||
body: | ||
string: '{"documents":[{"id":"0","entities":[{"text":"333-333-3333","category":"Phone | ||
Number","offset":43,"length":12,"confidenceScore":0.8}],"warnings":[]}],"errors":[],"modelVersion":"2020-07-01"}' | ||
headers: | ||
apim-request-id: 9265752d-3262-4dbb-94d6-be26889e3db9 | ||
content-type: application/json; charset=utf-8 | ||
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=1 | ||
date: Mon, 31 Aug 2020 20:32:55 GMT | ||
strict-transport-security: max-age=31536000; includeSubDomains; preload | ||
transfer-encoding: chunked | ||
x-content-type-options: nosniff | ||
x-envoy-upstream-service-time: '82' | ||
status: | ||
code: 200 | ||
message: OK | ||
url: https://westus2.api.cognitive.microsoft.com//text/analytics/v3.1-preview.1/entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=UnicodeCodePoint | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we include a comment for PHI about what it stands for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Framework Design Guidance:
Because of that, we should rename
PHI
toProtectedHealthInformation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
PHI
fits better in this case though, since we're abbreviatingPII
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even between us we've asked multiple times what
PHI
is.Pii
is more common, so I strongly recommend changing it.For .NET I will use the complete name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, since .NET is using the full name, I'll make the change