INF551 HW2
STATS.PY
import sys,copy,json
jFile=json.load(open(sys.argv[1]))
sumOfHow,sumOfHowMany,sumOfHowMuch,sumOfWhat,sumOfWhen,sumOfWhere,sumOfWhich,sumOfWho,sumOfWhom=0,0,0,0,0,0,0,0,0
# index01=0
# while index01<len(jFile['data']):
# for answer in jFile['data'][index]['paragraphs'][]
#
# index01+=1
for cataloge in jFile['data']:
for contextQas in cataloge['paragraphs']:
for qas in contextQas['qas']:
qas['question'].strip()
if qas['question'].startswith('How many') or qas['question'].startswith('how many'):
sumOfHowMany+=1
elif qas['question'].startswith('How much') or qas['question'].startswith('how much'):
sumOfHowMuch+=1
elif qas['question'].startswith('How') or qas['question'].startswith('how'):
sumOfHow+=1
elif qas['question'].startswith('What') or qas['question'].startswith('what'):
sumOfWhat+=1
elif qas['question'].startswith('When') or qas['question'].startswith('when'):
sumOfWhen+=1
elif qas['question'].startswith('Where') or qas['question'].startswith('where'):
sumOfWhere+=1
elif qas['question'].startswith('Which') or qas['question'].startswith('which'):
sumOfWhich+=1
elif qas['question'].startswith('Whom') or qas['question'].startswith('whom'):
sumOfWhom+=1
elif qas['question'].startswith('Who') or qas['question'].startswith('who'):
sumOfWho+=1
output={"how":sumOfHow,"how many":sumOfHowMany,"how much":sumOfHowMuch,"what":sumOfWhat,"when":sumOfWhen,"where":sumOfWhere,"which":sumOfWhich,"who":sumOfWho,"whom":sumOfWhom}
import sys,copy,json
jFile=json.load(open(sys.argv[1]))
sumOfHow,sumOfHowMany,sumOfHowMuch,sumOfWhat,sumOfWhen,sumOfWhere,sumOfWhich,sumOfWho,sumOfWhom=0,0,0,0,0,0,0,0,0
# index01=0
# while index01<len(jFile['data']):
# for answer in jFile['data'][index]['paragraphs'][]
#
# index01+=1
for cataloge in jFile['data']:
for contextQas in cataloge['paragraphs']:
for qas in contextQas['qas']:
qas['question'].strip()
if qas['question'].startswith('How many') or qas['question'].startswith('how many'):
sumOfHowMany+=1
elif qas['question'].startswith('How much') or qas['question'].startswith('how much'):
sumOfHowMuch+=1
elif qas['question'].startswith('How') or qas['question'].startswith('how'):
sumOfHow+=1
elif qas['question'].startswith('What') or qas['question'].startswith('what'):
sumOfWhat+=1
elif qas['question'].startswith('When') or qas['question'].startswith('when'):
sumOfWhen+=1
elif qas['question'].startswith('Where') or qas['question'].startswith('where'):
sumOfWhere+=1
elif qas['question'].startswith('Which') or qas['question'].startswith('which'):
sumOfWhich+=1
elif qas['question'].startswith('Whom') or qas['question'].startswith('whom'):
sumOfWhom+=1
elif qas['question'].startswith('Who') or qas['question'].startswith('who'):
sumOfWho+=1
output={"how":sumOfHow,"how many":sumOfHowMany,"how much":sumOfHowMuch,"what":sumOfWhat,"when":sumOfWhen,"where":sumOfWhere,"which":sumOfWhich,"who":sumOfWho,"whom":sumOfWhom}
评论
发表评论