2016-02-26 18:52:03 +00:00
|
|
|
// punctuation takes text and gives back only punctuation.
|
|
|
|
package punctuation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-02-26 18:58:06 +00:00
|
|
|
// valid characters to extract
|
2016-02-26 18:52:03 +00:00
|
|
|
const validPunc = ";:'\",!?.-()"
|
|
|
|
|
2016-02-26 18:58:06 +00:00
|
|
|
// Extract scans the given File and returns only typical punctuation used in
|
|
|
|
// prose.
|
2016-02-26 18:52:03 +00:00
|
|
|
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
|
|
|
|
}
|