-
Notifications
You must be signed in to change notification settings - Fork 0
/
makegeph.py
50 lines (40 loc) · 1.75 KB
/
makegeph.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
import csv
from fuzzywuzzy import fuzz
from itertools import combinations
def do():
podcast_list = []
guest_dict = {}
all_guests = set()
with open("rawdata.txt", encoding="utf8") as f:
for line in f:
line = line.strip()
stuff = line.split(';')
podcast_name = stuff[0]
guests = stuff[1].split(', ')
guest_set = set(guests)
all_guests = all_guests.union(guest_set)
podcast_list.append((podcast_name, guest_set))
for guest in guests:
if guest in guest_dict:
guest_dict[guest] = guest_dict[guest].union(
{podcast_name})
else:
guest_dict[guest] = {podcast_name}
with open("guest_nodes.csv", "w", encoding="utf8", newline="") as f:
csvwriter = csv.writer(f)
csvwriter.writerow(["Source", "Target", "Type", "Label"])
for (guest1, guest2) in combinations(all_guests, 2):
for something in guest_dict[guest1].intersection(guest_dict[guest2]):
csvwriter.writerow([guest1, guest2, "undirected", something])
with open("podcast_nodes.csv", "w", encoding="utf8", newline="") as f:
csvwriter = csv.writer(f)
csvwriter.writerow(["Source", "Target", "Type", "Label"])
for (podcast1, podcast2) in combinations(podcast_list, 2):
for guest1 in podcast1[1]:
for guest2 in podcast2[1]:
if guest1 == guest2:
csvwriter.writerow(
[podcast1[0], podcast2[0], "undirected", guest1])
# elif fuzz.ratio(guest1, guest2) > 80:
# print("Suspicious ", guest1, guest2)
do()