removed duplicate definitions fromm end json
This commit is contained in:
parent
2ca923889e
commit
2dcf2a840e
|
@ -6,43 +6,38 @@ const pipeline = fs.createReadStream('data/dp/wiktionary-grouped-objects-array.j
|
|||
const sqlite3 = require("sqlite3").verbose()
|
||||
const db = new sqlite3.Database("data/database")
|
||||
|
||||
const queries = []
|
||||
|
||||
pipeline.on('data', data => {
|
||||
const term = data.value.word
|
||||
// if(term==="unpalatable"){console.log("test word found!!")}
|
||||
const object = JSON.stringify(makeObject(data.value))
|
||||
// db.run('UPDATE prompts SET object=? WHERE word=?',[object,term],
|
||||
// function(err){
|
||||
// if(err){return console.error(err.message)}
|
||||
// console.log(`word: ${term} -- ${this.changes} changes`)
|
||||
// console.log(`object: ${object}`)
|
||||
// })
|
||||
const term = data.value.word
|
||||
if (term === "unpalatable") { console.log("test word found!!") }
|
||||
const rawMeanings = JSON.stringify(makeObject(data.value))
|
||||
db.run('UPDATE prompts SET object=? WHERE word=?', [object, term],
|
||||
function (err) {
|
||||
if (err) { return console.error(err.message) }
|
||||
console.log(`word: ${term} -- ${this.changes} changes`)
|
||||
console.log(`object: ${object}`)
|
||||
})
|
||||
console.log(`object: ${object}`)
|
||||
});
|
||||
|
||||
queries.push(`${queries}UPDATE prompts
|
||||
SET object='${object}'
|
||||
WHERE word='${term}';
|
||||
`)
|
||||
console.log(queries)
|
||||
});
|
||||
|
||||
db.exec(queries.join()).close(err=>{
|
||||
if(err){return console.error(err.message)}
|
||||
console.log("Database closed successfully")
|
||||
})
|
||||
db.close()
|
||||
|
||||
|
||||
const makeObject = (obj) => {
|
||||
const meaningsArray = []
|
||||
obj.data.forEach(element => {
|
||||
meaningsArray.push({
|
||||
type:element.type,
|
||||
definition:element.definition[0]
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
for(let i=0; i<=obj.meanings.length-1;i++){
|
||||
meaningsArray.push({
|
||||
type: element.type,
|
||||
definition: element.definition[0]
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
word: obj.word,
|
||||
pronunciation: obj.data[0].pronunciation,
|
||||
pronunciation: obj.pronunciation,
|
||||
meanings: meaningsArray
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue