-
Notifications
You must be signed in to change notification settings - Fork 1
/
ILP_Prepare.py
92 lines (72 loc) · 3.29 KB
/
ILP_Prepare.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
import Survey
import postProcess
import json
import fio
import NLTKWrapper
phraseext = ".key" #a list
studentext = ".keys.source" #json
countext = ".dict" #a dictionary
lpext = ".lp"
lpsolext = ".sol"
ngramext = ".ngram.json"
def getNgram(prefix):
#extract the ngram from the phrase
data = {}
phrasefile = prefix+phraseext
lines = fio.ReadFile(phrasefile)
phrases = [line.strip() for line in lines]
#get unigram
for n in [1,2]:
ngrams = []
for phrase in phrases:
grams = NLTKWrapper.getNgram(phrase, n)
ngrams = ngrams + grams
ngrams = list(set(ngrams))
data[n] = ngrams
with open(prefix + ngramext, 'w') as outfile:
json.dump(data, outfile, indent=2)
def ExtractNgram(outdir, np):
sheets = range(0,12)
for i, sheet in enumerate(sheets):
week = i + 1
dir = outdir + str(week) + '/'
for type in ['POI', 'MP', 'LP']:
prefix = dir + type + "." + np
getNgram(prefix)
if __name__ == '__main__':
excelfile = "../../data/2011Spring_norm.xls"
sennadatadir = "../../data/senna/"
#fio.NewPath(sennadatadir)
#Step1: get senna input
#Survey.getStudentResponses4Senna(excelfile, sennadatadir)
#exit(-1)
#Step2: get senna output
#Step3: get phrases
for outdir in [
#"../../data/ILP_Sentence_Supervised_FeatureWeightingAveragePerceptron/",
#"../../data/ILP_Sentence_Supervised_FeatureWeightingAveragePerceptronMC/",
#"../../data/ILP_Sentence_Supervised_FeatureWeighting_MC_LCS/",
#"../../data/oracle/",
#"../../data/ILP_Sentence_Supervised_Oracle/",
#"../../data/ILP1_Sentence_MC_Length/",
#"../../data/output/conceptweighting/"
#"../../data/ILP1_Sentence_Normalization/",
#"../../data/MC/",
#"../../data/ILP1_Sentence_MC_Normalization/",
#"../../data/ILP_Sentence_Supervised_FeatureWeightingAveragePerceptron_Normalization/",
"../../data/ILP1_Sentence_MC/",
#"../../data/ILP_Sentence_Supervised/",
#"../../data/ILP_Sentence_Supervised_FeatureWeighting/",
#"../../data/ILP_Sentence_Supervised_FeatureWeightingMC/",
#"../../data/ILP_Sentence_Supervised_MC/",
]:
fio.NewPath(outdir)
for np in ['sentence']:
postProcess.ExtractNPFromRaw(excelfile, sennadatadir, outdir, method=np, weekrange=range(0,25))
postProcess.ExtractNPSource(excelfile, sennadatadir, outdir, method=np, weekrange=range(0,25))
postProcess.ExtractNPFromRawWithCount(excelfile, sennadatadir, outdir, method=np, weekrange=range(0,25))
#postProcess.ExtractQualityScore(excelfile, sennadatadir, outdir, method=np, weekrange=range(0,12))
#Survey.getStudentResponses4Fei(excelfile, outdir)
#Step4: write TA's reference
Survey.WriteTASummary(excelfile, outdir)
print "done"