remove forms of script

This commit is contained in:
Andrzej Stepien 2023-08-04 20:51:42 +02:00
parent 253a44da21
commit bb53ec041e
2 changed files with 27 additions and 18 deletions

Binary file not shown.

View File

@ -2,6 +2,19 @@ import { db, getWords } from './db.mjs'
import fs from 'fs' import fs from 'fs'
//const words = getWords(db) //const words = getWords(db)
const allDefinitionsAreFormOf = (meanings) => {
let formsOf = 0
let totalDefs = 0
for (const meaning of meanings) {
for (const definition of meaning.definitions) {
totalDefs++
if (definition.form_of == true) {
formsOf++
}
}
}
return formsOf === totalDefs
}
const sampleMeanings =[ const sampleMeanings =[
{ {
"type": "noun", "type": "noun",
@ -29,24 +42,20 @@ const sampleMeanings =[
] ]
} }
] ]
const words = await getWords(db)
const deleted = []
for (const word of words) {
const res =
await db('dictionary')
const allDefinitionsArePluralOrFormOf = (meanings) => { .select('meanings')
let formsOf = 0 .where('word', word.word)
let totalDefs = 0 const meanings = JSON.parse(res[0].meanings)
for (const obj of meanings) { if(allDefinitionsAreFormOf(meanings)){
for (const definition of obj.definitions) { deleted.push(word)
totalDefs++
console.dir(definition)
if (definition.form_of == true) {
formsOf++
} }
} }
} console.log(`${deleted.length} entries deleted`)
return `Total defs: ${totalDefs}, formsOf: ${formsOf}, output: ${formsOf === totalDefs}` console.dir(deleted)
} db.destroy()
console.log(allDefinitionsArePluralOrFormOf(sampleMeanings))