-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
110 lines (90 loc) · 3.19 KB
/
test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import parser
import squad
import sys
import csv
#https://stackoverflow.com/questions/36610179/how-to-get-the-dependency-tree-with-spacy
#https://www.nltk.org/
# doc=parser.nlp("When did Beyonce start becoming popular?")
# for sentence in doc.sents:
# print(sentence.root)
##Parse Tree
#print(parser.svo_parseTree("When did Beyonce start becoming popular?"))
##Parse Tree Visualized
def run():
for q in range(442):
print(q);
resource=squad.getResource(q,0);
for question in resource:
if(len(question["answers"])>0):
print(question["question"]+" "+question["answers"][0]["text"])
print(parser.svo_parser(question["question"],question["answers"]))
def sample():
file=open('./output/sample.txt','w');
sys.stdout = file;
for q in range(442):
print("<PASSAGE>");
print(squad.getArticle(q,0));
print("</PASSAGE>");
print("<ANSWER>");
resource=squad.getResource(q,0);
for question in resource:
if(len(question["answers"])>0):
print(parser.svo_parser(question["question"],question["answers"])[0])
print("</ANSWER>");
#Generate Summaries for fine-tune dataset
def sampleSummarizer(dataset):
fields = ['text','summary']
rows = []
for q in range(squad.articleCount(dataset)):
print(q)
for r in range(squad.paragraphCount(q,dataset)):
article=squad.getArticle(q,r,dataset)
summary=""
resource=squad.getResource(q,r,dataset);
for question in resource:
if(len(question["answers"])>0):
temp=parser.svo_parser(question["question"],question["answers"])[0]
summary+=" ".join(temp)+". ";
rows.append([article,summary])
#print("\"{}\",\"{}\"".format(repr(article),repr(summary)))
filename = "./output/summarized.csv"
with open(filename, 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
def sampleCSV():
fields = ['text','questions','summary']
rows = []
file=open('./output/sampleCSV.csv','w');
sys.stdout = file;
for q in range(squad.articleCountTest()):
article=squad.getArticleTest(q,0)
summary=""
questions=""
resource=squad.getResourceTest(q,0);
for question in resource:
if(len(question["answers"])>0):
temp=parser.svo_parser(question["question"],question["answers"])[0]
question+=question["question"]
summary+=" ".join(temp)+". ";
rows.append([article,question,summary])
#print("\"{}\",\"{}\"".format(repr(article),repr(summary)))
filename = "summarizedCSV.csv"
with open(filename, 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
def sampleSubjects():
file=open('./output/sampleSubj.txt','w');
sys.stdout = file;
for q in range(442):
print("<PASSAGE>");
print(squad.getArticle(q,0));
print("</PASSAGE>");
print("<ANSWER>");
resource=squad.getResource(q,0);
for question in resource:
if(len(question["answers"])>0):
temp2=parser.svo_parser(question["question"],question["answers"])[0][0]
print(temp2[0]+" "+temp2[1]+" "+temp2[2])
print("</ANSWER>");