-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (31 loc) · 988 Bytes
/
index.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
var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs)
path = require('path');
const pathDir = __dirname + '/nearest_neighbors'
const datastore = require('nedb')
const db = new datastore('./database/database.db')
db.loadDatabase()
realFs.readdir(pathDir, function(err, files){
if (err){
return console.log(err);
}
files.forEach(file => {
// console.log(file)
let fromPath = path.join(pathDir, file)
// console.log(fromPath)
const fileId = file.replace('.json', '')
let dbItem = {
_id: fileId,
fileName: file,
neighbors: {}
}
realFs.readFile(fromPath, (err, data) => {
dbItem.neighbors = JSON.parse(data).filter((item, index) => {
return item.filename !== fileId
}) //first item its self, has similarity 1
db.insert(dbItem)
console.log(fileId)
})
});
});