2023-08-04 17:59:02 +00:00
|
|
|
import { db, getWords } from './db.mjs'
|
|
|
|
|
|
|
|
//const words = getWords(db)
|
2023-08-04 18:51:42 +00:00
|
|
|
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
|
|
|
|
}
|
2023-08-04 17:59:02 +00:00
|
|
|
const sampleMeanings =[
|
|
|
|
{
|
|
|
|
"type": "noun",
|
|
|
|
"definitions": [
|
|
|
|
{
|
|
|
|
"definition": "plural of look",
|
|
|
|
"form_of": true,
|
|
|
|
"plural": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"definition": "One's appearance or attractiveness.",
|
|
|
|
"form_of": false,
|
|
|
|
"plural": true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "verb",
|
|
|
|
"definitions": [
|
|
|
|
{
|
|
|
|
"definition": "third-person singular simple present indicative form of look",
|
|
|
|
"form_of": true,
|
|
|
|
"plural": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2023-08-04 18:51:42 +00:00
|
|
|
const words = await getWords(db)
|
2023-08-05 20:11:43 +00:00
|
|
|
const flagged = []
|
2023-08-04 18:51:42 +00:00
|
|
|
for (const word of words) {
|
|
|
|
const res =
|
|
|
|
await db('dictionary')
|
|
|
|
.select('meanings')
|
|
|
|
.where('word', word.word)
|
|
|
|
const meanings = JSON.parse(res[0].meanings)
|
|
|
|
if(allDefinitionsAreFormOf(meanings)){
|
2023-08-05 20:11:43 +00:00
|
|
|
await db('dictionary').
|
|
|
|
where('word', word.word)
|
|
|
|
.update('derivative',1)
|
|
|
|
flagged.push(word)
|
2023-08-04 17:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-05 20:11:43 +00:00
|
|
|
console.log(`${flagged.length} entries flagged`)
|
|
|
|
//console.dir(flagged)
|
2023-08-04 18:51:42 +00:00
|
|
|
db.destroy()
|
|
|
|
|
2023-08-04 17:59:02 +00:00
|
|
|
|