From a231b597d70f8ee9e435a86b00020c93691dc97d Mon Sep 17 00:00:00 2001
From: ab <abdullah_ahmed@brown.edu>
Date: Sat, 23 Nov 2019 16:06:30 -0500
Subject: keyphrase query ui

---
 src/client/views/KeyphraseQueryView.tsx | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 src/client/views/KeyphraseQueryView.tsx

(limited to 'src/client/views/KeyphraseQueryView.tsx')

diff --git a/src/client/views/KeyphraseQueryView.tsx b/src/client/views/KeyphraseQueryView.tsx
new file mode 100644
index 000000000..1955399f9
--- /dev/null
+++ b/src/client/views/KeyphraseQueryView.tsx
@@ -0,0 +1,30 @@
+import { observer } from "mobx-react";
+import React = require("react");
+import "./KeyphraseQueryView.scss";
+
+// tslint:disable-next-line: class-name
+export interface KP_Props {
+    keyphrases: string[];
+}
+
+@observer
+export class KeyphraseQueryView extends React.Component<KP_Props>{
+    constructor(props: KP_Props) {
+        super(props);
+        console.log("FIRST KEY PHRASE: ", props.keyphrases[0]);
+    }
+
+    render() {
+        return (
+            <div>
+                <h1>Select queries to send:</h1>
+                {this.props.keyphrases.map((kp: string) => {
+                    setTimeout(() => {
+                        return (<p className="fading">{kp}</p>);
+                    }, 1000);
+
+                })}
+            </div>
+        );
+    }
+}
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 07141291bee793955d7061f4e479942d7aceda67 Mon Sep 17 00:00:00 2001
From: ab <abdullah_ahmed@brown.edu>
Date: Wed, 4 Dec 2019 16:08:12 -0500
Subject: user queries stuff

---
 src/client/ClientRecommender.tsx                   | 13 +++++++++---
 src/client/cognitive_services/CognitiveServices.ts |  2 +-
 src/client/views/KeyphraseQueryView.tsx            | 21 +++++++++++--------
 src/client/views/nodes/DocumentView.tsx            | 24 +++++++++++++++++-----
 4 files changed, 43 insertions(+), 17 deletions(-)

(limited to 'src/client/views/KeyphraseQueryView.tsx')

diff --git a/src/client/ClientRecommender.tsx b/src/client/ClientRecommender.tsx
index b384a8ebe..83aed0204 100644
--- a/src/client/ClientRecommender.tsx
+++ b/src/client/ClientRecommender.tsx
@@ -45,6 +45,7 @@ export class ClientRecommender extends React.Component<RecommenderProps> {
     static Instance: ClientRecommender;
     private mainDoc?: RecommenderDocument;
     private docVectors: Set<RecommenderDocument> = new Set();
+    public _queries: string[] = [];
 
     @observable private corr_matrix = [[0, 0], [0, 0]]; // for testing
 
@@ -277,11 +278,17 @@ export class ClientRecommender extends React.Component<RecommenderProps> {
                     const sorted_keywords = response.result.keywords;
                     if (sorted_keywords.length > 0) {
                         console.log("IBM keyphrase", sorted_keywords[0]);
-                        highKP = [sorted_keywords[0].text];
+                        highKP = [];
+                        for (let i = 0; i < 5; i++) {
+                            if (sorted_keywords[i]) {
+                                highKP.push(sorted_keywords[i].text);
+                            }
+                        }
+                        keyterms = new List<string>(highKP);
                     }
                 });
-                let kpqv = new KeyphraseQueryView({ keyphrases: ["hello"] });
-                ext_recs = await this.sendRequest(highKP, api);
+                //let kpqv = new KeyphraseQueryView({ keyphrases: ["hello"] });
+                ext_recs = await this.sendRequest([highKP[0]], api);
             }
 
             // keyterms: list for extDoc, kp_string: input to TF, ext_recs: {titles, urls} of retrieved results from highKP query
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts
index 356cf52ca..94532aaaa 100644
--- a/src/client/cognitive_services/CognitiveServices.ts
+++ b/src/client/cognitive_services/CognitiveServices.ts
@@ -398,7 +398,7 @@ export namespace CognitiveServices {
                     //await vectorize([data], dataDoc, isMainDoc);
                     await vectorize(kp_string, dataDoc, isMainDoc);
                 } else {
-                    return external_recommendations;
+                    return { recs: external_recommendations, keyterms: keyterms };
                 }
             };
 
