Fix Portuguese coverage gaps: synonyms, translations, frequency, gerunds

- Extract sense-level synonyms/antonyms from Wiktionary (not just top-level),
  dramatically improving Portuguese synonym coverage
- Add bidirectional translation lookup so pt→en queries find en→pt entries
  stored by English Wiktionary loader, with reverse index for performance
- Fix frequency loader: auto-detect column order (count\tword vs word\tcount),
  auto-detect ISO-8859-1 encoding and convert to UTF-8, insert missing words
  instead of only updating existing ones
- Switch WordNet download from 3.1 to 3.0 to match WOLF/OMW synset offsets
- Add OpenSubtitles-derived Portuguese frequency list (hermitdave/FrequencyWords)
- Increase affix expansion cap from 30→80 forms per word for Portuguese gerunds

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
prosolis
2026-04-03 08:48:22 -07:00
parent 25ed087c3e
commit 2cc1832439
6 changed files with 157 additions and 48 deletions

View File

@@ -128,12 +128,25 @@ func (d *Dictionary) Synonyms(word, lang string) ([]string, error) {
}
func (d *Dictionary) Translate(word, fromLang, toLang string) ([]string, error) {
// Forward: find translations stored for this word in fromLang → toLang
// Reverse: find words in toLang that have this word as a translation to fromLang
// This makes translations bidirectional: if English kaikki has "house" → "casa" (pt-PT),
// querying "casa" from pt-PT to en will find "house" via the reverse lookup.
rows, err := d.db.Query(`
SELECT DISTINCT t.translation
FROM translations t
JOIN words w ON w.id = t.word_id
WHERE w.word = ? AND w.lang = ? AND t.target_lang = ?
ORDER BY t.translation`,
SELECT DISTINCT result FROM (
SELECT t.translation AS result
FROM translations t
JOIN words w ON w.id = t.word_id
WHERE w.word = ? AND w.lang = ? AND t.target_lang = ?
UNION
SELECT w.word AS result
FROM translations t
JOIN words w ON w.id = t.word_id
WHERE t.translation = ? AND t.target_lang = ? AND w.lang = ?
) ORDER BY result`,
// Forward: word=word, lang=fromLang, target_lang=toLang
strings.ToLower(word), fromLang, toLang,
// Reverse: translation=word, target_lang=fromLang (stored target matches our source), lang=toLang
strings.ToLower(word), fromLang, toLang,
)
if err != nil {