Commits

Miki Tebeka committed f93d2e9 Merge

Merge with upstream

  • Participants
  • Parent commits 8d2c1cf, 5987800

Comments (0)

Files changed (2)

File example/song.txt

+The Road goes ever on and on
+Down from the door where it began.
+Now far ahead the Road has gone,
+And I must follow, if I can,
+Pursuing it with eager feet,
+Until it joins some larger way
+Where many paths and errands meet.
+And whither then? I cannot say.

File example/stem.go

+/* Example on using Snowball stemmer 
+
+This program will read a file, then print "word -> stem(word)" for every word in file
+*/
+package main
+
+import (
+	"bytes"
+	"flag"
+	"fmt"
+	"io/ioutil"
+	"os"
+	"regexp"
+
+	"bitbucket.org/tebeka/snowball"
+)
+
+func main() {
+	flag.Usage = func() {
+		fmt.Fprintf(os.Stderr, "usage: %s FILENAME\n", os.Args[0])
+		flag.PrintDefaults()
+	}
+	lang := flag.String("lang", "english", "stemmer language")
+	flag.Parse()
+
+	if flag.NArg() != 1 {
+		fmt.Fprintf(os.Stderr, "error: wrong number of arguments\n")
+		os.Exit(1)
+	}
+
+	stmr, err := snowball.New(*lang)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "error: %s\n", err)
+		os.Exit(1)
+	}
+
+	data, err := ioutil.ReadFile(flag.Arg(0))
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "error: can't open %s - %s\n", flag.Arg(0), err)
+		os.Exit(1)
+	}
+
+	re := regexp.MustCompile("[a-zA-Z]+")
+
+	for _, field := range re.FindAll(data, -1) {
+		word := string(bytes.ToLower(field))
+		fmt.Printf("%s -> %s\n", word, stmr.Stem(word))
+	}
+}