new wiktionary > sqlite import script
This commit is contained in:
parent
bd498ae966
commit
bddb22565c
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
import Knex from 'knex'
|
||||
|
||||
export const db = Knex({
|
||||
client: 'sqlite3', // or 'better-sqlite3'
|
||||
connection: {
|
||||
filename: "../database"
|
||||
}
|
||||
})
|
|
@ -1,13 +1,6 @@
|
|||
import Knex from 'knex';
|
||||
import {db} from './db.mjs'
|
||||
import Spellchecker, { isMisspelled } from 'spellchecker'
|
||||
|
||||
const db = Knex({
|
||||
client: 'sqlite3', // or 'better-sqlite3'
|
||||
connection: {
|
||||
filename: "../database"
|
||||
}
|
||||
})
|
||||
|
||||
const getWords = async (db) => {
|
||||
return db
|
||||
.select("word")
|
||||
|
@ -26,10 +19,8 @@ for (const element of words) {
|
|||
} catch (error) {
|
||||
console.error(error.message)
|
||||
} finally {
|
||||
console.log()
|
||||
}
|
||||
}
|
||||
console.dir(element.word)
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
const fs = require('fs');
|
||||
const pipeline = fs.createReadStream('../processing/wiktionary-grouped-objects-array.json').pipe(StreamArray.withParser());
|
||||
|
||||
const { AsyncDatabase } = require("promised-sqlite3")
|
||||
let db = ""
|
||||
const importJson = async () =>{
|
||||
db = await AsyncDatabase.open("database")
|
||||
json = JSON.parse(fs.readFileSync('../processing/wiktionary-grouped-objects-array.json'))
|
||||
await json.forEach(async (data) => {
|
||||
//console.log(data)
|
||||
if(data?.word){
|
||||
const word = data.word
|
||||
const pronunciation = data.pronunciation
|
||||
const meanings = JSON.stringify(data.meanings)
|
||||
await db.run('UPDATE prompts SET pronunciation=?, meanings=? WHERE word=?', [pronunciation,meanings,word])
|
||||
}});
|
||||
db.close()
|
||||
}
|
||||
|
||||
importJson()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import {db} from './db.mjs'
|
||||
import fs from 'fs'
|
||||
|
||||
const wiktionary = JSON.parse(fs.readFileSync('../processing/wiktionary-p3.json'))
|
||||
|
||||
const sampleElement = {
|
||||
word: 'antinomian',
|
||||
pronunciation: '/æntiˈnoʊmi.ən/',
|
||||
meanings: [
|
||||
{ type: 'noun', definitions: [Array] },
|
||||
{ type: 'adj', definitions: [Array] }
|
||||
]
|
||||
}
|
||||
|
||||
for (const element of wiktionary) {
|
||||
await db('dictionary')
|
||||
.where('word', element.word)
|
||||
.update({
|
||||
pronunciation: element.pronunciation,
|
||||
meanings: JSON.stringify(element.meanings)
|
||||
}).then(res=>{
|
||||
if(res==1){console.log("added data for "+element.word)
|
||||
} else {console.error("failed to import for "+element.word+". Perhaps it doesn't exist.")}
|
||||
})
|
||||
|
||||
}
|
||||
db.destroy()
|
Loading…
Reference in New Issue