Add word frequency endpoint and SCOWL frequency data

SCOWL loader now sets frequency based on tier (10=1000 most common,
70=50 rare). New GET /frequency?word=X&lang=Y endpoint returns frequency
score for a word. Enables downstream consumers to identify rare/
sophisticated vocabulary from dictionary data rather than LLM guessing.

Also fix .gitignore matching cmd/server/ directory instead of just the
server binary.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
prosolis
2026-03-30 21:27:45 -07:00
parent 5b1eea67f2
commit eb471b6f6d
4 changed files with 417 additions and 11 deletions

View File

@@ -157,6 +157,24 @@ func (d *Dictionary) WordCount() (map[string]int, error) {
return counts, rows.Err()
}
// Frequency returns the frequency score for a word in a language.
// Returns 0 if the word is not found or has no frequency data.
// Higher values indicate more common words.
func (d *Dictionary) Frequency(word, lang string) (int, error) {
var freq int
err := d.db.QueryRow(
"SELECT COALESCE(frequency, 0) FROM words WHERE word = ? AND lang = ?",
strings.ToLower(word), lang,
).Scan(&freq)
if err == sql.ErrNoRows {
return 0, nil
}
if err != nil {
return 0, fmt.Errorf("dictionary: frequency: %w", err)
}
return freq, nil
}
func (d *Dictionary) Meta(key string) (string, error) {
var val string
err := d.db.QueryRow("SELECT value FROM meta WHERE key = ?", key).Scan(&val)