Skip to content

Commit 91c1788

Browse files
authored
[Text Analytics] Fix samples (Azure#14255)
This PR does the following: - updates samples so the typescript ones can run with `node8` with no issues by setting the compilation target to `ES6`. - fixes the recognize PII sample where a the behavior for the protected healthcare information parameter changed in the service. This PR updates the input text used with this parameter to one that does not have protected healthcare information according to the new update. More information can be found [here](https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/named-entity-types?tabs=personal#government-and-countryregion-specific-identification). Also, this is the output of the updated sample: ``` Running recognizePii sample The redacted text is "My phone number is ********" and found the following PII entities - "555-5555" of type PhoneNumber There are no PHI entities in this text: "His EU passport number is X65097105" Also there is nothing to redact: "His EU passport number is X65097105" But there are other PII entities in that text: - "X65097105" of type EUPassportNumber You can choose to get SSN entities only, or any other PII category or a combination of them. For example, in this text: "Patient name is Joe and SSN is 859-98-0987", this is the SSN number: - "859-98-0987" ``` - adds a new npm script `execute:sample` to run individual samples. - fixes a bug in the javascript sample for beginAnalyzeHealthcareEntities. - re-enable text analytics samples in smoke tests. The javascript samples still fail with `node8` because of the lack of support for `ES6`, but this is fine because we should always write our samples using the recent features of the language and we do not want them to look outdated.
1 parent bbc78d0 commit 91c1788

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

sdk/textanalytics/ai-text-analytics/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"node": ">=8.0.0"
4545
},
4646
"//sampleConfiguration": {
47-
"skipFolder": true
47+
"skipFolder": false
4848
},
4949
"browser": {
5050
"./dist-esm/src/utils/url.js": "./dist-esm/src/utils/url.browser.js",
@@ -61,6 +61,7 @@
6161
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
6262
"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
6363
"execute:samples": "npm run build:samples && dev-tool samples run dist-samples/javascript dist-samples/typescript/dist/dist-samples/typescript/src/",
64+
"execute:sample": "npm run build:samples && dev-tool samples run",
6465
"extract-api": "tsc -p . && api-extractor run --local",
6566
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
6667
"integration-test:browser": "karma start --single-run",

sdk/textanalytics/ai-text-analytics/samples/javascript/beginAnalyzeHealthcareEntities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function main() {
6060
}
6161
}
6262
}
63-
if (result.entityRelations?.length > 0) {
63+
if (result.entityRelations !== undefined && result.entityRelations.length > 0) {
6464
console.log(`\tRecognized relations between entities:`);
6565
for (const relation of result.entityRelations) {
6666
console.log(

sdk/textanalytics/ai-text-analytics/samples/javascript/recognizePii.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ async function main() {
2525
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
2626

2727
const textOnePii = "My phone number is 555-5555";
28-
const textNoPHI =
29-
"FIFA is a non-profit organization which describes itself as an international governing body of association football.";
28+
const textNoPHI = "His EU passport number is X65097105";
3029
const textMultiplePIIs = "Patient name is Joe and SSN is 859-98-0987";
3130

3231
const [result] = await client.recognizePiiEntities([textOnePii]);
@@ -40,13 +39,12 @@ async function main() {
4039
}
4140
}
4241

43-
console.log(`There are no PHI entities in this text: ${textNoPHI}`);
44-
const [resultWithPHI] = await client.recognizePiiEntities(
45-
[{ id: "0", text: textNoPHI, language: "en" }],
46-
{ domainFilter: PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION }
47-
);
42+
console.log(`There are no PHI entities in this text: "${textNoPHI}"`);
43+
const [resultWithPHI] = await client.recognizePiiEntities([textNoPHI], "en", {
44+
domainFilter: PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION
45+
});
4846
if (!resultWithPHI.error) {
49-
console.log(`Also there is nothing to redact: ${resultWithPHI.redactedText}`);
47+
console.log(`Also there is nothing to redact: "${resultWithPHI.redactedText}"`);
5048
assert(resultWithPHI.entities.length === 0, "did not expect any entities but got some");
5149
}
5250

@@ -61,7 +59,9 @@ async function main() {
6159
categoriesFilter: ["USSocialSecurityNumber"]
6260
});
6361
if (!resultWithSSNPII.error) {
64-
console.log("The service was asked to return just SSN entities:");
62+
console.log(
63+
`You can choose to get SSN entities only, or any other PII category or a combination of them. For example, in this text: "${textMultiplePIIs}", this is the SSN number:`
64+
);
6565
for (const entity of resultWithSSNPII.entities) {
6666
console.log(`\t- "${entity.text}"`);
6767
assert(entity.category === "USSocialSecurityNumber");

sdk/textanalytics/ai-text-analytics/samples/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
"devDependencies": {
3737
"@types/node": "^8.0.0",
3838
"rimraf": "^3.0.0",
39-
"typescript": "~3.6.4"
39+
"typescript": "latest"
4040
}
4141
}

sdk/textanalytics/ai-text-analytics/samples/typescript/src/recognizePii.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export async function main() {
2626
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
2727

2828
const textOnePii = "My phone number is 555-5555";
29-
const textNoPHI =
30-
"FIFA is a non-profit organization which describes itself as an international governing body of association football.";
29+
const textNoPHI = "His EU passport number is X65097105";
3130
const textMultiplePIIs = "Patient name is Joe and SSN is 859-98-0987";
3231

3332
const [result] = await client.recognizePiiEntities([textOnePii]);
@@ -41,13 +40,12 @@ export async function main() {
4140
}
4241
}
4342

44-
console.log(`There are no PHI entities in this text: ${textNoPHI}`);
45-
const [resultWithPHI] = await client.recognizePiiEntities(
46-
[{ id: "0", text: textNoPHI, language: "en" }],
47-
{ domainFilter: PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION }
48-
);
43+
console.log(`There are no PHI entities in this text: "${textNoPHI}"`);
44+
const [resultWithPHI] = await client.recognizePiiEntities([textNoPHI], "en", {
45+
domainFilter: PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION
46+
});
4947
if (!resultWithPHI.error) {
50-
console.log(`Also there is nothing to redact: ${resultWithPHI.redactedText}`);
48+
console.log(`Also there is nothing to redact: "${resultWithPHI.redactedText}"`);
5149
assert(resultWithPHI.entities.length === 0, "did not expect any entities but got some");
5250
}
5351

@@ -62,7 +60,9 @@ export async function main() {
6260
categoriesFilter: ["USSocialSecurityNumber"]
6361
});
6462
if (!resultWithSSNPII.error) {
65-
console.log("The service was asked to return just SSN entities:");
63+
console.log(
64+
`You can choose to get SSN entities only, or any other PII category or a combination of them. For example, in this text: "${textMultiplePIIs}", this is the SSN number:`
65+
);
6666
for (const entity of resultWithSSNPII.entities) {
6767
console.log(`\t- "${entity.text}"`);
6868
assert(entity.category === "USSocialSecurityNumber");

sdk/textanalytics/ai-text-analytics/samples/typescript/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"strict": true,
99
"alwaysStrict": true,
1010

11+
"target": "ES6",
12+
1113
"outDir": "dist",
1214
"rootDir": "src"
1315
},

0 commit comments

Comments
 (0)