forked from jhtimmins/dagster-spam-filter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample_data.py
66 lines (54 loc) · 1.72 KB
/
sample_data.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
import duckdb
# Define spam and non-spam words
spam_words = ["urgent", "winner", "guarantee", "congratulations", "prize", "free"]
non_spam_words = ["hello", "meeting", "schedule", "update", "invoice", "reminder"]
# Define templates for spam and non-spam messages
spam_templates = [
"You are the {0}!",
"Claim your {1} {0} now!",
"{1} {0} offer!",
"This is an {0} message!",
]
non_spam_templates = [
"{0}, can we have a {1}?",
"{1} on your {0}.",
"{0} {1} for the week.",
]
# Connect to DuckDB
conn = duckdb.connect("database.duckdb")
# Create dimension table if it doesn't exist
conn.execute(
"""
CREATE TABLE IF NOT EXISTS messages (
spam BOOLEAN,
body VARCHAR
);
"""
)
# Initialize list to hold fake messages and labels
fake_messages = []
fake_labels = []
# Generate 10,000 fake messages
for _ in range(10000):
is_spam = random.choice([True, False])
if is_spam:
template = random.choice(spam_templates)
words_needed = [random.choice(spam_words) for _ in range(template.count("{"))]
message = template.format(*words_needed)
else:
template = random.choice(non_spam_templates)
words_needed = [
random.choice(non_spam_words) for _ in range(template.count("{"))
]
message = template.format(*words_needed)
fake_messages.append(message)
fake_labels.append(is_spam)
# Insert the fake data into the messages table
for message, is_spam in zip(fake_messages, fake_labels):
conn.execute("INSERT INTO messages (spam, body) VALUES (?, ?)", (is_spam, message))
# Commit changes to the database
conn.commit()
# Verify data insertion
result = conn.execute("SELECT * FROM messages LIMIT 10").fetchall()
print(result)