package main

import (
	"bufio"
	log "github.com/donnie4w/go-logger/logger"
	"github.com/pinyin-master"
	"io"
	"os"
	"regexp"
	"strings"
)

var industryArr = []string{
	"服务采购_安保",
	"服务采购_仓储物流",
	"服务采购_法律咨询",
	"服务采购_广告宣传印刷",
	"服务采购_其他",
	"服务采购_物业",
	"机械设备_车辆",
	"机械设备_工程机械",
	"机械设备_机床相关",
	"机械设备_机械零部件",
	"机械设备_矿山机械",
	"机械设备_其他机械设备",
	"建筑工程_材料设备",
	"建筑工程_工程施工",
	"建筑工程_机电安装",
	"建筑工程_监理咨询",
	"建筑工程_勘察设计",
	"交通工程_道路",
	"交通工程_轨道",
	"交通工程_其他",
	"交通工程_桥梁",
	"能源化工_化工产品",
	"能源化工_设备物资",
	"能源化工_仪器仪表",
	"能源化工_原材料",
	"农林牧渔_生产设备",
	"农林牧渔_生产物资",
	"农林牧渔_相关服务",
	"弱电安防_智能系统",
	"弱电安防_综合布线",
	"市政设施_道路",
	"市政设施_绿化",
	"市政设施_线路管网",
	"市政设施_综合项目",
	"水利水电_发电工程",
	"水利水电_航运工程",
	"水利水电_其他工程",
	"水利水电_水利工程",
	"信息技术_其他",
	"信息技术_软件开发",
	"信息技术_系统集成及安全",
	"信息技术_运维服务",
	"行政办公_办公家具",
	"行政办公_办公用品",
	"行政办公_生活用品",
	"行政办公_通用办公设备",
	"行政办公_专业设备",
	"医疗卫生_耗材",
	"医疗卫生_设备",
	"医疗卫生_药品",
}

var IsValid *regexp.Regexp = regexp.MustCompile("^([\u4e00-\u9fa5A-Za-z]+)$")

//导出行业词
func exportIndustryWords() {

	for _, v := range industryArr {
		name := "行业词/" + v + ".txt"
		f, _ := os.Open(name)
		defer f.Close()
		rd := bufio.NewReader(f)

		arr := strings.Split(v, "_")
		class_1 := arr[0]
		class_2 := arr[1]
		total := 0
		for {
			total++
			line, err := rd.ReadString('\n') //以'\n'为结束符读入一行
			if err != nil || io.EOF == err {
				break
			}
			line = strings.ReplaceAll(line, "", "")
			line = strings.ReplaceAll(line, "\r", "")
			line = strings.ReplaceAll(line, "\n", "")
			if len(line) > 0 {
				first_word := string([]rune(line)[0:1])
				str, _ := pinyin.New(first_word).Split("").Mode(pinyin.InitialsInCapitals).Convert()
				letter := ""
				if len(str) > 0 {
					l := str[:1]
					if LetterReg.MatchString(l) {
						letter = strings.ToUpper(l)
					}
				}
				if letter == "" || !IsValid.MatchString(line) {
					log.Debug(line)
				} else {
					info := map[string]interface{}{}
					info["class_1"] = class_1
					info["class_2"] = class_2
					info["name"] = line
					info["letter"] = letter
					Source_Mgo.Save("zktest_mysql_industry_info", info)
				}
			}

		}
		//log.Debug(v, "~", total)
	}

	log.Debug("is over ~~~")
}
