當前位置: 首頁>>代碼示例>>Golang>>正文


Golang analysis.Token類代碼示例

本文整理匯總了Golang中github.com/blevesearch/bleve/analysis.Token的典型用法代碼示例。如果您正苦於以下問題:Golang Token類的具體用法?Golang Token怎麽用?Golang Token使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Token類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: shingleCurrentRingState

func (s *ShingleFilter) shingleCurrentRingState(ring *ring.Ring, itemsInRing int) analysis.TokenStream {
	rv := make(analysis.TokenStream, 0)
	for shingleN := s.min; shingleN <= s.max; shingleN++ {
		// if there are enough items in the ring
		// to produce a shingle of this size
		if itemsInRing >= shingleN {
			thisShingleRing := ring.Move(-(shingleN - 1))
			shingledBytes := make([]byte, 0)
			pos := 0
			start := -1
			end := 0
			for i := 0; i < shingleN; i++ {
				if i != 0 {
					shingledBytes = append(shingledBytes, []byte(s.tokenSeparator)...)
				}
				curr := thisShingleRing.Value.(*analysis.Token)
				if pos == 0 && curr.Position != 0 {
					pos = curr.Position
				}
				if start == -1 && curr.Start != -1 {
					start = curr.Start
				}
				if curr.End != -1 {
					end = curr.End
				}
				shingledBytes = append(shingledBytes, curr.Term...)
				thisShingleRing = thisShingleRing.Next()
			}
			token := analysis.Token{
				Type: analysis.Shingle,
				Term: shingledBytes,
			}
			if pos != 0 {
				token.Position = pos
			}
			if start != -1 {
				token.Start = start
			}
			if end != -1 {
				token.End = end
			}
			rv = append(rv, &token)
		}
	}
	return rv
}
開發者ID:ekanite,項目名稱:bleve,代碼行數:46,代碼來源:shingle.go

示例2: Tokenize

func (t *UnicodeWordBoundaryTokenizer) Tokenize(input []byte) analysis.TokenStream {
	rv := make(analysis.TokenStream, 0)

	if len(input) < 1 {
		return rv
	}

	// works
	var myUnsafePointer = unsafe.Pointer(&(input[0]))
	var myCCharPointer *C.char = (*C.char)(myUnsafePointer)

	var inlen C.int32_t = C.int32_t(len(input))
	var buflen C.int32_t = C.int32_t(2*len(input) + 1) // worse case each byte becomes 2
	var stringToExamine []C.UChar = make([]C.UChar, buflen)
	var myUnsafePointerToExamine = unsafe.Pointer(&(stringToExamine[0]))
	var myUCharPointer *C.UChar = (*C.UChar)(myUnsafePointerToExamine)
	C.u_uastrncpy(myUCharPointer, myCCharPointer, inlen)

	var err C.UErrorCode = C.U_ZERO_ERROR
	bi := C.ubrk_open(C.UBRK_WORD, t.locale, myUCharPointer, -1, &err)

	if err > C.U_ZERO_ERROR {
		return rv
	}

	defer C.ubrk_close(bi)

	position := 0
	var prev C.int32_t
	p := C.ubrk_first(bi)
	for p != C.UBRK_DONE {

		q := C.ubrk_getRuleStatus(bi)

		// convert boundaries back to utf8 positions
		var nilCString *C.char
		var indexA C.int32_t

		C.u_strToUTF8(nilCString, 0, &indexA, myUCharPointer, prev, &err)
		if err > C.U_ZERO_ERROR && err != C.U_BUFFER_OVERFLOW_ERROR {
			return rv
		} else {
			err = C.U_ZERO_ERROR
		}

		var indexB C.int32_t
		C.u_strToUTF8(nilCString, 0, &indexB, myUCharPointer, p, &err)
		if err > C.U_ZERO_ERROR && err != C.U_BUFFER_OVERFLOW_ERROR {
			return rv
		} else {
			err = C.U_ZERO_ERROR
		}

		if q != 0 {
			position += 1
			token := analysis.Token{
				Start:    int(indexA),
				End:      int(indexB),
				Term:     input[indexA:indexB],
				Position: position,
				Type:     analysis.AlphaNumeric,
			}
			if q == 100 {
				token.Type = analysis.Numeric
			}
			if q == 400 {
				token.Type = analysis.Ideographic
			}
			rv = append(rv, &token)
		}
		prev = p
		p = C.ubrk_next(bi)
	}

	return rv
}
開發者ID:drewwells,項目名稱:bleve,代碼行數:76,代碼來源:boundary.go


注:本文中的github.com/blevesearch/bleve/analysis.Token類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。