Ejemplo n.º 1
0
func Test_SegmentMerger(t *testing.T) {
	sign := dict.NewSign("../data/dictionary/sign.txt")
	stop := dict.NewSign("../data/dictionary/stopwords.txt")
	d := dict.NewDictionary("../data/dictionary/sogoudictionary.txt")

	article := util.ReadFile("../data/testdata/125-2.txt")
	allsegs := segment.SegmentDoc(article, sign, d)
	allsegs = occurrence.FilterSegment(allsegs, stop)
	fmt.Println(len(allsegs))
	str := segment.GetSegmentStr(allsegs)

	util.WriteFile("../data/test-125-2.log", str)

	occur := occurrence.NewOccurrence()
	occur.AddSegments(allsegs, 3)
	occur.Compute()
	occur.Output()

	pairTerms := occur.GetPairTerms(10.0)
	str = term.GetPairTermStr(pairTerms)
	util.WriteFile("../data/test-125-2-occur.log", str)

	newSegments := occurrence.MergeSegment(allsegs, pairTerms)
	fmt.Println(len(newSegments))
	str = segment.GetSegmentStr(newSegments)
	//fmt.Println(str)
	util.WriteFile("../data/test-125-2-merge.log", str)

	occur1 := occurrence.NewOccurrence()
	occur1.AddSegments(newSegments, 1)
	occur1.Compute()
	occur1.Output()
	pairTerms = occur1.GetPairTerms(10.0)
	str = term.GetPairTermStr(pairTerms)
	util.WriteFile("../data/test-125-2-second-merge.log", str)
}
Ejemplo n.º 2
0
func Test_Occurrence_Compute(t *testing.T) {
	//var segmenter sego.Segmenter
	//segmenter.LoadDictionary("C:/Go/thirdpartlib/src/github.com/huichen/sego/data/dictionary.txt")
	filename := "../data/testdata/125-2.txt"

	buf, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err)
		panic(err)
	}

	sign := dict.NewSign("../data/dictionary/sign.txt")
	d := dict.NewDictionary("../data/dictionary/sogoudictionary.txt")
	//stop := dict.NewSign("../data/dictionary/stopwords.txt.txt")
	//segments := segmenter.Segment(buf)
	segments := segment.SegmentDoc(string(buf), sign, d)
	fmt.Println(len(segments))
	LogSegments(segments)
	occur := occurrence.NewOccurrence()
	occur.AddSegments(segments, 3)
	occur.Compute(1)
	occur.Output()
}