Skip to content

Commit 13036a7

Browse files
authored
Merge pull request #3 from S0obi/fix/fix-golangci-lint-issue
chore: fix golang-lint issue
2 parents 109f631 + 2ca1e39 commit 13036a7

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

parser.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ func (l *lexable) next() (rune, bool) {
2626
*l = (*l)[width:]
2727
return curchar, true
2828
}
29+
2930
return ' ', false
3031
}
3132
func (l *lexable) peek() (rune, bool) {
3233
if !l.empty() {
3334
c, _ := utf8.DecodeRuneInString(string(*l))
3435
return c, true
3536
}
37+
3638
return ' ', false
3739
}
3840

@@ -50,13 +52,16 @@ func (l *lexable) lexDecimalNumber() (int64, error) {
5052
r, _ := l.next()
5153
number += fmt.Sprintf("%c", r)
5254
}
55+
5356
if len(number) == 0 {
5457
return 0, fmt.Errorf("number not found in string: %s", *l)
5558
}
59+
5660
i, err := strconv.ParseInt(number, 10, 64)
5761
if err != nil {
5862
return 0, err
5963
}
64+
6065
return i, nil
6166
}
6267

@@ -76,6 +81,7 @@ func (l *lexable) lexWord() (string, error) {
7681
word = append(word, buf[0:x]...)
7782
}
7883
}
84+
7985
return string(word), nil
8086
}
8187

@@ -85,9 +91,11 @@ func (l *lexable) lexGloss() (string, error) {
8591
if !ok {
8692
return "", fmt.Errorf("definition expected")
8793
}
94+
8895
if r != '|' {
8996
return "", fmt.Errorf("definition expected (want '|' got '%c') [%q]", r, string(*l))
9097
}
98+
9199
return strings.TrimSpace(string(*l)), nil
92100
}
93101

@@ -101,13 +109,16 @@ func (l *lexable) lexHexNumber() (int64, error) {
101109
r, _ := l.next()
102110
number += fmt.Sprintf("%c", r)
103111
}
112+
104113
if len(number) == 0 {
105114
return 0, fmt.Errorf("number not found in string: %s", *l)
106115
}
116+
107117
i, err := strconv.ParseInt(number, 16, 64)
108118
if err != nil {
109119
return 0, err
110120
}
121+
111122
return i, nil
112123
}
113124

@@ -116,14 +127,17 @@ func (l *lexable) lexOffset() (string, error) {
116127
if len(*l) < 8 {
117128
return "", fmt.Errorf("invalid offset")
118129
}
130+
119131
for i := 0; i < 8; i++ {
120132
if !unicode.IsDigit(rune((*l)[i])) {
121133
return "", fmt.Errorf("invalid chars in offset: %s", string((*l)[0:8]))
122134
}
123135
}
136+
124137
cpy := make([]byte, 8)
125138
copy(cpy, (*l)[0:8])
126139
*l = (*l)[8:]
140+
127141
return string(cpy), nil
128142
}
129143

