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 sqlite3 = require("sqlite3").verbose()
|
||||||
const db = new sqlite3.Database("data/database")
|
const db = new sqlite3.Database("data/database")
|
||||||
|
|
||||||
const queries = []
|
|
||||||
|
|
||||||
pipeline.on('data', data => {
|
pipeline.on('data', data => {
|
||||||
const term = data.value.word
|
const term = data.value.word
|
||||||
// if(term==="unpalatable"){console.log("test word found!!")}
|
if (term === "unpalatable") { console.log("test word found!!") }
|
||||||
const object = JSON.stringify(makeObject(data.value))
|
const rawMeanings = JSON.stringify(makeObject(data.value))
|
||||||
// db.run('UPDATE prompts SET object=? WHERE word=?',[object,term],
|
db.run('UPDATE prompts SET object=? WHERE word=?', [object, term],
|
||||||
// function(err){
|
function (err) {
|
||||||
// if(err){return console.error(err.message)}
|
if (err) { return console.error(err.message) }
|
||||||
// console.log(`word: ${term} -- ${this.changes} changes`)
|
console.log(`word: ${term} -- ${this.changes} changes`)
|
||||||
// console.log(`object: ${object}`)
|
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=>{
|
db.close()
|
||||||
if(err){return console.error(err.message)}
|
|
||||||
console.log("Database closed successfully")
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const makeObject = (obj) => {
|
const makeObject = (obj) => {
|
||||||
const meaningsArray = []
|
const meaningsArray = []
|
||||||
obj.data.forEach(element => {
|
|
||||||
|
|
||||||
|
|
||||||
|
for(let i=0; i<=obj.meanings.length-1;i++){
|
||||||
meaningsArray.push({
|
meaningsArray.push({
|
||||||
type: element.type,
|
type: element.type,
|
||||||
definition: element.definition[0]
|
definition: element.definition[0]
|
||||||
})
|
})
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
word: obj.word,
|
word: obj.word,
|
||||||
pronunciation: obj.data[0].pronunciation,
|
pronunciation: obj.pronunciation,
|
||||||
meanings: meaningsArray
|
meanings: meaningsArray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue