factored out getAcceptablePrompts

This commit is contained in:
Andrzej Stepien 2023-08-12 00:18:09 +02:00
parent ee2415f454
commit f7d5842010
2 changed files with 28 additions and 25 deletions

View File

@ -0,0 +1,24 @@
import logger from "./logger.mjs"
import { db } from "./db.mjs"
const blocklist = db.union([
db('bad_words').select('word'),
db('medical_dictionary').select('word'),
db('published').select('word')
])
export default async () => {
return db('dictionary')
.select('*')
.where({
derivative: 0,
scientific: 0,
})
.andWhere('count', '<', maxCount)
.andWhere('count', '>', minCount)
.andWhere('word', 'not in', blocklist)
.whereRaw('length(word) > 3')
.whereNotNull('pronunciation')
.orderByRaw('count desc')
.catch(error=>{throw error})
}

View File

@ -1,30 +1,13 @@
import { db } from "./db.mjs"
import logger from "./logger.mjs"
import getAcceptablePrompts from "./getAcceptablePrompts.mjs"
const blocklist = db.union([
db('bad_words').select('word'),
db('medical_dictionary').select('word'),
db('published').select('word')
])
export default async function getNewPrompt({ minCount = 200000, maxCount = 30000000, rarityBias = 0.5 }) {
const childLogger = logger.child({minCount,maxCount,rarityBias})
childLogger.trace("getNewPrompt called")
const prompts = await db('dictionary')
.select('*')
.where({
derivative: 0,
scientific: 0,
})
.andWhere('count', '<', maxCount)
.andWhere('count', '>', minCount)
.andWhere('word', 'not in', blocklist)
.whereRaw('length(word) > 3')
.whereNotNull('pronunciation')
.orderByRaw('count desc')
.catch(error=>{throw error})
const getBiasedRng = (min, max, bias, influence) => {
const random = Math.random() * (max - min) + min
const mix = Math.random() * influence
@ -41,15 +24,11 @@ export default async function getNewPrompt({ minCount = 200000, maxCount = 30000
]
}
//await db.destroy()
return await randomEntry(prompts)
return randomEntry(await getAcceptablePrompts())
}
//console.dir(await getNewPrompt({}))
//console.log(await blocklist)