@@ -133,6 +147,7 @@ func (l *lexable) lexPOS() (PartOfSpeech, error) {
133147
if !ok {
134148
return 0, fmt.Errorf("unexpected end of input")
135149
}
150+
136151
switch curchar {
137152
case 'n':
138153
return Noun, nil
@@ -149,6 +164,7 @@ func (l *lexable) lexPOS() (PartOfSpeech, error) {
149164
case 'r':
150165
return Adverb, nil
151166
}
167+
152168
return 0, fmt.Errorf("invalid part of speech: %c", curchar)
153169
}
154170

@@ -158,6 +174,7 @@ func (l *lexable) lexRelationType() (Relation, error) {
158174
if err != nil {
159175
return 0, fmt.Errorf("can't read relation type: %s", err)
160176
}
177+
161178
switch word {
162179
case "!":
163180
return Antonym, nil
@@ -213,6 +230,7 @@ func (l *lexable) lexRelationType() (Relation, error) {
213230
case "~i":
214231
return InstanceHyponym, nil
215232
}
233+
216234
return 0, fmt.Errorf("unrecognized pointer type: %q", word)
217235
}
218236

@@ -247,25 +265,30 @@ func parseLine(data []byte, line int64) (*parsed, error) {
247265
}
248266
return nil, fmt.Errorf("can't parse line, expected comment or Offset")
249267
}
268+
250269
// file number
251270
filenum, err := l.lexDecimalNumber()
252271
if err != nil {
253272
return nil, fmt.Errorf("filenumber expected: %s", err)
254273
}
274+
255275
pos, err := l.lexPOS()
256276
if err != nil {
257277
return nil, fmt.Errorf("part of speech expected: %s", err)
258278
}
279+
259280
// lexicographer file containing the word
260281
wordcount, err := l.lexHexNumber()
261282
if err != nil {
262283
return nil, fmt.Errorf("wordcount expected: %s", err)
263284
}
285+
264286
p := parsed{
265287
byteOffset: byteOffset,
266288
pos: pos,
267289
fileNum: filenum,
268290
}
291+
269292
for ; wordcount > 0; wordcount-- {
270293
value, err := l.lexWord()
271294
if err != nil {
@@ -281,10 +304,12 @@ func parseLine(data []byte, line int64) (*parsed, error) {
281304
sense: uint8(sense),
282305
})
283306
}
307+
284308
pcount, err := l.lexDecimalNumber()
285309
if err != nil {
286310
return nil, fmt.Errorf("pointer count expected: %s", err)
287311
}
312+
288313
for ; pcount > 0; pcount-- {
289314
if rt, err := l.lexRelationType(); err != nil {
290315
return nil, err
@@ -310,6 +335,7 @@ func parseLine(data []byte, line int64) (*parsed, error) {
310335
p.rels = append(p.rels, r)
311336
}
312337
}
338+
313339
// parse optional frame count
314340
frameCount, err := l.lexDecimalNumber()
315341
if err == nil {
@@ -324,10 +350,12 @@ func parseLine(data []byte, line int64) (*parsed, error) {
324350
}
325351
}
326352
}
353+
327354
gloss, err := l.lexGloss()
328355
if err != nil {
329356
return nil, err
330357
}
358+
331359
p.gloss = gloss
332360

333361
return &p, nil

read.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func inPlaceReadLine(s io.Reader, cb func([]byte, int64, int64) error) error {
2626
offset += int64(len(line))
2727
count++
2828
}
29+
2930
// If we reached end of file and the line contents are empty, don't return an additional line.
3031
if err == io.EOF {
3132
if len(line) > 0 {
@@ -34,6 +35,7 @@ func inPlaceReadLine(s io.Reader, cb func([]byte, int64, int64) error) error {
3435
} else {
3536
return cb(line, count, offset)
3637
}
38+
3739
return nil
3840
}
3941

@@ -42,10 +44,12 @@ func inPlaceReadLineFromPath(filePath string, cb func([]byte, int64, int64) erro
4244
if err != nil {
4345
return err
4446
}
47+
4548
defer func() {
4649
if cerr := f.Close(); cerr != nil {
4750
fmt.Println("Error closing file:", cerr)
4851
}
4952
}()
53+
5054
return inPlaceReadLine(f, cb)
5155
}

wordnet.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (w *Lookup) Related(r Relation) (relationships []Lookup) {
209209
})
210210
}
211211
}
212+
212213
// next let's look for syntactic relationships
213214
key := normalize(w.word)
214215
for _, word := range w.cluster.words {
@@ -437,10 +438,11 @@ func wordbase(word string, ender int) string {
437438

438439
// Try to find all possible baseforms (lemmas) of individual word in POS.
439440
func (h *Handle) MorphWord(word string, pos PartOfSpeech) string {
440-
if pos == Adverb {
441+
switch pos {
442+
case Adverb:
441443
// Adverbs are not inflected in WordNet
442444
return ""
443-
} else if pos == Noun {
445+
case Noun:
444446
if strings.HasSuffix(word, "ful") {
445447
return word[:len(word)-3]
446448
} else if strings.HasSuffix(word, "ss") || len(word) <= 2 {

wordnet_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package wnram
33
import (
44
"path"
55
"runtime"
6+
"slices"
67
"testing"
78
)
89

@@ -107,20 +108,15 @@ func TestLemma(t *testing.T) {
107108
}
108109
t.Fatalf("expected one synonym cluster for awesome, got %d", len(found))
109110
}
111+
110112
if found[0].Lemma() != "amazing" {
111113
t.Errorf("incorrect lemma for awesome (%s)", found[0].Lemma())
112114
}
113115
}
114116

115117
func setContains(haystack, needles []string) bool {
116118
for _, n := range needles {
117-
found := false
118-
for _, h := range haystack {
119-
if n == h {
120-
found = true
121-
break
122-
}
123-
}
119+
found := slices.Contains(haystack, n)
124120
if !found {
125121
return false
126122
}
@@ -160,6 +156,7 @@ func TestAntonyms(t *testing.T) {
160156
antonyms = append(antonyms, a.Word())
161157
}
162158
}
159+
163160
if !setContains(antonyms, []string{"bad", "evil"}) {
164161
t.Errorf("missing antonyms for good")
165162
}
@@ -178,6 +175,7 @@ func TestHypernyms(t *testing.T) {
178175
hypernyms = append(hypernyms, a.Word())
179176
}
180177
}
178+
181179
if !setContains(hypernyms, []string{"punch"}) {
182180
t.Errorf("missing hypernyms for jab (expected punch, got %v)", hypernyms)
183181
}
@@ -196,6 +194,7 @@ func TestHyponyms(t *testing.T) {
196194
hyponyms = append(hyponyms, a.Word())
197195
}
198196
}
197+
199198
expected := []string{"chocolate", "cheese", "pasta", "leftovers"}
200199
if !setContains(hyponyms, expected) {
201200
t.Errorf("missing hyponyms for candy (expected %v, got %v)", expected, hyponyms)
@@ -208,9 +207,11 @@ func TestIterate(t *testing.T) {
208207
count++
209208
return nil
210209
})
210+
211211
if err != nil {
212212
t.Fatalf("Iterate failed: %v", err)
213213
}
214+
214215
if count != 82192 {
215216
t.Errorf("Missing nouns!")
216217
}

0 commit comments

Comments
 (0)