UNPKG

@azure/ai-text-analytics

Version:
53 lines 2.08 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import { makeTextAnalyticsErrorResult, makeTextAnalyticsSuccessResult } from "./textAnalyticsResult"; import { parseHealthcareEntityIndex } from "./util"; /** * Creates a user-friendly healthcare entity represented as a node in a graph * @param entity - the healthcare entity returned by the service * @internal */ function makeHealthcareEntitiesWithoutNeighbors(entity) { var _a; const { category, confidenceScore, assertion, offset, text, links, subcategory, length, name } = entity; return { category, confidenceScore, assertion, offset, length, text, normalizedText: name, subCategory: subcategory, dataSources: (_a = links === null || links === void 0 ? void 0 : links.map(({ dataSource, id }) => ({ name: dataSource, entityId: id }))) !== null && _a !== void 0 ? _a : [] }; } /** * @internal */ function makeHealthcareRelations(entities, relations) { return relations.map((relation) => ({ relationType: relation.relationType, roles: relation.entities.map((role) => ({ entity: entities[parseHealthcareEntityIndex(role.ref)], name: role.role })) })); } /** * Creates a healthcare entity in the convenience layer from the one sent by the service. * @param document - incoming results sent by the service for a particular document * @internal */ export function makeHealthcareEntitiesResult(document) { const { id, entities, relations, warnings, statistics } = document; const newEntities = entities.map(makeHealthcareEntitiesWithoutNeighbors); return Object.assign(Object.assign({}, makeTextAnalyticsSuccessResult(id, warnings, statistics)), { entities: newEntities, entityRelations: makeHealthcareRelations(newEntities, relations) }); } /** * @internal */ export function makeHealthcareEntitiesErrorResult(id, error) { return makeTextAnalyticsErrorResult(id, error); } //# sourceMappingURL=analyzeHealthcareEntitiesResult.js.map