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

[Language Text] Mitigating bug in auto detected language for TA4H #23720

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions sdk/cognitivelanguage/ai-language-text/src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
PiiResult as GeneratedPiiEntityRecognitionResult,
SentenceSentiment as GeneratedSentenceSentiment,
SentimentResponse as GeneratedSentimentAnalysisResult,
HealthcareEntitiesDocumentResult,
HealthcareLROResult,
HealthcareRelation,
HealthcareRelationEntity,
Expand All @@ -50,6 +49,8 @@ import {
CustomEntitiesResultDocumentsItem,
ExtractedSummaryDocumentResultWithDetectedLanguage,
AbstractiveSummaryDocumentResultWithDetectedLanguage,
HealthcareResultDocumentsItem,
DetectedLanguage,
} from "./generated";
import {
AnalyzeActionName,
Expand All @@ -74,6 +75,7 @@ import {
TextAnalysisError,
TextAnalysisErrorResult,
TextAnalysisSuccessResult,
WithDetectedLanguage,
} from "./models";
import {
AssessmentIndex,
Expand Down Expand Up @@ -392,20 +394,34 @@ function toHealthcareResult(
),
});
}
return transformDocumentResults<HealthcareEntitiesDocumentResult, HealthcareSuccessResult>(
docIds,
results,
{
processSuccess: ({ entities, relations, ...rest }) => {
const newEntities = entities.map(makeHealthcareEntity);
return {
entities: newEntities,
entityRelations: relations.map(makeHealthcareRelation(newEntities)),
...rest,
};
},
function deserializeDetectedLanguage(input: string): DetectedLanguage {
function helper(str: string): undefined {
try {
return JSON.parse(str);
} catch (e) {
return undefined;
}
}
);
const obj = helper(input);
return obj !== undefined ? obj : ({ iso6391Name: input } as any);
}
return transformDocumentResults<
HealthcareResultDocumentsItem,
WithDetectedLanguage<HealthcareSuccessResult>
>(docIds, results, {
processSuccess: ({ entities, relations, detectedLanguage, ...rest }) => {
const newEntities = entities.map(makeHealthcareEntity);
return {
entities: newEntities,
entityRelations: relations.map(makeHealthcareRelation(newEntities)),
// FIXME: remove this mitigation when the API fixes the representation on their end
...(detectedLanguage
? { detectedLanguage: deserializeDetectedLanguage(detectedLanguage) }
: {}),
...rest,
};
},
});
}

function toCustomSingleLabelClassificationResult(
Expand Down
15 changes: 15 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ generate-metadata: false
license-header: MICROSOFT_MIT_NO_VERSION
output-folder: ../
source-code-folder-path: ./src/generated
# input-file: ./swagger.json
input-file: https://github.com/Azure/azure-rest-api-specs/blob/ac205086f477776e8d9aa4ff771e98f174afbea2/specification/cognitiveservices/data-plane/Language/preview/2022-10-01-preview/analyzetext.json
add-credentials: false
package-version: 1.1.0-beta.1
Expand Down Expand Up @@ -319,6 +320,20 @@ directive:
where: $.definitions.JobState
transform: $.properties.lastUpdatedDateTime["x-ms-client-name"] = "modifiedOn";

- from: swagger-document
where: $.definitions
transform: >
if (!$.DocumentDetectedLanguageForHealthcare) {
$.DocumentDetectedLanguageForHealthcare = { "type": "object", "properties": { "detectedLanguage": { "type": "string" } } };
}

- from: swagger-document
where: $.definitions.HealthcareResult.properties.documents.items.allOf
transform: >
if ($[1]["$ref"] === "#/definitions/DocumentDetectedLanguage") {
$[1]["$ref"] = "#/definitions/DocumentDetectedLanguageForHealthcare";
}

# Enhance documentation strings for some exported swagger types

- from: swagger-document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8696,7 +8696,7 @@ export const expectation71: any = [
entityRelations: [],
id: "0",
warnings: [],
detectedLanguage: { "0": "e", "1": "n" },
detectedLanguage: { iso6391Name: "en" },
kristapratico marked this conversation as resolved.
Show resolved Hide resolved
isLanguageDefaulted: false,
},
{
Expand Down