Unverified Commit bca1a519 by David Star Committed by GitHub

Merge pull request #1 from yanchaosb123/rank_opt

算分优化
parents a59ff1f5 33b7d636
package main
import (
"net/http"
"time"
"encoding/json"
"bytes"
"io/ioutil"
"container/list"
"strings"
"github.com/mozillazg/go-pinyin"
"fmt"
"strconv"
"fmt"
)
type ENV struct {
......@@ -16,6 +22,13 @@ type ENV struct {
ManualFolder string
SensitiveFolder string
}
type Message struct {
Title string
Phones *list.List
Body *list.List
}
var test_env = &ENV{
DataWareDB: "DataWarehouse_test:FihdZW7o1XKtDETZexOG@tcp(test01-secooDataWarehouse.master.com:3306)/secooDataWarehouse",
ErpDB: "3306_test:iS6CXpYqgZ8Mhjui@tcp(10.4.3.223:3306)/secooErpDB",
......@@ -37,12 +50,28 @@ var prod_env = &ENV {
SensitiveFolder: "/data/pssmaster/corpus_set/suggest_corpus/sensitive"}
// 重要,该参数 确定是 正式还是 测试环境
var RUN_ENV = test_env
var RUN_ENV = prod_env
/************************* 下面是 util 方法 *****************************/
var CH_EN_PUNC = map[string]string {
",":",",
"。":".",
"!":"!",
"?":"?",
"【":"[",
"】":"]",
"(":"(",
")":")",
"‘":"'",
"’":"'",
"“":"\"",
"”":"\"",
}
func convertToPinyin(str string) string {
var ret string
for _, v := range str {
......@@ -62,7 +91,7 @@ func convertToPinyin(str string) string {
func cleanKeyword(keyword string) string {
out, err := t2s.Convert(keyword)
if err != nil { fmt.Println(err) }
keyword = strings.ToLower(strings.Trim(DBC2SBC(strings.TrimSpace(out)),"\ufffc|,"))
keyword = strings.ToLower(strings.Trim(DBC2SBC(strings.TrimSpace(out)),"\ufffc|,|."))
return strings.Join(strings.Fields(keyword)," ")
}
......@@ -78,12 +107,16 @@ func DBC2SBC(s string) string {
var strLst []string
for _, i := range s {
insideCode := i
if insideCode == 12288 {
insideCode = 32
} else {
insideCode -= 65248
}
if insideCode < 32 || insideCode > 126 {
if key,exist := CH_EN_PUNC[string(i)]; exist {
strLst = append(strLst, key)
} else if insideCode < 32 || insideCode > 126 {
strLst = append(strLst, string(i))
} else {
strLst = append(strLst, string(insideCode))
......@@ -91,3 +124,41 @@ func DBC2SBC(s string) string {
}
return strings.Join(strLst, "")
}
// 发送POST请求
// url: 请求地址
// data: POST请求提交的数据
// contentType: 请求体格式,如:application/json
func Post(url string, data interface{}, contentType string) string {
// 超时时间:5秒
client := &http.Client{Timeout: 5 * time.Second}
jsonStr, _ := json.Marshal(data)
resp, err := client.Post(url, contentType, bytes.NewBuffer(jsonStr))
if err != nil {
panic(err)
}
defer resp.Body.Close()
result, _ := ioutil.ReadAll(resp.Body)
return string(result)
}
func sendSuggestNotify() {
msg := Message{
Title:"提示词数据异常",
}
body := list.New()
body.PushBack("提示词数据太少")
msg.Body = body
phones := list.New()
phones.PushBack("17621863255,13894895183")
msg.Phones = phones
Post("http://matrix-inform.secoolocal.com/user/sendToUser", msg,"application/json")
}
package main
import (
"encoding/json"
"math"
"strings"
"fmt"
)
......@@ -13,20 +14,29 @@ type B struct {
YearCartCount int32 `json:"yearCartCount"`
ZhaoCount int32 `json:"-"`
}
func main() {
b := B{
Keyword: "赵延超",
KeywordPinYin: "zhaoyanchao",
YearCount: 1000,
YearCartCount: 100,
YearClickCount: 10,
ZhaoCount: 2}
if jsonBytes,errs := json.Marshal(b); errs == nil {
fmt.Print(string(jsonBytes))
prefix := strings.HasPrefix("tod's", "tod's")
fmt.Print(prefix)
}
func calculateRatioFactor2(ratio float64, count int32) float64 {
var rank float64
switch {
case count > 1 && count < 10 : rank = 1.2
case count >= 10 && count < 20 : rank = 1.4
case count >= 20 && count < 50 : rank = 1.6
case count >= 50 && count < 100 : rank = 1.8
case count >= 100 && count < 200 : rank = 2.0
case count >= 200 && count < 500 : rank = 2.2
case count >= 500 : rank = 2.5
default:rank = 1.0
}
//根据搜索转化率,转换为热度因子
return math.Log10(math.Sqrt(ratio + 10)) * rank
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment