Words and symbols in, punctuation out.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

29 linhas
515 B

  1. // punctuation takes text and gives back only punctuation.
  2. package punctuation
  3. import (
  4. "bufio"
  5. "os"
  6. "strings"
  7. )
  8. // valid characters to extract
  9. const validPunc = ";:'\",!?.-()"
  10. // Extract scans the given File and returns only typical punctuation used in
  11. // prose.
  12. func Extract(f *os.File) string {
  13. var out string
  14. in := bufio.NewScanner(f)
  15. for in.Scan() {
  16. out += strings.Map(func(r rune) rune {
  17. if strings.IndexRune(validPunc, r) >= 0 {
  18. return r
  19. }
  20. return -1
  21. }, in.Text())
  22. }
  23. return out
  24. }