diff options
| author | ab <abdullah_ahmed@brown.edu> | 2019-08-07 16:28:51 -0400 |
|---|---|---|
| committer | ab <abdullah_ahmed@brown.edu> | 2019-08-07 16:28:51 -0400 |
| commit | 17b27d3575d3f91f461262e5ad72a457238d198a (patch) | |
| tree | 98e6c0a9f5a8f140ff6239a27ebc6f518c87280b /src/client/cognitive_services/CognitiveServices.ts | |
| parent | 06b59a4ec2f1871846696da22928fc7d54ae02d6 (diff) | |
correlation matrix completed
Diffstat (limited to 'src/client/cognitive_services/CognitiveServices.ts')
| -rw-r--r-- | src/client/cognitive_services/CognitiveServices.ts | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts index 863236b60..cc366abc2 100644 --- a/src/client/cognitive_services/CognitiveServices.ts +++ b/src/client/cognitive_services/CognitiveServices.ts @@ -8,6 +8,7 @@ import { InkData } from "../../new_fields/InkField"; import { UndoManager } from "../util/UndoManager"; import requestPromise = require("request-promise"); import { List } from "../../new_fields/List"; +import { ClientRecommender } from "../ClientRecommender"; type APIManager<D> = { converter: BodyConverter<D>, requester: RequestExecutor, analyzer: AnalysisApplier }; type RequestExecutor = (apiKey: string, body: string, service: Service) => Promise<string>; @@ -257,20 +258,21 @@ export namespace CognitiveServices { //target[keys[0]] = Docs.Get.DocumentHierarchyFromJson(results, "Key Word Analysis"); target[keys[0]] = keyterms; console.log("analyzed!"); - vectorize(keyterms); - return null; - }, - - + await vectorize(keyterms); + } }; - function vectorize(keyterms: any) { + async function vectorize(keyterms: any) { console.log("vectorizing..."); - keyterms = ["father", "king"]; + //keyterms = ["father", "king"]; let args = { method: 'POST', uri: Utils.prepend("/recommender"), body: { keyphrases: keyterms }, json: true }; - requestPromise.post(args).then((value) => { - value.forEach((wordvec: any) => { - console.log(wordvec.word); + await requestPromise.post(args).then(async (wordvecs) => { + var vectorValues = new Set<number[]>(); + wordvecs.forEach((wordvec: any) => { + //console.log(wordvec.word); + vectorValues.add(wordvec.values as number[]); }); + ClientRecommender.Instance.mean(vectorValues); + //console.log(vectorValues.size); }); } |
