Skip to content

Commit 2836402

Browse files
committed
Added code to write corpus as a table
1 parent 1b6d755 commit 2836402

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

QCPAnalysis/src/QCPAnalysis/QCPCorpus.rsc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ private Corpus newCorpus = (
2828
"web2project" : "3.3"
2929
);
3030

31+
public str getSensibleName("faqforge") = "FAQ Forge";
32+
public str getSensibleName("firesoftboard") = "Fire-Soft-Board";
33+
public default str getSensibleName(str p) = p;
34+
3135
private Corpus corpus = originalCorpus + newCorpus;
3236

3337

QCPAnalysis/src/QCPAnalysis/WriteResults.rsc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import QCPAnalysis::QueryStringAnalysis;
1010

1111
import lang::php::ast::AbstractSyntax;
1212
import lang::php::util::Corpus;
13+
import lang::php::util::Utils;
1314

1415
import IO;
16+
import List;
17+
import String;
1518

1619
loc lists = |project://QCPAnalysis/results/lists/|;
1720
loc counts = |project://QCPAnalysis/results/counts/|;
@@ -51,4 +54,45 @@ public void writeQG(){
5154

5255
public void writeQueryStrings(){
5356
iprintToFile(strings, {q | q <- buildAndClassifyQueryStrings(), q.flags.qcp5 == true});
57+
}
58+
59+
public str corpusAsLatexTable() {
60+
Corpus corpus = getCorpus();
61+
corpusCounts = getSortedCountsCaseInsensitive();
62+
pForSort = [ < toUpperCase(p), p > | p <- corpus ];
63+
pForSort = sort(pForSort, bool(tuple[str,str] t1, tuple[str,str] t2) { return t1[0] < t2[0]; });
64+
65+
str getLine(str p, str v) = "<getSensibleName(p)> & <v> & <getOneFrom(corpusCounts[p,v]<1>)> & <getOneFrom(corpusCounts[p,v]<0>)>";
66+
str res =
67+
"\\npaddmissingzero
68+
'\\npfourdigitsep
69+
'\\begin{table}
70+
'\\centering
71+
'\\caption{The Corpus.\\label{tbl:php-corpus}}
72+
'\\ra{1.2}
73+
'\\begin{tabularx}{\\columnwidth}{Xrrr} \\toprule
74+
'System & Version & File Count & SLOC \\\\ \\midrule
75+
'<for(<_,p> <- pForSort, v := corpus[p]){><getLine(p,v)> \\\\
76+
'<}>
77+
'\\bottomrule
78+
'\\end{tabularx}
79+
'\\end{table}
80+
'\\npfourdigitnosep
81+
'\\npnoaddmissingzero
82+
";
83+
return res;
84+
}
85+
86+
public int totalCorpusFiles() {
87+
Corpus corpus = getCorpus();
88+
corpusCounts = { < p, v, lc, fc > | < p, v, lc, fc > <- getSortedCounts(), p in corpus<0>, v := corpus[p] };
89+
corpusFileCounts = corpusCounts<3>;
90+
return ( 0 | it + fc | fc <- corpusFileCounts );
91+
}
92+
93+
public int totalCorpusLines() {
94+
Corpus corpus = getCorpus();
95+
corpusCounts = { < p, v, lc, fc > | < p, v, lc, fc > <- getSortedCounts(), p in corpus<0>, v := corpus[p] };
96+
corpusLineCounts = corpusCounts<2>;
97+
return ( 0 | it + fc | fc <- corpusLineCounts );
5498
}

0 commit comments

Comments
 (0)