-
diff --git a/shiritori/main.go b/cmd/shiritori/main.go similarity index 75% rename from shiritori/main.go rename to cmd/shiritori/main.go index 1a2266b..7e71134 100644 --- a/shiritori/main.go +++ b/cmd/shiritori/main.go @@ -4,8 +4,8 @@ import ( "log" "net/http" - "git.elnu.com/ElnuDev/jichanorg/shiritori/api" - . "git.elnu.com/ElnuDev/jichanorg/shiritori/clients" + . "git.elnu.com/ElnuDev/shiritori-go/shiritori" + "git.elnu.com/ElnuDev/shiritori-go/shiritori/api" ) func main() { diff --git a/shiritori/static/index.html b/cmd/shiritori/static/index.html similarity index 100% rename from shiritori/static/index.html rename to cmd/shiritori/static/index.html diff --git a/shiritori/static/style.css b/cmd/shiritori/static/style.css similarity index 100% rename from shiritori/static/style.css rename to cmd/shiritori/static/style.css diff --git a/dict/.gitignore b/dict/.gitignore deleted file mode 100644 index 30e4d8d..0000000 --- a/dict/.gitignore +++ /dev/null @@ -1 +0,0 @@ -JMdict.xml \ No newline at end of file diff --git a/dict/README.md b/dict/README.md deleted file mode 100644 index bb0c063..0000000 --- a/dict/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# jichanorg/dict - -**jichanorg/dict** is a [hypermedia](https://hypermedia.systems/) and JSON API for parsing the JMDict Japanese dictionary project. - -Its primary goals are: - -- be a self-hostable dictionary solution to replace existing proprietary ([Jisho.org](https://jisho.org/)) and partially proprietary ([Jotoba](https://jotoba.de/)) dictionaries. -- Provide a hypermedia API for integration into other applications, such as [jichanorg/shiritori](../shiritori). - -### Configuration - -1. [Download the latest version of JMdict](https://www.edrdg.org/wiki/index.php/JMdict-EDICT_Dictionary_Project#CURRENT_VERSION_&_DOWNLOAD). For development, download the file with only English glosses, which will substantially decrease parsing time. -2. Extract the archive -3. Rename the file to JMDict.xml \ No newline at end of file diff --git a/dict/go.mod b/dict/go.mod deleted file mode 100644 index c0b1214..0000000 --- a/dict/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module git.elnu.com/ElnuDev/jichanorg/dict - -go 1.20 - -require ( - foosoft.net/projects/jmdict v0.0.0-20220714211640-cc9bc30b68a3 // indirect - github.com/gorilla/mux v1.8.0 // indirect -) diff --git a/dict/go.sum b/dict/go.sum deleted file mode 100644 index 7ae614e..0000000 --- a/dict/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -foosoft.net/projects/jmdict v0.0.0-20220714211640-cc9bc30b68a3 h1:zjHGpgUR2WP3pf6NVZM38OKYNse0GjovCW2v23V72PQ= -foosoft.net/projects/jmdict v0.0.0-20220714211640-cc9bc30b68a3/go.mod h1:ZrjLCcE7ZrND28ZOSGYMd78tL+Dffiv2g+NjOMKgnew= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/dict/main.go b/dict/main.go deleted file mode 100644 index 77755a9..0000000 --- a/dict/main.go +++ /dev/null @@ -1,112 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "log" - "net/http" - "os" - - "foosoft.net/projects/jmdict" - "git.elnu.com/ElnuDev/jichanorg/httputils" - "github.com/gorilla/mux" -) - -var dict jmdict.Jmdict - -func LoadDict() error { - const jmdictFile = "JMdict.xml" - reader, err := os.Open(jmdictFile) - if err != nil { - return err - } - dict, _, err = jmdict.LoadJmdict(reader) - if err != nil { - return err - } - return nil -} - -type Entry struct { - Kanji string - Reading string - Definitions []string -} - -func ParseEntry(entry jmdict.JmdictEntry) Entry { - kanji := "" - if len(entry.Kanji) > 0 { - kanji = entry.Kanji[0].Expression - } - reading := "" - if len(entry.Readings) > 0 { - reading = entry.Readings[0].Reading - } - var definitions []string - if len(entry.Sense) > 0 && len(entry.Sense[0].Glossary) > 0 { - definitions = make([]string, len(entry.Sense[0].Glossary)) - for i, glossary := range entry.Sense[0].Glossary { - definitions[i] = glossary.Content - } - } - return Entry{ - Kanji: kanji, - Reading: reading, - Definitions: definitions, - } -} - -func Search(query string) []Entry { - entries := make([]Entry, 0) - for _, jmdictEntry := range dict.Entries { - for _, kanji := range jmdictEntry.Kanji { - if kanji.Expression == query { - goto match - } - } - for _, reading := range jmdictEntry.Readings { - if reading.Reading == query { - goto match - } - } - continue - match: - entry := ParseEntry(jmdictEntry) - entries = append(entries, entry) - } - return entries -} - -func main() { - err := LoadDict() - if err != nil { - fmt.Println(err) - return - } - fmt.Println("JMdict loaded!") - r := mux.NewRouter() - r.HandleFunc("/api/search", httputils.GenerateHandler( - "search.html", - func(w http.ResponseWriter, r *http.Request) bool { - if r.Header.Get("Accept") != "application/json" { - return true - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - r.ParseMultipartForm(0) - query := r.FormValue("q") - entries := Search(query) - jsonBytes, _ := json.Marshal(entries) - fmt.Fprint(w, string(jsonBytes)) - return false - }, - func(w http.ResponseWriter, r *http.Request) any { - r.ParseMultipartForm(0) - query := r.FormValue("q") - entry := Search(query) - return entry - }, - []string{http.MethodGet, http.MethodPost}, - )) - r.Handle("/", http.FileServer(http.Dir("static"))) - log.Fatal(http.ListenAndServe(":3334", r)) -} diff --git a/dict/static/index.html b/dict/static/index.html deleted file mode 100644 index cfebb64..0000000 --- a/dict/static/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - -
- - -{{ $count := (len .) }}{{ if eq $count 0 }}No results{{ else }}{{ $count }} result{{ if ne $count 1}}s{{ end }}{{ end }}.
-{{- range . -}} -{{- index .Definitions 0 -}}
- {{- else -}} -