annotate fca/writeHTML.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents 62d2c72e4223
children
rev   line source
nothing@0 1 def writeHTML(path, matrix, columns, rows):
nothing@0 2 html = "<table border=1><tr><th></th>"
nothing@0 3
nothing@0 4 for it in columns:
nothing@0 5 html += "<th>" + it + "</th>"
nothing@0 6
nothing@0 7 html += "</tr>"
nothing@0 8
nothing@0 9 for i in range(len(rows)):
nothing@0 10 html += "<tr><td>" + rows[i] + "</td>"
nothing@0 11 for j in range(len(columns)):
nothing@0 12 if matrix[i][j] == 1:
nothing@0 13 html += "<td>x</td>"
nothing@0 14 else:
nothing@0 15 html += "<td></td>"
nothing@0 16 html += "</tr>"
nothing@0 17
nothing@0 18 html += "</table>"
nothing@0 19
nothing@0 20 if path != '':
nothing@0 21 file = open(path, 'w')
nothing@0 22 file.write(html)
nothing@0 23 file.close()
nothing@0 24
nothing@0 25 return html
nothing@0 26
nothing@0 27
nothing@0 28 def writeWikiTable(path, matrix, columns, rows):
nothing@0 29 wiki = "{| class='wikitable' \n"
nothing@0 30
nothing@0 31 wiki += ("! align='left'| \n")
nothing@0 32
nothing@0 33 for it in columns:
nothing@0 34 wiki += ("! " + it + "\n")
nothing@0 35
nothing@0 36 for i in range(len(rows)):
nothing@0 37 wiki += "|-\n"
nothing@0 38 wiki += "| align='left'| " + rows[i] + "\n"
nothing@0 39 for j in range(len(columns)):
nothing@0 40 if matrix[i][j] == 1:
nothing@0 41 wiki += "| align='center'| x\n"
nothing@0 42 else:
nothing@0 43 wiki += "| \n"
nothing@0 44
nothing@0 45 wiki += "|}\n"
nothing@0 46
nothing@0 47 if path != '':
nothing@0 48 file = open(path, 'w')
nothing@0 49 file.write(wiki)
nothing@0 50 file.close()
nothing@0 51
nothing@0 52 return wiki
nothing@0 53
nothing@0 54
nothing@0 55 def writeLatexTable(path, matrix, columns, rows):
nothing@0 56 latex = "\\begin{center} \n\\begin{tabular}{ | l |"
nothing@0 57
nothing@0 58 for it in columns:
nothing@0 59 latex += (" l |")
nothing@0 60
nothing@0 61 latex += "}\n\hline\n & "
nothing@0 62
nothing@0 63 for i in range(len(columns)):
nothing@0 64 latex += columns[i]
nothing@0 65 if i < len(columns)-1:
nothing@0 66 latex += " & "
nothing@0 67
nothing@0 68 latex += " \\\ \hline\n"
nothing@0 69
nothing@0 70 for i in range(len(rows)):
nothing@0 71 latex += rows[i].replace("_", "") + " & "
nothing@0 72 for j in range(len(columns)):
nothing@0 73 if matrix[i][j] == 1:
nothing@0 74 latex += "x"
nothing@0 75 else:
nothing@0 76 latex += " "
nothing@0 77 if j < len(columns)-1:
nothing@0 78 latex += " & "
nothing@0 79
nothing@0 80 latex += " \\\ \hline\n"
nothing@0 81
nothing@0 82 latex += "\end{tabular}\n\end{center}"
nothing@0 83
nothing@0 84 if path != '':
nothing@0 85 file = open(path, 'w')
nothing@0 86 file.write(latex)
nothing@0 87 file.close()
nothing@0 88
nothing@0 89 return latex
nothing@0 90
nothing@0 91
nothing@0 92 def writeCXT( path, matrix, cols, rows ):
nothing@0 93 cxt = "B\n\n" + str(len(rows)) + "\n" + str(len(cols)) + "\n\n"
nothing@0 94
nothing@0 95 for it in rows:
nothing@0 96 cxt += it + "\n"
nothing@0 97
nothing@0 98 for it in cols:
nothing@0 99 cxt += it + "\n"
nothing@0 100
nothing@0 101 for i in range(len(rows)):
nothing@0 102 for j in range(len(cols)):
nothing@0 103 if matrix[i][j] == 1:
nothing@0 104 cxt += "X"
nothing@0 105 else:
nothing@0 106 cxt += "."
nothing@0 107 cxt += "\n"
nothing@0 108
nothing@0 109 if path != '':
nothing@0 110 file = open(path, 'w')
nothing@0 111 file.write(cxt)
nothing@0 112 file.close()
nothing@0 113
nothing@0 114 return cxt
nothing@0 115
nothing@0 116 def writeFIMI( path, matrix, cols, rows ):
nothing@0 117
nothing@0 118 fimi = ""
nothing@0 119
nothing@0 120 for i in range(len(rows)):
nothing@0 121 for j in range(len(cols)):
nothing@0 122 if matrix[i][j] == 1:
nothing@0 123 fimi += str(j)+" "
nothing@0 124 fimi += "\n"
nothing@0 125
nothing@0 126 if path != '':
nothing@0 127 file = open(path, 'w')
nothing@0 128 file.write(fimi)
nothing@0 129 file.close()
nothing@0 130
nothing@0 131 return fimi