diff options
| author | ab <abdullah_ahmed@brown.edu> | 2019-08-01 16:29:56 -0400 |
|---|---|---|
| committer | ab <abdullah_ahmed@brown.edu> | 2019-08-01 16:29:56 -0400 |
| commit | 131f3fa7d1f1a42be58de63ee54fecd20e6d9fbf (patch) | |
| tree | b895ca01909735d73b4d3fd0e939bbd1a75d52bb /src/client/cognitive_services | |
| parent | c423f607d09e49eadc0140ddcbf8e268b702d996 (diff) | |
key words successfully extracted
Diffstat (limited to 'src/client/cognitive_services')
| -rw-r--r-- | src/client/cognitive_services/CognitiveServices.ts | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts index c118d91d3..8aac20084 100644 --- a/src/client/cognitive_services/CognitiveServices.ts +++ b/src/client/cognitive_services/CognitiveServices.ts @@ -19,7 +19,8 @@ export type Rectangle = { top: number, left: number, width: number, height: numb export enum Service { ComputerVision = "vision", Face = "face", - Handwriting = "handwriting" + Handwriting = "handwriting", + Text = "text" } export enum Confidence { @@ -211,4 +212,51 @@ export namespace CognitiveServices { } + export namespace Text { + export const Manager: APIManager<string> = { + converter: (data: string) => { + return JSON.stringify({ + documents: [{ + id: 1, + language: "en", + text: data + }] + }); + }, + requester: async (apiKey: string, body: string, service: Service) => { + let serverAddress = "https://eastus.api.cognitive.microsoft.com"; + let endpoint = serverAddress + "/text/analytics/v2.1/keyPhrases"; + let sampleBody = { + "documents": [ + { + "language": "en", + "id": 1, + "text": "Hello world. This is some input text that I love." + } + ] + }; + let actualBody = body; + const options = { + uri: endpoint, + body: actualBody, + headers: { + 'Content-Type': 'application/json', + 'Ocp-Apim-Subscription-Key': apiKey + } + + }; + console.log("requested!"); + return request.post(options); + }, + analyzer: async (target: Doc, keys: string[], data: string, converter: Converter) => { + let results = await ExecuteQuery<string, any>(Service.Text, Manager, data); + console.log(results); + converter(results); + //target[keys[0]] = Docs.Get.DocumentHierarchyFromJson(results, "Key Word Analysis"); + console.log("analyzed!"); + return null; + } + }; + } + }
\ No newline at end of file |
