-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from CocaineCong/feature-bm25
refactor: extract the segment with weight module
- Loading branch information
Showing
4 changed files
with
49 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,4 @@ _testmain.go | |
.glide/ | ||
examples/dict/embed/embed | ||
examples/dict/embed/main | ||
oryxBuildBinary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package segment | ||
|
||
// Segment type a word with weight. | ||
type Segment struct { | ||
Text string | ||
Weight float64 | ||
} | ||
|
||
// Text return the segment's text. | ||
func (s Segment) GetText() string { | ||
return s.Text | ||
} | ||
|
||
// Weight return the segment's weight. | ||
func (s Segment) GetWeight() float64 { | ||
return s.Weight | ||
} | ||
|
||
// Segments type a slice of Segment. | ||
type Segments []Segment | ||
|
||
func (ss Segments) Len() int { | ||
return len(ss) | ||
} | ||
|
||
func (ss Segments) Less(i, j int) bool { | ||
if ss[i].Weight == ss[j].Weight { | ||
return ss[i].Text < ss[j].Text | ||
} | ||
|
||
return ss[i].Weight < ss[j].Weight | ||
} | ||
|
||
func (ss Segments) Swap(i, j int) { | ||
ss[i], ss[j] = ss[j], ss[i] | ||
} |