aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdullah Ahmed <abdullah_ahmed@brown.edu>2019-10-07 11:02:20 -0400
committerAbdullah Ahmed <abdullah_ahmed@brown.edu>2019-10-07 11:02:20 -0400
commit1c75007a5b12224009d0ccfd531e7406b0792760 (patch)
treee8a4a66e55ae96fcc9e70af6f8398fd48de0963b
parent57b57b2d82b385ec9aa9d59c0899dc8f48a31223 (diff)
idk
-rw-r--r--package.json2
-rw-r--r--src/client/ClientRecommender.tsx11
-rw-r--r--src/client/cognitive_services/CognitiveServices.ts7
-rw-r--r--src/new_fields/FieldSymbols.ts3
-rw-r--r--src/new_fields/RichTextField.ts6
5 files changed, 20 insertions, 9 deletions
diff --git a/package.json b/package.json
index 2868c79a1..fbed088fd 100644
--- a/package.json
+++ b/package.json
@@ -235,4 +235,4 @@
"xoauth2": "^1.2.0",
"youtube": "^0.1.0"
}
-} \ No newline at end of file
+}
diff --git a/src/client/ClientRecommender.tsx b/src/client/ClientRecommender.tsx
index 14af0a69b..b4a496563 100644
--- a/src/client/ClientRecommender.tsx
+++ b/src/client/ClientRecommender.tsx
@@ -10,7 +10,8 @@ var sw = require('stopword');
var FeedParser = require('feedparser');
import "./ClientRecommender.scss";
import { JSXElement } from "babel-types";
-import { ToPlainText, RichTextField } from "../new_fields/RichTextField";
+import { RichTextField } from "../new_fields/RichTextField";
+import { ToPlainText } from "../new_fields/FieldSymbols";
export interface RecommenderProps {
title: string;
@@ -166,15 +167,19 @@ export class ClientRecommender extends React.Component<RecommenderProps> {
});
});
this.highKP = highKP;
- console.log(highKP);
+ //console.log(highKP);
const kts_counted = new List<string>();
keyterms_counted.forEach(kt => kts_counted.push(kt.toLowerCase()));
const values = await this.sendRequest(highKP);
return { keyterms: keyterms, keyterms_counted: kts_counted, values };
};
- return CognitiveServices.Text.Appliers.analyzer(dataDoc, extDoc, ["key words"], data, converter, mainDoc, internal);
+ if (data != "") {
+ return CognitiveServices.Text.Appliers.analyzer(dataDoc, extDoc, ["key words"], data, converter, mainDoc, internal);
+ }
+ return;
}
+
private countFrequencies(keyphrase: string, paragraph: string) {
let data = paragraph.split(" ");
let kp_array = keyphrase.split(" ");
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts
index 7c660c347..e391b98d2 100644
--- a/src/client/cognitive_services/CognitiveServices.ts
+++ b/src/client/cognitive_services/CognitiveServices.ts
@@ -269,12 +269,13 @@ export namespace CognitiveServices {
//keyterms = ["father", "king"];
let args = { method: 'POST', uri: Utils.prepend("/recommender"), body: { keyphrases: keyterms }, json: true };
await requestPromise.post(args).then(async (wordvecs) => {
- if (wordvecs.length > 0) {
+ if (wordvecs) {
+ let indices = Object.keys(wordvecs);
console.log("successful vectorization!");
var vectorValues = new Set<number[]>();
- wordvecs.forEach((wordvec: any) => {
+ indices.forEach((ind: any) => {
//console.log(wordvec.word);
- vectorValues.add(wordvec as number[]);
+ vectorValues.add(wordvecs[ind]);
});
ClientRecommender.Instance.mean(vectorValues, dataDoc, mainDoc);
} // adds document to internal doc set
diff --git a/src/new_fields/FieldSymbols.ts b/src/new_fields/FieldSymbols.ts
index b5b3aa588..8e5161dac 100644
--- a/src/new_fields/FieldSymbols.ts
+++ b/src/new_fields/FieldSymbols.ts
@@ -7,4 +7,5 @@ export const Id = Symbol("Id");
export const OnUpdate = Symbol("OnUpdate");
export const Parent = Symbol("Parent");
export const Copy = Symbol("Copy");
-export const ToScriptString = Symbol("ToScriptString"); \ No newline at end of file
+export const ToScriptString = Symbol("ToScriptString");
+export const ToPlainText = Symbol("ToPlainText"); \ No newline at end of file
diff --git a/src/new_fields/RichTextField.ts b/src/new_fields/RichTextField.ts
index d2f76c969..390045ee1 100644
--- a/src/new_fields/RichTextField.ts
+++ b/src/new_fields/RichTextField.ts
@@ -1,7 +1,7 @@
import { ObjectField } from "./ObjectField";
import { serializable } from "serializr";
import { Deserializable } from "../client/util/SerializationHelper";
-import { Copy, ToScriptString } from "./FieldSymbols";
+import { Copy, ToScriptString, ToPlainText } from "./FieldSymbols";
import { scriptingGlobal } from "../client/util/Scripting";
@scriptingGlobal
@@ -23,4 +23,8 @@ export class RichTextField extends ObjectField {
return `new RichTextField("${this.Data}")`;
}
+ [ToPlainText]() {
+ return this.Data;
+ }
+
} \ No newline at end of file