Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): refactor Go SDK to be more intuitive #604

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func compile(c *cli.Context) error {
}

return t(c, func() error {
bytes, err := core.CompileDictionary(inputFile, outputFile)
bytes, err := core.CompilePath(inputFile, outputFile)

if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ github.com/google/flatbuffers v23.5.26+incompatible h1:M9dgRyhJemaM4Sw8+66GHBu8i
github.com/google/flatbuffers v23.5.26+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
Expand Down
4 changes: 2 additions & 2 deletions cli/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func lookup(c *cli.Context) error {

entries := core.Lookup(request)

representables := types.NestedEntriesToRepresentables(entries)
ss := types.NestedEntriesStructs(entries)

PrintEntries(representables, format, true)
PrintEntries(ss, format, true)

return nil
})
Expand Down
2 changes: 1 addition & 1 deletion cli/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func merge(c *cli.Context) error {
return err
}

core.WriteDictionaryToDisk(outputFile, result)
core.WriteDictionary(result, outputFile)

return nil
})
Expand Down
16 changes: 8 additions & 8 deletions cli/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func printDivider() {
fmt.Println(strings.Repeat("─", 32))
}

func printNote(note types.NoteRepresentable, targetWord string, numbering string, indent int) {
func printNote(note types.Note, targetWord string, numbering string, indent int) {
fmtNumbering := "%" + fmt.Sprint(indent) + "s."

fmt.Printf(fmtNumbering+" %s\n", numbering, note.Value)
Expand All @@ -69,7 +69,7 @@ func printNote(note types.NoteRepresentable, targetWord string, numbering string
fmt.Println()
}

func printDefinition(definition types.DefinitionRepresentable, numbering string, entry types.EntryRepresentable, indent int) {
func printDefinition(definition types.Definition, numbering string, entry types.Entry, indent int) {
value := definition.Value
matches := parentheticalRegex.FindAllStringIndex(string(value), -1)
fmtNumbering := "%" + fmt.Sprint(indent) + "s."
Expand Down Expand Up @@ -106,15 +106,15 @@ func printDefinition(definition types.DefinitionRepresentable, numbering string,
}
}

func printGroup(group types.GroupRepresentable, i int, entry types.EntryRepresentable) {
func printGroup(group types.Group, i int, entry types.Entry) {
fmt.Printf("%4d. %s\n", i+1, group.Description)

for j, definition := range group.Definitions {
printDefinition(definition, string(rune('a'+j)), entry, 7)
}
}

func printSense(sense types.SenseRepresentable, entry types.EntryRepresentable) {
func printSense(sense types.Sense, entry types.Entry) {
fmt.Printf("\n%s\n\n", fmtPartOfSpeech(sense.POS.Label))

var i = 0
Expand All @@ -130,7 +130,7 @@ func printSense(sense types.SenseRepresentable, entry types.EntryRepresentable)
}
}

func printEty(ety types.EtymologyRepresentable, i int, showTitle bool, entry types.EntryRepresentable) {
func printEty(ety types.Etymology, i int, showTitle bool, entry types.Entry) {
if showTitle {
fmt.Printf("%s\n\n", fmtEtymology("Etymology #%d", i+1))
}
Expand All @@ -146,7 +146,7 @@ func printEty(ety types.EtymologyRepresentable, i int, showTitle bool, entry typ
fmt.Println()
}

func printEntry(entry types.EntryRepresentable) {
func printEntry(entry types.Entry) {
printDivider()

fmt.Println(fmtEntry(entry.Term))
Expand All @@ -163,7 +163,7 @@ func printEntry(entry types.EntryRepresentable) {

}

func prettyPrint(entries [][]types.EntryRepresentable) error {
func prettyPrint(entries [][]types.Entry) error {
fmt.Println()

hasEntries := false
Expand All @@ -182,7 +182,7 @@ func prettyPrint(entries [][]types.EntryRepresentable) error {
return nil
}

func PrintEntries(entries [][]types.EntryRepresentable, format PrintFormat, indent bool) error {
func PrintEntries(entries [][]types.Entry, format PrintFormat, indent bool) error {
switch {
case format == "json":
json, err := utils.SerializeToJSON(entries, indent)
Expand Down
8 changes: 4 additions & 4 deletions cli/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type SearchRequest struct {
Dictionary *types.Dictionary
Dictionary *types.DictionaryBuffer
Force bool
Exact bool
Query string
Expand Down Expand Up @@ -62,11 +62,11 @@ func search(c *cli.Context) error {
return err
}

representable := lo.Map(results, func(entry types.Entry, _ int) types.EntryRepresentable {
return entry.AsRepresentable()
s := lo.Map(results, func(entry types.EntryBuffer, _ int) types.Entry {
return entry.Struct()
})

json, err := utils.SerializeToJSON(representable, request.PrettyPrint)
json, err := utils.SerializeToJSON(s, request.PrettyPrint)

if err != nil {
return err
Expand Down
20 changes: 10 additions & 10 deletions cli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func service(c *cli.Context) error {
dictPath := c.Args().Get(0)

go func() {
var dict *types.Dictionary
var dict *types.DictionaryBuffer

if len(dictPath) > 0 {
var err error
Expand All @@ -57,7 +57,7 @@ func service(c *cli.Context) error {
ipc.Reply(reply, nil, err)
} else {
payload := GetRootAsWritePayload(buf, 0)
core.WriteDictionaryFromXML(string(payload.Xml()), string(payload.Out()))
core.WriteXML(string(payload.Xml()), string(payload.Out()))
ipc.Reply(reply, true, nil)
}
})
Expand All @@ -79,9 +79,9 @@ func service(c *cli.Context) error {
Threshold: threshold,
})

representable := types.EntriesToRepresentables(entries)
s := types.EntriesStructs(entries)

ipc.Reply(reply, representable, nil)
ipc.Reply(reply, s, nil)
}
})

Expand All @@ -104,11 +104,11 @@ func service(c *cli.Context) error {
return
}

representable := lo.Map(results, func(entry types.Entry, _ int) types.EntryRepresentable {
return entry.AsRepresentable()
s := lo.Map(results, func(entry types.EntryBuffer, _ int) types.Entry {
return entry.Struct()
})

ipc.Reply(reply, representable, nil)
ipc.Reply(reply, s, nil)
}
})

Expand Down Expand Up @@ -153,9 +153,9 @@ func service(c *cli.Context) error {
Split: split,
})

representable := types.NestedEntriesToRepresentables(entries)
s := types.NestedEntriesStructs(entries)

ipc.Reply(reply, representable, nil)
ipc.Reply(reply, s, nil)
} else if err != nil {
ipc.Reply(reply, nil, err)
} else {
Expand All @@ -169,7 +169,7 @@ func service(c *cli.Context) error {
ipc.Reply(reply, nil, err)
} else {
payload := GetRootAsCompilePayload(buf, 0)
core.CompileDictionary(string(payload.Path()), string(payload.Out()))
core.CompilePath(string(payload.Path()), string(payload.Out()))
ipc.Reply(reply, true, nil)
}
})
Expand Down
4 changes: 2 additions & 2 deletions cli/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func split(c *cli.Context) error {

entries := core.Split(request)

representable := types.EntriesToRepresentables(entries)
s := types.EntriesStructs(entries)

fmt.Print(utils.SerializeToJSON(representable, true))
fmt.Print(utils.SerializeToJSON(s, true))

return nil
})
Expand Down
30 changes: 15 additions & 15 deletions flatbuffers/schema.fbs
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
include "enums.fbs";

table Note {
table NoteBuffer {
id:string;
value:string;
examples:[string];
}

table Definition {
table DefinitionBuffer {
id:string;
value:string;
examples:[string];
notes:[Note];
notes:[NoteBuffer];
}

table Etymology {
table EtymologyBuffer {
id:string;
pronunciation:string;
description:string;
senses:[Sense];
senses:[SenseBuffer];
}

table Group {
table GroupBuffer {
id:string;
description:string;
definitions:[Definition];
definitions:[DefinitionBuffer];
}

table Sense {
table SenseBuffer {
pos:POS (key);
definitions:[Definition];
groups:[Group];
definitions:[DefinitionBuffer];
groups:[GroupBuffer];
}

table Entry {
table EntryBuffer {
key:string (key);
term:string;
see:string;
etymologies:[Etymology];
etymologies:[EtymologyBuffer];
}

table Dictionary {
table DictionaryBuffer {
id:string;
name:string;
entries:[Entry];
entries:[EntryBuffer];
}

root_type Dictionary;
root_type DictionaryBuffer;
118 changes: 118 additions & 0 deletions js/src/__generated__/posbuffer.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading