Skip to content

Commit b600074

Browse files
committed
WIP
1 parent a295b44 commit b600074

File tree

26 files changed

+2204
-23
lines changed

26 files changed

+2204
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*.so
66
*.dylib
77

8+
bin
9+
810
# Test binary, built with `go test -c`
911
*.test
1012

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/library.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

Lines changed: 674 additions & 21 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# library
2-
A unified (and indexed) library of Vale-related resources.
1+
# lois
2+
3+
LOIS (or Line-Oriented Information System) provides an advanced, structured understanding of free-form notes and other unstructured documents.
4+
5+
```
6+
go build -ldflags="-s -w" -o bin/engine cmd/engine/main.go
7+
```

cmd/engine/main.go

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
"log"
8+
"os"
9+
10+
"github.com/errata-ai/library/internal/nlp"
11+
"github.com/errata-ai/library/pkg/data"
12+
"github.com/errata-ai/library/pkg/search"
13+
"github.com/go-resty/resty/v2"
14+
"github.com/urfave/cli/v2"
15+
)
16+
17+
func printJSON(t interface{}) error {
18+
b, err := json.MarshalIndent(t, "", " ")
19+
if err != nil {
20+
fmt.Println("{}")
21+
return err
22+
}
23+
fmt.Println(string(b))
24+
return nil
25+
}
26+
27+
func main() {
28+
app := &cli.App{
29+
Name: "lois",
30+
Usage: "A local, offline search engine",
31+
Commands: []*cli.Command{
32+
{
33+
Name: "read",
34+
Action: func(c *cli.Context) error {
35+
args := c.Args().Slice()
36+
if len(args) != 2 {
37+
return errors.New("2 argument required")
38+
}
39+
40+
src, err := data.FromLinkList(args[0])
41+
if err != nil {
42+
return err
43+
}
44+
45+
_, err = search.NewEngineFromData(args[1], src)
46+
if err != nil {
47+
return err
48+
}
49+
50+
return nil
51+
},
52+
},
53+
{
54+
Name: "create",
55+
Action: func(c *cli.Context) error {
56+
args := c.Args().Slice()
57+
if len(args) != 2 {
58+
return errors.New("2 argument required")
59+
}
60+
61+
src, err := data.FromMapping(args[0])
62+
if err != nil {
63+
return err
64+
}
65+
66+
_, err = search.NewEngineFromData(args[1], src)
67+
if err != nil {
68+
return err
69+
}
70+
71+
return nil
72+
},
73+
},
74+
{
75+
Name: "search",
76+
Action: func(c *cli.Context) error {
77+
args := c.Args().Slice()
78+
if len(args) != 2 {
79+
return errors.New("2 arguments required")
80+
}
81+
82+
engine, err := search.LoadEngine(args[0])
83+
if err != nil {
84+
return err
85+
}
86+
87+
results, err := engine.Search(args[1])
88+
if err != nil {
89+
return err
90+
}
91+
92+
return printJSON(results)
93+
},
94+
},
95+
{
96+
Name: "lookup",
97+
Usage: "Finds the context for a given result ID",
98+
Action: func(c *cli.Context) error {
99+
args := c.Args().Slice()
100+
if len(args) != 2 {
101+
return errors.New("2 arguments required")
102+
}
103+
104+
m, err := data.ParseMap(args[1])
105+
if err != nil {
106+
return err
107+
}
108+
109+
context, err := data.Context(args[0], m.Path)
110+
if err != nil {
111+
return err
112+
}
113+
fmt.Println(context)
114+
115+
return nil
116+
},
117+
},
118+
{
119+
Name: "parse",
120+
Usage: "",
121+
Action: func(c *cli.Context) error {
122+
args := c.Args().Slice()
123+
if len(args) != 2 {
124+
return errors.New("2 arguments required")
125+
}
126+
127+
m, err := data.ParseMap(args[1])
128+
if err != nil {
129+
return err
130+
}
131+
132+
context, err := data.Context(args[0], m.Path)
133+
if err != nil {
134+
return err
135+
}
136+
137+
tokens, err := nlp.TextToTokens(context)
138+
if err != nil {
139+
return err
140+
}
141+
142+
return printJSON(tokens)
143+
},
144+
},
145+
{
146+
Name: "post",
147+
Usage: "",
148+
Action: func(c *cli.Context) error {
149+
args := c.Args().Slice()
150+
if len(args) != 2 {
151+
return errors.New("2 arguments required")
152+
}
153+
client := resty.New()
154+
155+
resp, err := client.R().
156+
SetHeader("Content-Type", "application/x-www-form-urlencoded").
157+
SetQueryParam("text", args[1]).
158+
Post(args[0])
159+
160+
if err != nil {
161+
return err
162+
}
163+
fmt.Println(resp)
164+
165+
return nil
166+
},
167+
},
168+
{
169+
Name: "fsm",
170+
Usage: "",
171+
Action: func(c *cli.Context) error {
172+
args := c.Args().Slice()
173+
if len(args) != 2 {
174+
return errors.New("2 arguments required")
175+
}
176+
177+
out, err := nlp.DoSectionize(args[0], args[1])
178+
if err != nil {
179+
return err
180+
}
181+
182+
return printJSON(out)
183+
},
184+
},
185+
},
186+
}
187+
188+
err := app.Run(os.Args)
189+
if err != nil {
190+
log.Fatal(err)
191+
}
192+
}

