Words and symbols in, punctuation out.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

punctuation.go 515 B

il y a 8 ans
il y a 8 ans
12345678910111213141516171819202122232425262728
  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. }