package main

import (
	"fmt"
	"jy/admin/track"
	"jy/extract"
	. "jy/mongodbutil"
	"log"
	"os"
	"regexp"
	"strconv"
	"strings"
	"testing"
	"time"
)

func Test_han(t *testing.T) {
	str := `[\u4e00-\u9fa5]` //"[\u4e00-\u9fa5]"
	//var rg = regexp.MustCompile(`[\u4e00-\u9fa5]`)会出错
	if strings.Contains(str, "\\u") {
		pattern, _ := strconv.Unquote(`"` + str + `"`)
		log.Println(pattern)
	}
	var rg = regexp.MustCompile(str)
	fmt.Println(rg.MatchString(str))
	os.Exit(0)
}
func Test_task(t *testing.T) {
	Mgo = MgoFactory(1, 3, 120, "192.168.3.207:27082", "extract_kf")
	//extract.StartExtractTaskId("5b8f804025e29a290415aee1")5c528686698414055c47b115
	extract.StartExtractTestTask("5cdd3025698414032c8322b1", "5736324a61a0721f15f73188", "1", "mxs_v1", "mxs_v1")
	//extract.StartExtractTestTask("5c3d75c96984142998eb00e1", "5c2a3d28a5cb26b9b76144dd", "100", "mxs_v3", "mxs_v3")
	time.Sleep(5 * time.Second)
}
func Test_extractcity(t *testing.T) {
	Mgo = MgoFactory(1, 3, 120, "192.168.3.207:27082", "extract_kf")
	extract.InitDFA2()
	//查询采购单位信息
	extract.FindBuyer()
}
func Test_reg(t *testing.T) {
	reg1, _ := regexp.Compile("((([（(]\\d{3,4}[)）])?(\\d{6,12}([×―—－\\-]+\\d{3,4})?|\\d{3,5}[×―—－\\-]+[\u3000\u2003\u00a0\\s]*\\d{6,12}([×―—－\\-]+\\d{3,})?|(\\d{2}[×―—－\\-])+\\d{8}[×―—－\\-](\\d{3}[、])+)(转\\d{3,4})?[或/、,，;；\u3000\u2003\u00a0\\s]*)+(\\d{3,})?)")
	log.Println("---", reg1.FindAllString("05939-5365001(兰陵县芦柞镇人民政府)", -1))
	reg2, _ := regexp.Compile("^\\d*[×―—－\\-]*[\u3000\u2003\u00a0\\s]*\\d*$")
	log.Println("---", reg2.MatchString("张女士/"))
	filterK := regexp.MustCompile("[(（\\[【].*?[)）\\]】]|<[^>].+?>|[①②③￥·；;‘“'’”,*<>(（\\[【、)）/\\]】？?,。．\".\\s\u3000\u2003\u00a0]+|^[一二三四五六七八九十0-9１２３４５６７８９０]+")
	log.Println(filterK.FindString("二）采购项目联系人（代理机构）"))
}

func Test_reg1(t *testing.T) {
	context := `sss<input  name="AgentCode" size="30" maxsize="50" value="91370800688271668P" class="textbox">
    dfdf<input type="hidden" name="AgentCode" size="30" maxsize="50" value="tttt" class="textbox"></input>`
	reg := regexp.MustCompile(`<\s*input.*value=['"](.[^'"]+).+>`)
	tmp := reg.ReplaceAllString(context, "$1")
	log.Println(tmp)
}

func Test_paths(t *testing.T) {
	Mgo = MgoFactory(1, 3, 120, "192.168.3.207:27082", "extract_v3")
	tracks := track.GetTrackPath("5b8dd276a5cb26b9b7faaa7c", "projectname", "rack_v3", "result_v3")
	for code, v := range tracks {
		if tmp, ok := v.([]map[string]interface{}); ok {
			for k, v := range tmp {
				if k == 0 {
					log.Println(v)
				} else {
					log.Println(code, v["code"], v["value"])
				}
			}
		}
		break
	}
}

func Test_clear(t *testing.T) {
	value := "法拉(盛（客{）户)端副科级沙发俩括号的"
	log.Println("pre---", value)
	startChars := []string{"[（(]", "[\\[【]", "[{｛]", "[<《]", "〔"}
	endChars := []string{"[)）]", "[\\]】]", "[}｝]", "[>》]", "〕"}
	for k, v := range startChars {
		sReg := regexp.MustCompile(v)
		eReg := regexp.MustCompile(endChars[k])
		sIndex := sReg.FindAllStringIndex(value, -1)
		eIndex := eReg.FindAllStringIndex(value, -1)
		sCount := len(sIndex)
		eCount := len(eIndex)
		if sCount == eCount {
			continue
		}
		log.Println("value1---", value, sCount, eCount)
		//清理前面
		if sCount > eCount {
			value = value[sIndex[eCount][1]:]
		}
		log.Println("value2---", value)
		//清理后面
		if sCount < eCount {
			value = value[:eIndex[sCount][0]]
		}
		log.Println("value3---", value)
	}
	log.Println("value4---", value)
	//交叉出现情况处理
	sReplReg := regexp.MustCompile("[（(\\[【{｛〔<《][^）)\\]】}｝〕>》]*$")
	eReplReg := regexp.MustCompile("^[^（(\\[【{｛〔<《]*[）)\\]】}｝〕>》]")
	if sReplReg.MatchString(value) || eReplReg.MatchString(value) {
		value = sReplReg.ReplaceAllString(value, "")
		value = eReplReg.ReplaceAllString(value, "")
		//value = fmt.Sprint(childCutNotPrs([]interface{}{value, data[1]}, count+1)[0])
	}
	log.Println("result---", value)
}