go.mod

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module github.com/errata-ai/library
2+
3+
go 1.17
4+
5+
require (
6+
github.com/GolangNLP/split v0.1.0
7+
github.com/advancedlogic/GoOse v0.0.0-20210820140952-9d5822d4a625
8+
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
9+
github.com/blevesearch/bleve/v2 v2.1.0
10+
github.com/go-resty/resty/v2 v2.6.0
11+
github.com/sirikothe/gotextfsm v1.0.0
12+
github.com/urfave/cli/v2 v2.3.0
13+
gopkg.in/yaml.v2 v2.4.0
14+
)
15+
16+
require (
17+
github.com/PuerkitoBio/goquery v1.4.1 // indirect
18+
github.com/RoaringBitmap/roaring v0.7.3 // indirect
19+
github.com/andybalholm/cascadia v1.0.0 // indirect
20+
github.com/bits-and-blooms/bitset v1.2.0 // indirect
21+
github.com/blevesearch/bleve_index_api v1.0.1 // indirect
22+
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
23+
github.com/blevesearch/mmap-go v1.0.2 // indirect
24+
github.com/blevesearch/scorch_segment_api/v2 v2.0.1 // indirect
25+
github.com/blevesearch/segment v0.9.0 // indirect
26+
github.com/blevesearch/snowballstem v0.9.0 // indirect
27+
github.com/blevesearch/upsidedown_store_api v1.0.1 // indirect
28+
github.com/blevesearch/vellum v1.0.5 // indirect
29+
github.com/blevesearch/zapx/v11 v11.2.2 // indirect
30+
github.com/blevesearch/zapx/v12 v12.2.2 // indirect
31+
github.com/blevesearch/zapx/v13 v13.2.2 // indirect
32+
github.com/blevesearch/zapx/v14 v14.2.2 // indirect
33+
github.com/blevesearch/zapx/v15 v15.2.2 // indirect
34+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
35+
github.com/fatih/set v0.2.1 // indirect
36+
github.com/gigawattio/window v0.0.0-20180317192513-0f5467e35573 // indirect
37+
github.com/golang/protobuf v1.3.2 // indirect
38+
github.com/golang/snappy v0.0.1 // indirect
39+
github.com/jaytaylor/html2text v0.0.0-20180606194806-57d518f124b0 // indirect
40+
github.com/kr/text v0.2.0 // indirect
41+
github.com/mattn/go-runewidth v0.0.13 // indirect
42+
github.com/mschoch/smat v0.2.0 // indirect
43+
github.com/neurosnap/sentences v1.0.6 // indirect
44+
github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84 // indirect
45+
github.com/pkg/errors v0.8.1 // indirect
46+
github.com/rivo/uniseg v0.2.0 // indirect
47+
github.com/russross/blackfriday/v2 v2.0.1 // indirect
48+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
49+
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
50+
github.com/steveyen/gtreap v0.1.0 // indirect
51+
go.etcd.io/bbolt v1.3.5 // indirect
52+
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
53+
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
54+
golang.org/x/text v0.3.7 // indirect
55+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
56+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
57+
)

0 commit comments

Comments
 (0)