diff --git a/src/client/views/KeyphraseQueryView.tsx b/src/client/views/KeyphraseQueryView.tsx
index 1955399f9..a9dafc4a4 100644
--- a/src/client/views/KeyphraseQueryView.tsx
+++ b/src/client/views/KeyphraseQueryView.tsx
@@ -4,7 +4,7 @@ import "./KeyphraseQueryView.scss";
 
 // tslint:disable-next-line: class-name
 export interface KP_Props {
-    keyphrases: string[];
+    keyphrases: string;
 }
 
 @observer
@@ -15,15 +15,20 @@ export class KeyphraseQueryView extends React.Component<KP_Props>{
     }
 
     render() {
+        let kps = this.props.keyphrases.toString();
+        let keyterms = this.props.keyphrases.split(',');
         return (
             <div>
-                <h1>Select queries to send:</h1>
-                {this.props.keyphrases.map((kp: string) => {
-                    setTimeout(() => {
-                        return (<p className="fading">{kp}</p>);
-                    }, 1000);
-
-                })}
+                <h5>Select queries to send:</h5>
+                <form>
+                    {keyterms.map((kp: string) => {
+                        //return (<p>{"-" + kp}</p>);
+                        return (<p><label>
+                            <input name="query" type="radio" />
+                            <span>{kp}</span>
+                        </label></p>);
+                    })}
+                </form>
             </div>
         );
     }
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 079df9cf4..91618491c 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -1,6 +1,6 @@
 import { library } from '@fortawesome/fontawesome-svg-core';
 import * as fa from '@fortawesome/free-solid-svg-icons';
-import { action, computed, runInAction, trace } from "mobx";
+import { action, computed, runInAction, trace, observable } from "mobx";
 import { observer } from "mobx-react";
 import * as rp from "request-promise";
 import { Doc, DocListCast, DocListCastAsync, Opt } from "../../../new_fields/Doc";
@@ -119,6 +119,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
     private _mainCont = React.createRef<HTMLDivElement>();
     private _dropDisposer?: DragManager.DragDropDisposer;
     private _showKPQuery: boolean = false;
+    private _queries: string = "";
 
     public get ContentDiv() { return this._mainCont.current; }
     @computed get active() { return SelectionManager.IsSelected(this) || this.props.parentActive(); }
@@ -643,16 +644,28 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
         // RecommendationsBox.Instance.displayRecommendations(e.pageX + 100, e.pageY);
     }
 
+    @action
     externalRecommendation = async (e: React.MouseEvent, api: string) => {
         if (!ClientRecommender.Instance) new ClientRecommender({ title: "Client Recommender" });
         ClientRecommender.Instance.reset_docs();
         const doc = Doc.GetDataDoc(this.props.Document);
         const extdoc = doc.data_ext as Doc;
-        const values = await ClientRecommender.Instance.extractText(doc, extdoc ? extdoc : doc, false, api);
+        const recs_and_kps = await ClientRecommender.Instance.extractText(doc, extdoc ? extdoc : doc, false, api);
+        let recs: any;
+        let kps: any;
+        if (recs_and_kps) {
+            recs = recs_and_kps.recs;
+            kps = recs_and_kps.keyterms;
+        }
+        else {
+            console.log("recommender system failed :(");
+            return;
+        }
+        console.log("ibm keyterms: ", kps.toString());
         const headers = [new SchemaHeaderField("title"), new SchemaHeaderField("href")];
         let bodies: Doc[] = [];
-        const titles = values.title_vals;
-        const urls = values.url_vals;
+        const titles = recs.title_vals;
+        const urls = recs.url_vals;
         for (let i = 0; i < 5; i++) {
             const body = Docs.Create.FreeformDocument([], { title: titles[i] });
             body.href = urls[i];
@@ -660,6 +673,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
         }
         CollectionDockingView.AddRightSplit(Docs.Create.SchemaDocument(headers, bodies, { title: `Showing External Recommendations for "${StrCast(doc.title)}"` }), undefined);
         this._showKPQuery = true;
+        this._queries = kps.toString();
     }
 
     onPointerEnter = (e: React.PointerEvent): void => { Doc.BrushDoc(this.props.Document); };
@@ -828,7 +842,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
                 }} >
                 {this.innards}
             </div>
-            {this._showKPQuery ? <KeyphraseQueryView keyphrases={["hello", "world"]}></KeyphraseQueryView> : undefined}
+            {this._showKPQuery ? <KeyphraseQueryView keyphrases={this._queries}></KeyphraseQueryView> : undefined}
         </div>;
     }
 }
-- 
cgit v1.2.3-70-g09d2

