Publish as versioned Gitea module; move dictionary pipeline out
- Rename module to gitea.iliadenisov.ru/developer/scrabble-solver so it can be consumed as a versioned dependency (no go.work replace / CI clone). - De-internalize wordlist and dictdawg as public packages. - Remove cmd/builddict, dictprep/, the dictionaries submodule and the dawg Makefile: the word-list parsing and DAWG build now live in the separate scrabble-dictionary repository, which publishes the DAWG set as a release artifact. - internal/dict loads the committed dawg/en_sowpods.dawg fixture for cmd/stress. - Update README/CLAUDE docs accordingly.
This commit is contained in:
+13
-43
@@ -1,24 +1,18 @@
|
||||
// Package dict loads the English test dictionary as a DAWG, preferring the serialized
|
||||
// cache under testdata and falling back to building from the dictionaries submodule.
|
||||
// Paths are resolved relative to the repository root so it works both from the repo root
|
||||
// (commands) and from a package directory (tests).
|
||||
// Package dict loads the English test dictionary as a DAWG from the committed
|
||||
// dawg/en_sowpods.dawg fixture, for the cmd/stress benchmark. The dictionary build
|
||||
// pipeline (word-list parsing and DAWG construction from sources) now lives in the
|
||||
// separate scrabble-dictionary repository; this package only loads the committed
|
||||
// artifact. Paths are resolved relative to the repository root so it works both from
|
||||
// the repo root (commands) and from a package directory (tests).
|
||||
package dict
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/iliadenisov/alphabet"
|
||||
dawg "github.com/iliadenisov/dafsa"
|
||||
|
||||
"scrabble-solver/internal/dictdawg"
|
||||
"scrabble-solver/internal/wordlist"
|
||||
)
|
||||
|
||||
// MinLen and MaxLen bound playable word lengths (a 15x15 board holds at most 15).
|
||||
const (
|
||||
MinLen = 2
|
||||
MaxLen = 15
|
||||
"gitea.iliadenisov.ru/developer/scrabble-solver/dictdawg"
|
||||
)
|
||||
|
||||
func exists(p string) bool { _, err := os.Stat(p); return err == nil }
|
||||
@@ -42,35 +36,11 @@ func Root() string {
|
||||
}
|
||||
}
|
||||
|
||||
// DAWGCache and WordlistPath locate the English cache file and source word list,
|
||||
// relative to the repository root.
|
||||
func DAWGCache() string { return filepath.Join(Root(), "testdata", "sowpods.dawg") }
|
||||
func WordlistPath() string { return filepath.Join(Root(), "dictionaries", "english", "sowpods.txt") }
|
||||
// DAWGCache locates the committed English DAWG, relative to the repository root.
|
||||
func DAWGCache() string { return filepath.Join(Root(), "dawg", "en_sowpods.dawg") }
|
||||
|
||||
// EnglishAvailable reports whether the English dictionary can be loaded (cache or source).
|
||||
func EnglishAvailable() bool {
|
||||
return exists(DAWGCache()) || exists(WordlistPath())
|
||||
}
|
||||
// EnglishAvailable reports whether the committed English DAWG is present.
|
||||
func EnglishAvailable() bool { return exists(DAWGCache()) }
|
||||
|
||||
// EnglishWords returns the encoded English word list (from the submodule source).
|
||||
func EnglishWords() ([][]byte, error) {
|
||||
return wordlist.Read(WordlistPath(), alphabet.Latin(), MinLen, MaxLen)
|
||||
}
|
||||
|
||||
// EnglishDAWG returns the English DAWG, loading the cache if present, otherwise building
|
||||
// it from the word list and caching it (best effort).
|
||||
func EnglishDAWG() (dawg.Finder, error) {
|
||||
if exists(DAWGCache()) {
|
||||
return dictdawg.Load(DAWGCache())
|
||||
}
|
||||
words, err := EnglishWords()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := dictdawg.Build(alphabet.Latin(), words)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = dictdawg.Save(f, DAWGCache())
|
||||
return f, nil
|
||||
}
|
||||
// EnglishDAWG loads the committed English DAWG.
|
||||
func EnglishDAWG() (dawg.Finder, error) { return dictdawg.Load(DAWGCache()) }
|
||||
|
||||
Reference in New Issue
Block a user