-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseText.go
More file actions
36 lines (31 loc) · 1.17 KB
/
parseText.go
File metadata and controls
36 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func checkStringForKeywords(s string) (int, error) {
sampleText := `Spice up your Valentine's date night with an Oriental dinner date and live music. Head over to Fortune Miramar on 14th February and enjoy a delicious meal at Ramens and More, Chris will surely keep you entertained with his popular beats. And lastly, end the perfect evening with a complimentary dessert platter with your loved one. For table reservations call 0832-6637373.
#FortuneMiramar #FortuneHotels #Goa #ValentinesOffer #ValentinesDay #ValentinesDinner #Ramen #NoodleBowl #RiceBowl #Noodles #Food #Foodie #Meal #MealOfTheDay #Noodles`
keywordsFile, err := os.Open("keywords.txt")
if err != nil {
return 0, err
}
defer keywordsFile.Close()
reader := bufio.NewReader(keywordsFile)
keyword, err := reader.ReadString('\n')
var keywords []string
for err == nil {
keywords = append(keywords, strings.TrimSpace(keyword))
keyword, err = reader.ReadString('\n')
}
hitCount := 0
for _, key := range keywords {
if strings.Contains(strings.ToLower(sampleText), strings.ToLower(key)) {
hitCount++
fmt.Println(key)
}
}
return hitCount, nil
}