Skip to content

Commit

Permalink
tokenizer and weighting bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBelicza committed Feb 15, 2018
1 parent 7e7751e commit 285d247
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions parse/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ type Rule interface {
}

type RuleDefault struct {
wordSeparators [11]string
wordSeparators [18]string
sentenceSeparators [3]string
}

func NewRule() *RuleDefault {
return &RuleDefault{
[11]string{" ", ",", ")", "(", "[", "]", "{", "}", "\"", ";", "\n"},
[18]string{" ", ",", ")", "(", "[", "]", "{", "}", "\"", ";", "\n", ">", "<", "%", "@", "&", "=", "#"},
[3]string{"!", ".", "?"},
}
}
Expand Down
38 changes: 32 additions & 6 deletions rank/algorithm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rank

import "math"

type Algorithm interface {
WeightingRelation(
word1ID int,
Expand All @@ -21,7 +23,7 @@ type Algorithm interface {
) float32
}

type AlgorithmDefault struct {}
type AlgorithmDefault struct{}

func NewAlgorithmDefault() *AlgorithmDefault {
return &AlgorithmDefault{}
Expand All @@ -38,7 +40,13 @@ func (a *AlgorithmDefault) WeightingRelation(
wordQtyMin int,
wordQtyMax int,
) float32 {
return (float32(relationQty) - float32(relationMin)) / (float32(relationMax) - float32(relationMin))
weight := (float32(relationQty) - float32(relationMin)) / (float32(relationMax) - float32(relationMin))

if math.IsNaN(float64(weight)) {
return 0
}

return weight
}

func (a *AlgorithmDefault) WeightingHits(
Expand All @@ -47,10 +55,16 @@ func (a *AlgorithmDefault) WeightingHits(
wordMin int,
wordMax int,
) float32 {
return (float32(wordQty) - float32(wordMin)) / (float32(wordMax) - float32(wordMin))
weight := (float32(wordQty) - float32(wordMin)) / (float32(wordMax) - float32(wordMin))

if math.IsNaN(float64(weight)) {
return 0
}

return weight
}

type AlgorithmMixed struct {}
type AlgorithmMixed struct{}

func NewAlgorithmMixed() *AlgorithmMixed {
return &AlgorithmMixed{}
Expand All @@ -71,7 +85,13 @@ func (a *AlgorithmMixed) WeightingRelation(
max := float32(relationMax + wordQtyMax)
qty := float32(relationQty + word1Qty)

return (qty - min) / (max - min)
weight := (qty - min) / (max - min)

if math.IsNaN(float64(weight)) {
return 0
}

return weight
}

func (a *AlgorithmMixed) WeightingHits(
Expand All @@ -80,5 +100,11 @@ func (a *AlgorithmMixed) WeightingHits(
wordMin int,
wordMax int,
) float32 {
return (float32(wordQty) - float32(wordMin)) / (float32(wordMax) - float32(wordMin))
weight := (float32(wordQty) - float32(wordMin)) / (float32(wordMax) - float32(wordMin))

if math.IsNaN(float64(weight)) {
return 0
}

return weight
}

0 comments on commit 285d247

Please sign in to comment.