-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.js
More file actions
75 lines (68 loc) · 1.85 KB
/
Copy pathservices.js
File metadata and controls
75 lines (68 loc) · 1.85 KB
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
function Movie(Movie_Name, Genre, Plot, Directors, Stars) {
this.Movie_Name = Movie_Name;
this.Genre = Genre;
this.Plot = Plot;
this.Directors = Directors;
this.Stars = Stars;
}
function tokenize(text) {
return text.split(/\W+/).filter(token => token.length > 0);
}
function stopwordFilter(tokens) {
const stopwords = {
"movie_name": true,
"genre": true,
"plot": true,
"an": true,
"directors": true,
"stars": true,
"a": true,
"and": true,
"be": true,
"have": true,
"i": true,
"in": true,
"of": true,
"that": true,
"the": true,
"to": true
};
const result = [];
for (let token of tokens) {
if (!stopwords[token]) {
result.push(token);
}
}
return result;
}
function GetTokens(text) {
let tokens = tokenize(text);
tokens = lowercaseFilter(tokens);
tokens = stopwordFilter(tokens)
return tokens;
}
function lowercaseFilter(tokens) {
return tokens.map(token => token.toLowerCase());
}
function intersection(a, b) {
const maxLen = Math.max(a.length, b.length);
const r = [];
let i = 0, j = 0;
while (i < a.length && j < b.length) {
if (a[i] < b[j]) {
i++;
} else if (a[i] > b[j]) {
j++;
} else {
r.push(a[i]);
i++;
j++;
}
}
return r;
}
module.exports = {
Movie,
GetTokens,
intersection
};