Create fake_news.py
Browse files- fake_news.py +50 -0
fake_news.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from faker import Faker
|
3 |
+
import random
|
4 |
+
from datetime import datetime, timedelta
|
5 |
+
|
6 |
+
fake = Faker()
|
7 |
+
|
8 |
+
def generate_fake_data(num_nodes=10, num_links=5):
|
9 |
+
nodes = []
|
10 |
+
links = []
|
11 |
+
topics = ["Environment", "Politics", "Technology", "Health", "Economy"]
|
12 |
+
emotions = ["trust", "joy", "fear", "sadness", "anger", "surprise"]
|
13 |
+
sentiments = ["positive", "negative", "neutral"]
|
14 |
+
|
15 |
+
# Generate nodes
|
16 |
+
for i in range(1, num_nodes + 1):
|
17 |
+
node = {
|
18 |
+
"id": i,
|
19 |
+
"headline": fake.sentence(nb_words=6),
|
20 |
+
"topic": random.choice(topics),
|
21 |
+
"emotion": random.choice(emotions),
|
22 |
+
"time": (datetime.now() - timedelta(days=random.randint(0, 365))).strftime("%Y-%m-%d"),
|
23 |
+
"sentiment": random.choice(sentiments)
|
24 |
+
}
|
25 |
+
nodes.append(node)
|
26 |
+
|
27 |
+
# Generate links
|
28 |
+
for _ in range(num_links):
|
29 |
+
source = random.randint(1, num_nodes)
|
30 |
+
target = random.randint(1, num_nodes)
|
31 |
+
while target == source:
|
32 |
+
target = random.randint(1, num_nodes)
|
33 |
+
|
34 |
+
link = {
|
35 |
+
"source": source,
|
36 |
+
"target": target,
|
37 |
+
"semantic_sim": round(random.uniform(0.1, 1.0), 2),
|
38 |
+
"causal": random.choice([True, False]),
|
39 |
+
"causal_note": fake.sentence(nb_words=8) if random.random() > 0.5 else None
|
40 |
+
}
|
41 |
+
links.append(link)
|
42 |
+
|
43 |
+
return {"nodes": nodes, "links": links}
|
44 |
+
|
45 |
+
def main(num_nodes=10, num_links=5):
|
46 |
+
data = generate_fake_data(num_nodes, num_links)
|
47 |
+
return json.dumps(data, indent=2)
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
print(main())
|