コード例 #1
0
ファイル: spellcheck.go プロジェクト: Reejoshi/cli
func NewCommandSuggester(existingCmds []string) CommandSuggester {
	model := fuzzy.NewModel()
	model.SetThreshold(1)
	model.SetDepth(1)

	model.Train(existingCmds)

	return CommandSuggester{model: model}
}
コード例 #2
0
ファイル: tokenizer.go プロジェクト: postfix/tweetanalyzer
func NewTokenizer() (*Tokenizer, error) {
	happy := `:-) :) ;) :o) :] :3 :c) :> =] 8) =) :} :^) :-d :d 8-d 8d x-d xd =-d =d =-3 =3 :-)) :'-) :') :* :^* >:p :-p x-p xp :p =p :-b :b >:) >;) >:-) <3 ;-) ;) ;-] ;] ;d ;^) >;) |;-)`
	sad := `>:[ :-( :( :-c :c :-< :< :-[ :[ :{ ;( :-|| :@ >:( :'-( :'( >:\\ >:/ :-/ :-. :\\ =/ =\\ :L =L :S >.< d; :-(( :(( ;-(( ;((`
	// http://sentiment.christopherpotts.net/lingstruc.html#negation
	negations := map[string]string{
		"don't":     "do not",
		"doesn't":   "do not",
		"didn't":    "do not",
		"won't":     "will not",
		"shouldn't": "will not",
		"wouldn't":  "will not",
		"isn't":     "is not",
		"aren't":    "is not",
		"wasn't":    "is not",
		"weren't":   "is not",
		"ain't":     "is not",
		"couldn't":  "can not",
		"can't":     "can not",
		"haven't":   "has not",
		"hasn't":    "has not",
		"hadn't":    "has not",
		"shan't":    "shall not",
		"mightn't":  "shall not",
		"mustn't":   "shall not",
		"mayn't":    "may not",
	}

	happyEmoticons := createMap(happy)
	sadEmoticons := createMap(sad)

	url := regexp.MustCompile(`((www\.[^\s]+)|(https?://[^\s]+))`)
	user := regexp.MustCompile(`@[^\s]+`)
	hashtag := regexp.MustCompile(`#([^\s]+)`)
	removeSpChars := regexp.MustCompile(`[^a-zA-Z_'-]+`)
	removeWhitesp := regexp.MustCompile(`[\s]+`)
	regexp := myRegexp{url: url, user: user, hashtag: hashtag, removeSpChars: removeSpChars, removeWhitesp: removeWhitesp}

	stopWords, err := createDict("data/stop_words.txt")
	if err != nil {
		return nil, err
	}

	spellCorrect := fuzzy.NewModel()
	spellCorrect.Train(fuzzy.SampleEnglish())
	spellCorrect.Threshold = 3

	return &Tokenizer{spellCorrect: spellCorrect, stopWords: stopWords, happyEmoticons: happyEmoticons, sadEmoticons: sadEmoticons, negationsWords: negations, myRegexp: regexp}, err
}
コード例 #3
0
ファイル: speak.go プロジェクト: johnskopis/whatwould
func Speak(cfg *string, quit chan bool) {
	handles := read_handles()
	creds := shared.ReadCreds(cfg)
	recv_chan := make(chan anaconda.Tweet)
	conn, err := shared.MakeConn(recv_chan)
	if err != nil {
		fmt.Printf("go error %s", err)
	}

	conn.BindRecvQueueChan("tweets", "worker", recv_chan)

	model := fuzzy.NewModel()
	model.SetDepth(4)
	model.Train(handles)

	anaconda.SetConsumerKey(creds["consumer_key"])
	anaconda.SetConsumerSecret(creds["consumer_secret"])
	//api := anaconda.NewTwitterApi(creds["access_token"], creds["access_token_secret"])

	go func() {
		<-quit
		fmt.Print("Caught an interrupt...cleanign up")
		conn.Close()
	}()

	for {
		select {
		case twt := <-recv_chan:
			if len(twt.Entities.User_mentions) != 0 {
				for _, u := range twt.Entities.User_mentions {
					suggest := model.Suggestions(u.Screen_name, false)
					if len(suggest) != 0 && suggest[0] != u.Screen_name {
						fmt.Printf("suggest: %s\n", model.Suggestions(u.Screen_name, false))
						fmt.Printf("mention: %s\n", u.Screen_name)
						fmt.Printf("twt: %s\n", twt.Text)
						fmt.Printf("%s\n", twt.User.ScreenName)
					}
				}
			}
		}
	}
}