Explorar el Código

Write code

,.(:.---).
master
Matt Baer hace 6 años
commit
fe0a21acec
Se han modificado 4 ficheros con 44 adiciones y 0 borrados
  1. +2
    -0
      .gitignore
  2. +4
    -0
      README.md
  3. +13
    -0
      cmd/main.go
  4. +25
    -0
      punctuation.go

+ 2
- 0
.gitignore Ver fichero

@@ -0,0 +1,2 @@
*.swp
cmd/cmd

+ 4
- 0
README.md Ver fichero

@@ -0,0 +1,4 @@
punctuation
===========

Words and symbols in, punctuation out. Inspired by an [article on punctuation in novels](https://medium.com/@neuroecology/punctuation-in-novels-8f316d542ec4).

+ 13
- 0
cmd/main.go Ver fichero

@@ -0,0 +1,13 @@
package main

import (
"fmt"
"os"

"github.com/thebaer/punctuation"
)

func main() {
o := punctuation.Extract(os.Stdin)
fmt.Println(o)
}

+ 25
- 0
punctuation.go Ver fichero

@@ -0,0 +1,25 @@
// punctuation takes text and gives back only punctuation.
package punctuation

import (
"bufio"
"os"
"strings"
)

const validPunc = ";:'\",!?.-()"

func Extract(f *os.File) string {
var out string
in := bufio.NewScanner(f)
for in.Scan() {
out += strings.Map(func(r rune) rune {
if strings.IndexRune(validPunc, r) >= 0 {
return r
}
return -1
}, in.Text())
}

return out
}

Cargando…
Cancelar
Guardar