-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNodes
More file actions
46 lines (40 loc) · 1.5 KB
/
Nodes
File metadata and controls
46 lines (40 loc) · 1.5 KB
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
#this generates nodes for the socialnetwork graph
import csv
from nltk.tag import pos_tag
#creates word pairs csv by cooccurence by verse
with open("kingjames.tsv") as tsvfile, open("nodes.csv",'wb') as f:
biblebychapter = list()
for line in tsvfile:
line = line.strip('\n')
line = line.split('\t')
propernouns = list()
text = pos_tag(line[3].split())
for tup in text:
if tup[1] == 'NNP':
propernouns.append(tup[0].strip(",;.:)?'"))
unique = set(propernouns)
if len(list(unique)) > 1:
biblebychapter.append((line[0],line[1],line[2],list(unique)))
wordpairs = list()
uniquewords = set()
for verse in biblebychapter:
uniquepairs = set()
for word1 in verse[3]:
uniquewords.add(word1)
for word2 in verse[3]:
uniquewords.add(word2)
if word1 != word2:
plist =sorted([word1, word2])
pair = tuple(plist)
uniquepairs.add(pair)
versenum = verse[0] + " " + verse[1] + ":" + verse[2]
for pair in uniquepairs:
wordpairs.append([pair[0],pair[1],versenum])
writer = csv.writer(f)
wordlist = list(uniquewords)
listoflists = list()
for word in wordlist:
listoflists.append([word])
for word in listoflists:
writer.writerows([word])
print(listoflists)