You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2014 Couchbase, Inc.
  2. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  3. // except in compliance with the License. You may obtain a copy of the License at
  4. // http://www.apache.org/licenses/LICENSE-2.0
  5. // Unless required by applicable law or agreed to in writing, software distributed under the
  6. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  7. // either express or implied. See the License for the specific language governing permissions
  8. // and limitations under the License.
  9. /*
  10. Package segment is a library for performing Unicode Text Segmentation
  11. as described in Unicode Standard Annex #29 http://www.unicode.org/reports/tr29/
  12. Currently only segmentation at Word Boundaries is supported.
  13. The functionality is exposed in two ways:
  14. 1. You can use a bufio.Scanner with the SplitWords implementation of SplitFunc.
  15. The SplitWords function will identify the appropriate word boundaries in the input
  16. text and the Scanner will return tokens at the appropriate place.
  17. scanner := bufio.NewScanner(...)
  18. scanner.Split(segment.SplitWords)
  19. for scanner.Scan() {
  20. tokenBytes := scanner.Bytes()
  21. }
  22. if err := scanner.Err(); err != nil {
  23. t.Fatal(err)
  24. }
  25. 2. Sometimes you would also like information returned about the type of token.
  26. To do this we have introduce a new type named Segmenter. It works just like Scanner
  27. but additionally a token type is returned.
  28. segmenter := segment.NewWordSegmenter(...)
  29. for segmenter.Segment() {
  30. tokenBytes := segmenter.Bytes())
  31. tokenType := segmenter.Type()
  32. }
  33. if err := segmenter.Err(); err != nil {
  34. t.Fatal(err)
  35. }
  36. */
  37. package segment