Skip to content

Commit 293517d

Browse files
committed
chore: init CI and fix lint issues
1 parent 5860846 commit 293517d

File tree

9 files changed

+79
-55
lines changed

9 files changed

+79
-55
lines changed

.github/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# .github/release.yml
2+
3+
changelog:
4+
exclude:
5+
authors:
6+
- octocat
7+
categories:
8+
- title: ⭐ New features
9+
labels:
10+
- feature
11+
- enhancement
12+
- title: 🛠 Fixes
13+
labels:
14+
- bug
15+
- title: ⚙️ Dependency updates
16+
labels:
17+
- dependencies
18+
- title: 🧰 Other changes
19+
labels:
20+
- "*"

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
branches: [ main ]
5+
types: [opened, synchronize, reopened]
6+
push:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
go-version: [^1.23]
18+
steps:
19+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
20+
with:
21+
fetch-depth: 1
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
25+
with:
26+
go-version: ${{ matrix.go-version }}
27+
cache: true
28+
29+
- name: Run golangci-lint
30+
uses: golangci/golangci-lint
31+
32+
- name: Run Go Tests
33+
run: go test -coverprofile=coverage.out ./...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage.out

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ seconds on a modest laptop.
3030
import (
3131
"log"
3232

33-
"github.com/lloyd/wnram"
33+
"github.com/coreruleset/wnram"
3434
)
3535

