aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/ClientRecommender.tsx (renamed from src/client/ClientRecommender.ts)57
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx4
-rw-r--r--src/server/Recommender.ts2
3 files changed, 57 insertions, 6 deletions
diff --git a/src/client/ClientRecommender.ts b/src/client/ClientRecommender.tsx
index 7ff79ab50..2344ee490 100644
--- a/src/client/ClientRecommender.ts
+++ b/src/client/ClientRecommender.tsx
@@ -2,19 +2,31 @@ import { Doc } from "../new_fields/Doc";
import { StrCast } from "../new_fields/Types";
import { List } from "../new_fields/List";
import { CognitiveServices } from "./cognitive_services/CognitiveServices";
-
-
+import React = require("react");
+import { observer } from "mobx-react";
+import { observable, action, computed, reaction } from "mobx";
var assert = require('assert');
+import Table from 'react-bootstrap/Table';
+
+export interface RecommenderProps {
+ title: string;
+}
-export class ClientRecommender {
+@observer
+export class ClientRecommender extends React.Component<RecommenderProps> {
static Instance: ClientRecommender;
private docVectors: Set<number[]>;
+ private corr_matrix = observable([[0, 0], [0, 0]]);
+ @observable private firstnum = 0;
+ //@observable private corr_matrix: number[][] = [[0, 0], [0, 0]];
- constructor() {
+ constructor(props: RecommenderProps) {
//console.log("creating client recommender...");
+ super(props);
ClientRecommender.Instance = this;
this.docVectors = new Set<number[]>();
+ //this.corr_matrix = [[0, 0], [0, 0]];
}
@@ -84,10 +96,13 @@ export class ClientRecommender {
* Creates distance matrix for all Documents analyzed
*/
+ @action
public createDistanceMatrix(documents: Set<number[]> = this.docVectors) {
+ //this.corr_matrix[0][0] = 500;
+ this.firstnum = 500;
const documents_list = Array.from(documents);
const n = documents_list.length;
- var matrix = new Array(n).fill(0).map(() => new Array(n).fill(0));
+ var matrix = new Array<number>(n).fill(0).map(() => new Array<number>(n).fill(0));
for (let i = 0; i < n; i++) {
var doc1 = documents_list[i];
for (let j = 0; j < n; j++) {
@@ -95,7 +110,39 @@ export class ClientRecommender {
matrix[i][j] = this.distance(doc1, doc2);
}
}
+ //this.corr_matrix = matrix;
+
return matrix;
}
+ @computed get first_num() {
+ return this.firstnum;
+ }
+
+ dumb_reaction = reaction(
+ () => this.first_num,
+ number => {
+ console.log("number has changed", number);
+ this.forceUpdate();
+ }
+ );
+
+ render() {
+ return (<div>
+ <h3>{this.props.title ? this.props.title : "hello"}</h3>
+ <table>
+ <tbody>
+ <tr>
+ <td>{this.first_num}</td>
+ <td>{this.corr_matrix[0][1]}</td>
+ </tr>
+ <tr>
+ <td>{this.corr_matrix[1][0]}</td>
+ <td>{this.corr_matrix[1][1]}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>);
+ }
+
} \ No newline at end of file
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 9344b43d2..5259b9b49 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -523,6 +523,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
super.setCursorPosition(this.getTransform().transformPoint(e.clientX, e.clientY));
}
+ @action
onContextMenu = (e: React.MouseEvent) => {
let layoutItems: ContextMenuProps[] = [];
layoutItems.push({
@@ -600,7 +601,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
ContextMenu.Instance.addItem({
description: "Recommender System",
event: async () => {
- new ClientRecommender();
+ // if (!ClientRecommender.Instance) new ClientRecommender({ title: "Client Recommender" });
let activedocs = this.getActiveDocuments();
await Promise.all(activedocs.map((doc: Doc) => {
console.log(StrCast(doc.title));
@@ -715,6 +716,7 @@ class CollectionFreeFormViewPannableContents extends React.Component<CollectionF
const zoom = this.props.zoomScaling();// needs to be a variable outside of the <Measure> otherwise, reactions won't fire
return <div className={freeformclass} style={{ borderRadius: "inherit", transform: `translate(${cenx}px, ${ceny}px) scale(${zoom}, ${zoom}) translate(${panx}px, ${pany}px)` }}>
{this.props.children}
+ <ClientRecommender title="Correlation Matrix" />
</div>;
}
} \ No newline at end of file
diff --git a/src/server/Recommender.ts b/src/server/Recommender.ts
index ea59703c3..d175b67c7 100644
--- a/src/server/Recommender.ts
+++ b/src/server/Recommender.ts
@@ -10,6 +10,7 @@ export class Recommender {
private _model: any;
static Instance: Recommender;
+ private dimension: number = 0;
constructor() {
console.log("creating recommender...");
@@ -25,6 +26,7 @@ export class Recommender {
return new Promise(res => {
w2v.loadModel("./node_modules/word2vec/vectors.txt", function (err: any, model: any) {
self._model = model;
+ self.dimension = model.size;
res(model);
});
});