Skip to content

Commit

Permalink
[Language Text] Mitigating bug in auto detected language for TA4H
Browse files Browse the repository at this point in the history
  • Loading branch information
deyaaeldeen committed Nov 4, 2022
1 parent a8a5e9e commit 9d39baf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 29 deletions.

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.

43 changes: 30 additions & 13 deletions sdk/cognitivelanguage/ai-language-text/src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
CustomEntitiesResultDocumentsItem,
ExtractedSummaryDocumentResultWithDetectedLanguage,
AbstractiveSummaryDocumentResultWithDetectedLanguage,
HealthcareResultDocumentsItem,
DetectedLanguage,
} from "./generated";
import {
AnalyzeActionName,
Expand All @@ -74,6 +76,7 @@ import {
TextAnalysisError,
TextAnalysisErrorResult,
TextAnalysisSuccessResult,
WithDetectedLanguage,
} from "./models";
import {
AssessmentIndex,
Expand Down Expand Up @@ -392,20 +395,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
3 changes: 2 additions & 1 deletion sdk/cognitivelanguage/ai-language-text/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ generate-metadata: false
license-header: MICROSOFT_MIT_NO_VERSION
output-folder: ../
source-code-folder-path: ./src/generated
input-file: https://github.com/Azure/azure-rest-api-specs/blob/ac205086f477776e8d9aa4ff771e98f174afbea2/specification/cognitiveservices/data-plane/Language/preview/2022-10-01-preview/analyzetext.json
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
v3: true
Expand Down

0 comments on commit 9d39baf

Please sign in to comment.