3636
func main() {

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/coreruleset/wnram
2+
3+
go 1.23.0

parser.go

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,6 @@ import (
88
"unicode/utf8"
99
)
1010

11-
type tokenType uint8
12-
13-
const (
14-
tNone tokenType = iota
15-
tEOL
16-
tNumber
17-
tPOS
18-
)
19-
20-
func (t tokenType) GoString() string {
21-
return t.String()
22-
}
23-
24-
func (t tokenType) String() string {
25-
switch t {
26-
case tNone:
27-
return "none"
28-
case tEOL:
29-
return "eol"
30-
case tNumber:
31-
return "number"
32-
case tPOS:
33-
return "pos"
34-
}
35-
return "unknown"
36-
}
37-
38-
type token struct {
39-
t tokenType
40-
v string
41-
n int64
42-
p PartOfSpeech
43-
}
44-
4511
type lexable string
4612

4713
func (l *lexable) chomp() {
@@ -97,7 +63,7 @@ func (l *lexable) lexDecimalNumber() (int64, error) {
9763
func (l *lexable) lexWord() (string, error) {
9864
l.chomp()
9965
var word []byte
100-
buf := make([]byte, 4, 4)
66+
buf := make([]byte, 4)
10167
for {
10268
if r, ok := l.peek(); !ok || unicode.IsSpace(r) {
10369
break
@@ -155,7 +121,7 @@ func (l *lexable) lexOffset() (string, error) {
155121
return "", fmt.Errorf("invalid chars in offset: %s", string((*l)[0:8]))
156122
}
157123
}
158-
cpy := make([]byte, 8, 8)
124+
cpy := make([]byte, 8)
159125
copy(cpy, (*l)[0:8])
160126
*l = (*l)[8:]
161127
return string(cpy), nil
@@ -267,7 +233,7 @@ type parsed struct {
267233
rels []parsedRel
268234
}
269235

270-
func parseLine(data []byte, line, offset int64) (*parsed, error) {
236+
func parseLine(data []byte, line int64) (*parsed, error) {
271237
l := lexable(data)
272238

273239
l.chomp()
@@ -303,12 +269,12 @@ func parseLine(data []byte, line, offset int64) (*parsed, error) {
303269
for ; wordcount > 0; wordcount-- {
304270
value, err := l.lexWord()
305271
if err != nil {
306-
return nil, fmt.Errorf("word expected: %s")
272+
return nil, fmt.Errorf("word expected: %s", err)
307273
}
308274
// XXX: handle syntactic markers
309275
sense, err := l.lexHexNumber()
310276
if err != nil {
311-
return nil, fmt.Errorf("sense id expected: %s")
277+
return nil, fmt.Errorf("sense id expected: %s", err)
312278
}
313279
p.words = append(p.words, word{
314280
word: value,

read.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wnram
22

33
import (
44
"bufio"
5+
"fmt"
56
"io"
67
"os"
78
)
@@ -27,7 +28,6 @@ func inPlaceReadLine(s io.Reader, cb func([]byte, int64, int64) error) error {
2728
}
2829
// If we reached end of file and the line contents are empty, don't return an additional line.
2930
if err == io.EOF {
30-
err = nil
3131
if len(line) > 0 {
3232
return cb(line, count, offset)
3333
}
@@ -42,6 +42,10 @@ func inPlaceReadLineFromPath(filePath string, cb func([]byte, int64, int64) erro
4242
if err != nil {
4343
return err
4444
}
45-
defer f.Close()
45+
defer func() {
46+
if cerr := f.Close(); cerr != nil {
47+
fmt.Println("Error closing file:", cerr)
48+
}
49+
}()
4650
return inPlaceReadLine(f, cb)
4751
}

wordnet.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ type Handle struct {
1616
db []*cluster
1717
}
1818

19-
type index struct {
20-
pos PartOfSpeech
21-
lemma string
22-
sense uint8
23-
}
24-
2519
// The results of a search against the wordnet database
2620
type Lookup struct {
2721
word string // the word the user searched for
@@ -158,7 +152,7 @@ func (w *Lookup) Gloss() string {
158152

159153
func (w *Lookup) DumpStr() string {
160154
s := fmt.Sprintf("Word: %s\n", w.String())
161-
s += fmt.Sprintf("Synonyms: ")
155+
s += "Synonyms: "
162156
words := []string{}
163157
for _, w := range w.cluster.words {
164158
words = append(words, w.word)
@@ -240,8 +234,8 @@ func New(dir string) (*Handle, error) {
240234

241235
err = inPlaceReadLineFromPath(filename, func(data []byte, line, offset int64) error {
242236
cnt++
243-
if p, err := parseLine(data, line, offset); err != nil {
244-
return fmt.Errorf("%s:%d: %s", err)
237+
if p, err := parseLine(data, line); err != nil {
238+
return fmt.Errorf("%s", err)
245239
} else if p != nil {
246240
// first, let's identify the cluster
247241
index := ix{p.byteOffset, p.pos}
@@ -299,15 +293,15 @@ func New(dir string) (*Handle, error) {
299293
}
300294
for _, c := range byOffset {
301295
if len(c.words) == 0 {
302-
return nil, fmt.Errorf("ERROR, internal consistency error -> cluster without words %v\n", c)
296+
return nil, fmt.Errorf("ERROR, internal consistency error -> cluster without words %v", c)
303297
}
304298
// add to the global slice of synsets (supports iteration)
305299
h.db = append(h.db, c)
306300

307301
// now index all the strings
308302
for _, w := range c.words {
309303
key := normalize(w.word)
310-
v, _ := h.index[key]
304+
v := h.index[key]
311305
v = append(v, c)
312306
h.index[key] = v
313307
}
@@ -331,7 +325,7 @@ func (h *Handle) Lookup(crit Criteria) ([]Lookup, error) {
331325
return nil, fmt.Errorf("empty string passed as criteria to lookup")
332326
}
333327
searchStr := normalize(crit.Matching)
334-
clusters, _ := h.index[searchStr]
328+
clusters := h.index[searchStr]
335329
found := []Lookup{}
336330
for _, c := range clusters {
337331
if len(crit.POS) > 0 {

wordnet_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ func TestHyponyms(t *testing.T) {
154154

155155
func TestIterate(t *testing.T) {
156156
count := 0
157-
wnInstance.Iterate(PartOfSpeechList{Noun}, func(l Lookup) error {
157+
err := wnInstance.Iterate(PartOfSpeechList{Noun}, func(l Lookup) error {
158158
count++
159159
return nil
160160
})
161+
if err != nil {
162+
t.Fatalf("Iterate failed: %v", err)
163+
}
161164
if count != 82192 {
162165
t.Errorf("Missing nouns!")
163166
}

0 commit comments

Comments
 (0)