|
import json |
|
from faker import Faker |
|
import random |
|
from datetime import datetime, timedelta |
|
|
|
fake = Faker() |
|
|
|
def generate_fake_data(num_nodes=10, num_links=5): |
|
nodes = [] |
|
links = [] |
|
topics = ["Environment", "Politics", "Technology", "Health", "Economy"] |
|
emotions = ["trust", "joy", "fear", "sadness", "anger", "surprise"] |
|
sentiments = ["positive", "negative", "neutral"] |
|
|
|
|
|
for i in range(1, num_nodes + 1): |
|
node = { |
|
"id": i, |
|
"headline": fake.sentence(nb_words=6), |
|
"topic": random.choice(topics), |
|
"emotion": random.choice(emotions), |
|
"time": (datetime.now() - timedelta(days=random.randint(0, 365))).strftime("%Y-%m-%d"), |
|
"sentiment": random.choice(sentiments) |
|
} |
|
nodes.append(node) |
|
|
|
|
|
for _ in range(num_links): |
|
source = random.randint(1, num_nodes) |
|
target = random.randint(1, num_nodes) |
|
while target == source: |
|
target = random.randint(1, num_nodes) |
|
|
|
link = { |
|
"source": source, |
|
"target": target, |
|
"semantic_sim": round(random.uniform(0.1, 1.0), 2), |
|
"causal": random.choice([True, False]), |
|
"causal_note": fake.sentence(nb_words=8) if random.random() > 0.5 else None |
|
} |
|
links.append(link) |
|
|
|
return {"nodes": nodes, "links": links} |
|
|
|
def main(num_nodes=10, num_links=5): |
|
data = generate_fake_data(num_nodes, num_links) |
|
return json.dumps(data, indent=2) |
|
|
|
if __name__ == "__main__": |
|
print(main()) |