-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatDocumentation.py
executable file
·167 lines (126 loc) · 6.4 KB
/
formatDocumentation.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from complexity import *
import pymysql
import socket
hostname = socket.gethostname()
#conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='APiCS')
conn = pymysql.connect(host='localhost', port=3307, user='root', passwd='', db='APiCS')
cur = conn.cursor()
parfile = open('/Volumes/Obang/MyDocuments/Saramaccan/Papers/WordStructure/MetricDocumentationPar.tex', 'w')
synfile = open('/Volumes/Obang/MyDocuments/Saramaccan/Papers/WordStructure/MetricDocumentationSyn.tex', 'w')
cur.execute("""SELECT WALSValueInfo.`Feature_number`, APiCSFeatures.`ShortName`, APiCSFeatures.`ComplexityType`, WALSValueInfo.`ValShort`, WALSValueInfo.`Complexity`, WALSValueInfo.`ComplexityDocumentation`
FROM WALSValueInfo
INNER JOIN APiCSFeatures
ON WALSValueInfo.`Feature_number` = APiCSFeatures.`WALS-APiCS`
WHERE WALSValueInfo.Complexity is not NULL
ORDER BY WALSValueInfo.`PureFeatureNumber`""")
# To do multirows for the feature names, collect number of values per feature
# This is inefficient, but I'm lazy
numfeatvals = { }
for row in cur.fetchall():
featid, featname, comptype, valuedesc, compscore, documentation = row
if featname in numfeatvals:
numfeatvals[featname] += 1
else:
numfeatvals[featname] = 1
# Do paradigmatic documentation
cur.execute("""SELECT WALSValueInfo.`Feature_number`, APiCSFeatures.`ShortName`, WALSValueInfo.`ValShort`, WALSValueInfo.`Complexity`, WALSValueInfo.`ShortComplexityDoc`
FROM WALSValueInfo
INNER JOIN APiCSFeatures
ON WALSValueInfo.`Feature_number` = APiCSFeatures.`WALS-APiCS`
WHERE WALSValueInfo.Complexity is not NULL AND APiCSFeatures.`ComplexityType` = 'Paradigmatic'
ORDER BY APiCSFeatures.`ComplexityType`, WALSValueInfo.`PureFeatureNumber`, WALSValueInfo.`Complexity`, WALSValueInfo.`ValShort`""")
print >> parfile, "\\begin{longtable}{lllllll}"
print >> parfile, "\\Hline"
print >> parfile, "{\\sc id}\t&\t{\\sc feature name}\t&\t{\\sc value name}\t&\t{\\sc n}\t&\t{\\sc justification}\\\\"
print >> parfile, "\\Hline"
print >> parfile, "\\endhead"
print >> parfile, "\\caption{Complexity scores assigned to values for the paradigmatic features in the WALS--APiCS data (continued)}\\\\"
print >> parfile, "\\endfoot"
print >> parfile, "\\caption{Complexity scores assigned to values for the paradigmatic features in the WALS--APiCS data \label{ParComp}}\\\\"
print >> parfile, "\\endlastfoot"
oldfeatname = ""
featcount = 0
for row in cur.fetchall():
featid, featname, valuedesc, compscore, documentation = row
featid = featid.replace("WALS ", "")
featid = featid.replace("A", "")
# documentation = documentation.replace("One ", "1 ")
# documentation = documentation.replace("Two ", "2 ")
# documentation = documentation.replace("Three ", "3 ")
# documentation = documentation.replace("Four ", "4 ")
# documentation = documentation.replace("Five ", "5 ")
# documentation = documentation.replace("Six ", "6 ")
#
# documentation = documentation.replace(" one ", " 1 ")
# documentation = documentation.replace(" two ", " 2 ")
# documentation = documentation.replace(" three ", " 3 ")
# documentation = documentation.replace(" four ", " 4 ")
# documentation = documentation.replace(" five ", " 5 ")
# documentation = documentation.replace(" six ", " 6 ")
documentation = documentation.replace("lingueme", "{\\sc lgm}")
documentation = documentation.replace("Lingueme", "{\\sc lgm}")
hline = False
if featname == oldfeatname:
printfeatname = ""
else:
printfeatname = featname
if featcount > 0:
hline = True
oldfeatname = featname
if hline == True:
print >> parfile, "\\hline"
print >> parfile, featid+"\t&\t", "\\multirow{"+str(numfeatvals[featname])+"}{1.25in}{"+printfeatname+"}\t&\t", valuedesc+"\t&\t", str(int(round(compscore,0)))+"\t&\t", documentation+"\t\\\\*"
featcount = featcount + 1
print >> parfile, "\\Hline"
print >> parfile, "\\end{longtable}"
# Do syntagmatic documentation
cur.execute("""SELECT WALSValueInfo.`Feature_number`, APiCSFeatures.`ShortName`, WALSValueInfo.`ValShort`, WALSValueInfo.`Complexity`, WALSValueInfo.`ShortComplexityDoc`
FROM WALSValueInfo
INNER JOIN APiCSFeatures
ON WALSValueInfo.`Feature_number` = APiCSFeatures.`WALS-APiCS`
WHERE WALSValueInfo.Complexity is not NULL AND APiCSFeatures.`ComplexityType` = 'Syntagmatic'
ORDER BY APiCSFeatures.`ComplexityType`, WALSValueInfo.`PureFeatureNumber`, WALSValueInfo.`Complexity`, WALSValueInfo.`ValShort`""")
print >> synfile, "\\begin{longtable}{lllllll}"
print >> synfile, "\\Hline"
print >> synfile, "{\\sc id}\t&\t{\\sc feature name}\t&\t{\\sc value name}\t&\t{\\sc n}\t&\t{\\sc justification}\\\\"
print >> synfile, "\\Hline"
print >> synfile, "\\endhead"
print >> synfile, "\\caption{Complexity scores assigned to values for the syntagmatic features in the WALS--APiCS data (continued)}\\\\"
print >> synfile, "\\endfoot"
print >> synfile, "\\caption{Complexity scores assigned to values for the syntagmatic features in the WALS--APiCS data \label{SynComp}}\\\\"
print >> synfile, "\\endlastfoot"
oldfeatname = ""
featcount = 0
for row in cur.fetchall():
featid, featname, valuedesc, compscore, documentation = row
featid = featid.replace("WALS ", "")
featid = featid.replace("A", "")
# documentation = documentation.replace("One ", "1 ")
# documentation = documentation.replace("Two ", "2 ")
# documentation = documentation.replace("Three ", "3 ")
# documentation = documentation.replace("Four ", "4 ")
# documentation = documentation.replace("Five ", "5 ")
# documentation = documentation.replace("Six ", "6 ")
#
# documentation = documentation.replace(" one ", " 1 ")
# documentation = documentation.replace(" two ", " 2 ")
# documentation = documentation.replace(" three ", " 3 ")
# documentation = documentation.replace(" four ", " 4 ")
# documentation = documentation.replace(" five ", " 5 ")
# documentation = documentation.replace(" six ", " 6 ")
documentation = documentation.replace("lingueme", "{\\sc lgm}")
documentation = documentation.replace("Lingueme", "{\\sc lgm}")
hline = False
if featname == oldfeatname:
printfeatname = ""
else:
printfeatname = featname
if featcount > 0:
hline = True
oldfeatname = featname
if hline == True:
print >> synfile, "\\hline"
print >> synfile, featid+"\t&\t", "\\multirow{"+str(numfeatvals[featname])+"}{1.25in}{"+printfeatname+"}\t&\t", valuedesc+"\t&\t", str(int(round(compscore,0)))+"\t&\t", documentation+"\t\\\\*"
featcount = featcount + 1
print >> synfile, "\\Hline"
print >> synfile, "\\end{longtable}"