forked from weaviate/weaviate-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_data.js
122 lines (113 loc) · 2.92 KB
/
add_data.js
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
const pd = require("node-pandas")
const weaviate = require("weaviate-client");
// set up client
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
// form the schema
classObj = {
"class": "Movies",
"description": "Various Info about movies",
"properties": [
{
"name": "title",
"dataType": ["string"],
"description": "The name of the movie",
},
{
"name": "genres",
"dataType": ["string"],
"description": "The genres of the movie",
},
{
"name": "overview",
"dataType": ["string"],
"description": "overview of the movie",
},
{
"name": "keywords",
"dataType": ["string"],
"description": "main keywords of the movie",
},
{
"name": "popularity",
"dataType": ["number"],
"description": "popularity of the movie",
},
{
"name": "runtime",
"dataType": ["number"],
"description": "runtime of the movie",
},
{
"name": "cast",
"dataType": ["string"],
"description": "The cast of the movie",
},
{
"name": "language",
"dataType": ["string"],
"description": "language in which movie was made",
},
{
"name": "tagline",
"dataType": ["string"],
"description": "tagline of the movie",
},
{
"name": "revenue",
"dataType": ["number"],
"description": "revenue of the movie",
},
{
"name": "director",
"dataType": ["string"],
"description": "Director of the movie",
},
]
}
// provision the schema
client
.schema
.classCreator()
.withClass(classObj)
.do()
.then(res => {
console.log(res)
})
.catch(err => {
console.error(err)
});
// load and preprocessing the dataset
data=pd.readCsv("./movies.csv")
// iterate movies and push objects
data.forEach(function(movie){
try {
movie_object = {
'title': movie['original_title'],
'genres': movie['genres'],
'overview':movie['overview'],
'keywords': movie['keywords'],
'popularity': parseFloat(movie['popularity']),
'runtime': parseInt(movie['runtime']),
'cast': movie['cast'],
'language': movie['original_language'],
'tagline': movie['tagline'],
'revenue': parseInt(movie['revenue']),
'director': movie['director']
}
client.data
.creator()
.withClassName('Movies')
.withProperties(movie_object)
.do()
.then(res => {
console.log(res)
})
.catch(err => {
console.error(err)
});
} catch(e) { console.log(e) }
})
// That's all!