diff --git a/go.mod b/go.mod index e6b42a5..78a6a80 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/ray1729/dict-web-simple go 1.22.2 require golang.org/x/net v0.24.0 + +require github.com/gertd/go-pluralize v0.2.1 diff --git a/go.sum b/go.sum index 4a8ba20..79ecc45 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ +github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA= +github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= diff --git a/main.go b/main.go index d5fbaa7..9875a78 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "strings" "golang.org/x/net/dict" + pluralize "github.com/gertd/go-pluralize" ) func main() { @@ -73,6 +74,13 @@ func renderTemplate(w http.ResponseWriter, t *template.Template, params TmplPara } } +var pl *pluralize.Client + +func init() { + pl = pluralize.NewClient() + pl.AddSingularRule("(rect)a", "$1um") +} + func getDefinitions(serverAddr string, word string) ([]*dict.Defn, error) { cli, err := dict.Dial("tcp", serverAddr) if err != nil { @@ -82,6 +90,10 @@ func getDefinitions(serverAddr string, word string) ([]*dict.Defn, error) { defs, err := cli.Define("*", word) if err != nil { if strings.Contains(err.Error(), "552 no match") { + word_singular := pl.Singular(word) + if word_singular != word { + return getDefinitions(serverAddr, word_singular) + } return nil, nil } return nil, fmt.Errorf("error from dict server: %v", err)