mirror of
https://github.com/safing/portmaster
synced 2025-09-04 19:49:15 +00:00
Clean up algs package
This commit is contained in:
parent
fd203fc8a7
commit
4d48b023ae
1 changed files with 15 additions and 13 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LmsScoreOfDomain calculates the mean longest meaningful substring of a domain. It follows some special rules to increase accuracy. It returns a value between 0 and 100, representing the length-based percentage of the meaningful substring.
|
||||||
func LmsScoreOfDomain(domain string) float64 {
|
func LmsScoreOfDomain(domain string) float64 {
|
||||||
var totalScore float64
|
var totalScore float64
|
||||||
domain = strings.ToLower(domain)
|
domain = strings.ToLower(domain)
|
||||||
|
@ -26,29 +27,30 @@ func LmsScoreOfDomain(domain string) float64 {
|
||||||
return totalScore
|
return totalScore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LmsScore calculates the longest meaningful substring of a domain. It returns a value between 0 and 100, representing the length-based percentage of the meaningful substring.
|
||||||
func LmsScore(subject string) float64 {
|
func LmsScore(subject string) float64 {
|
||||||
lms_start := -1
|
lmsStart := -1
|
||||||
lms_stop := -1
|
lmsStop := -1
|
||||||
longest_lms := 0
|
longestLms := 0
|
||||||
|
|
||||||
for i, c := range subject {
|
for i, c := range subject {
|
||||||
if int(c) >= int('a') && int(c) <= int('z') {
|
if int(c) >= int('a') && int(c) <= int('z') {
|
||||||
if lms_start == -1 {
|
if lmsStart == -1 {
|
||||||
lms_start = i
|
lmsStart = i
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if lms_start > -1 {
|
if lmsStart > -1 {
|
||||||
lms_stop = i
|
lmsStop = i
|
||||||
if lms_stop-lms_start > longest_lms {
|
if lmsStop-lmsStart > longestLms {
|
||||||
longest_lms = lms_stop - lms_start
|
longestLms = lmsStop - lmsStart
|
||||||
}
|
}
|
||||||
lms_start = -1
|
lmsStart = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lms_stop == -1 {
|
if lmsStop == -1 {
|
||||||
longest_lms = len(subject)
|
longestLms = len(subject)
|
||||||
}
|
}
|
||||||
// fmt.Printf("algs: lms score of %s is %.2f\n", subject, (float64(longest_lms) * 100.0 / float64(len(subject))))
|
// fmt.Printf("algs: lms score of %s is %.2f\n", subject, (float64(longest_lms) * 100.0 / float64(len(subject))))
|
||||||
return (float64(longest_lms) * 100.0 / float64(len(subject)))
|
return (float64(longestLms) * 100.0 / float64(len(subject)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue