예제 #1
0
//Split the arctile into some sentences
func SplitSentence(buf []rune, d *dict.Sign) []*Sentence {
	sentences := make([]*Sentence, 0)
	start := 0
	for i, count := 0, len(buf); i < count; i++ {
		current := string(buf[i])
		if IsSpace(buf[i]) {
			//fmt.Println(i, start)
			if i == start {
				start++
			}
		}

		if i == count-1 || d.IsContain(current) {
			if i > start {
				sentence := &Sentence{
					text:  buf[start:i],
					start: start,
					end:   i,
				}

				sentences = append(sentences, sentence)
			}

			start = i + 1
		}
	}

	return sentences
}
예제 #2
0
func FilterSegment(segments []*segment.Segment, stopdict *dict.Sign) []*segment.Segment {
	newSegs := make([]*segment.Segment, 0)
	for _, seg := range segments {
		key := seg.Text()

		if IsSpace(key) {
			continue
		}

		match, _ := regexp.MatchString("[\\d]+", key)
		if match {
			continue
		}

		if !stopdict.IsContain(key) {
			newSegs = append(newSegs, seg)
		}
	}

	return newSegs
}