db flag, shuffle high freq. words

main
Robert 2 years ago
parent ecade0ea0a
commit 936b9cbfd0
  1. 21
      create_db.go
  2. 5
      readData.go
  3. 10
      writeData.go

@ -3,7 +3,9 @@ package main
import (
"database/sql"
"fmt"
"flag"
"io/ioutil"
"math/rand"
"log"
"strings"
@ -22,8 +24,14 @@ var topEnglishWords = []string{
}
func main() {
dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use")
flag.Parse()
// Randomize high Freq. words
shuffleArray(topEnglishWords)
// Open SQLite database file
db, err := sql.Open("sqlite3", "./english_words.db")
db, err := sql.Open("sqlite3", *dbPtr)
if err != nil {
log.Fatal(err)
}
@ -93,3 +101,14 @@ func main() {
fmt.Println("American-English words inserted into the database.")
}
func shuffleArray(arr []string) {
n := len(arr)
for i := n - 1; i > 0; i-- {
// Generate a random index between 0 and i (inclusive)
j := rand.Intn(i + 1)
// Swap the elements at indices i and j
arr[i], arr[j] = arr[j], arr[i]
}
}

@ -23,13 +23,14 @@ func containsSymbol(input string, symbols []string) bool {
}
func main() {
// Define a command-line flag for the filename
// Define a command-line flags
dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use")
filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to")
pwdPtr := flag.String("pwd", "", "Enter a password")
flag.Parse()
// Open the SQLite3 database file
db, err := sql.Open("sqlite3", "./english_words.db")
db, err := sql.Open("sqlite3", *dbPtr)
if err != nil {
log.Fatal(err)
}

@ -12,19 +12,15 @@ import (
_ "github.com/mattn/go-sqlite3"
)
var symbols = []string{
".", ",", "!", ";", "?", "(", ")", "'", "\"",
}
func main() {
// Define a command-line flag for the filename
// Define a command-line flags
dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use")
filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to")
pwdPtr := flag.String("pwd", "", "Enter a password")
flag.Parse()
// Open the SQLite3 database file
db, err := sql.Open("sqlite3", "./english_words.db")
db, err := sql.Open("sqlite3", *dbPtr)
if err != nil {
log.Fatal(err)
}

Loading…
Cancel
Save