1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* eslint-disable no-use-before-define */
import { DocumentType } from '../../documents/DocumentTypes';
export interface IDocRequest {
id: string;
title: string;
text: string;
type: string;
}
export const fetchRecommendations = async (src: string, query: string, docs?: IDocRequest[], dummy?: boolean) => {
console.log('[rec] making request');
if (dummy) {
return {
recommendations: [], // dummyRecs,
keywords: dummyKeywords,
num_recommendations: 4,
max_x: 100,
max_y: 100,
min_x: 0,
min_y: 0,
};
}
const response = await fetch('http://127.0.0.1:8000/recommend', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
src: src,
query: query,
docs: docs,
}),
});
const data = await response.json();
return data;
};
export const fetchKeywords = async (text: string, n: number, dummy?: boolean) => {
console.log('[fetchKeywords]');
if (dummy) {
return {
keywords: dummyKeywords,
};
}
const response = await fetch('http://127.0.0.1:8000/keywords', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: text,
n: n,
}),
});
const data = await response.json();
return data;
};
export const getType = (type: DocumentType | string) => {
switch (type) {
case DocumentType.AUDIO:
return 'Audio';
case DocumentType.VID:
return 'Video';
case DocumentType.PDF:
return 'PDF';
case DocumentType.WEB:
return 'Webpage';
case 'YouTube':
return 'Video';
case 'HTML':
return 'Webpage';
default:
return 'Unknown: ' + type;
}
};
/*
const dummyRecs = {
a: {
title: 'Vannevar Bush - American Engineer',
previewUrl: 'https://cdn.britannica.com/98/23598-004-1E6A382E/Vannevar-Bush-Differential-Analyzer-1935.jpg',
type: 'web',
distance: 2.3,
source: 'www.britannica.com',
related_concepts: ['vannevar bush', 'knowledge'],
embedding: {
x: 0,
y: 0,
},
},
b: {
title: "From Memex to hypertext: Vannevar Bush and the mind's machine",
type: 'pdf',
distance: 5.4,
source: 'Google Scholar',
related_concepts: ['memex', 'vannevar bush', 'hypertext'],
},
c: {
title: 'How the hyperlink changed everything | Small Thing Big Idea, a TED series',
previewUrl: 'https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/b17d043f-2642-4117-a913-52204505513f/MargaretGouldStewart_2018V-embed.jpg?u%5Br%5D=2&u%5Bs%5D=0.5&u%5Ba%5D=0.8&u%5Bt%5D=0.03&quality=82w=640',
type: 'youtube',
distance: 5.3,
source: 'www.youtube.com',
related_concepts: ['User Control', 'Explanations'],
},
d: {
title: 'Recommender Systems: Behind the Scenes of Machine Learning-Based Personalization',
previewUrl: 'https://sloanreview.mit.edu/wp-content/uploads/2018/10/MAG-Ransbotham-Ratings-Recommendations-1200X627-1200x627.jpg',
type: 'pdf',
distance: 9.3,
source: 'www.altexsoft.com',
related_concepts: ['User Control', 'Explanations'],
},
};
*/
const dummyKeywords = ['user control', 'vannevar bush', 'hypermedia', 'hypertext'];
|