aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/ClientRecommender.tsx13
-rw-r--r--src/client/cognitive_services/CognitiveServices.ts2
-rw-r--r--src/client/views/KeyphraseQueryView.tsx21
-rw-r--r--src/client/views/nodes/DocumentView.tsx24
4 files changed, 43 insertions, 17 deletions
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>;
}
}