diff fca/writeHTML.py @ 0:62d2c72e4223

initial commit
author nothing@tehis.net
date Mon, 25 Feb 2013 14:40:54 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fca/writeHTML.py	Mon Feb 25 14:40:54 2013 +0000
@@ -0,0 +1,131 @@
+def writeHTML(path, matrix, columns, rows):
+    html = "<table border=1><tr><th></th>"
+
+    for it in columns:
+        html += "<th>" + it + "</th>"
+
+    html += "</tr>"
+
+    for i in range(len(rows)):
+        html += "<tr><td>" + rows[i] + "</td>"
+        for j in range(len(columns)):
+            if matrix[i][j] == 1:
+                html += "<td>x</td>"
+            else:
+                html += "<td></td>"
+        html += "</tr>"
+
+    html += "</table>"    
+
+    if path != '':
+        file = open(path, 'w')
+        file.write(html)
+        file.close()    
+
+    return html
+
+
+def writeWikiTable(path, matrix, columns, rows):
+    wiki = "{| class='wikitable' \n"
+    
+    wiki += ("! align='left'| \n")
+
+    for it in columns:
+        wiki += ("! " + it + "\n")
+
+    for i in range(len(rows)):
+        wiki += "|-\n" 
+        wiki += "| align='left'| " + rows[i] + "\n"
+        for j in range(len(columns)):
+            if matrix[i][j] == 1:
+                wiki += "| align='center'| x\n"
+            else:
+                wiki += "| \n"
+
+    wiki += "|}\n"
+
+    if path != '':
+        file = open(path, 'w')
+        file.write(wiki)
+        file.close()    
+
+    return wiki
+
+
+def writeLatexTable(path, matrix, columns, rows):
+    latex = "\\begin{center} \n\\begin{tabular}{ | l |"
+    
+    for it in columns:
+        latex += (" l |")
+
+    latex += "}\n\hline\n & "
+    
+    for i in range(len(columns)):
+        latex += columns[i]
+        if i < len(columns)-1:
+            latex += " & "
+
+    latex += " \\\ \hline\n"
+
+    for i in range(len(rows)):
+        latex += rows[i].replace("_", "") + " & "
+        for j in range(len(columns)):
+            if matrix[i][j] == 1:
+                latex += "x"
+            else:
+                latex += " "
+            if j < len(columns)-1:
+                latex += " & "
+                
+        latex += " \\\ \hline\n"
+
+    latex += "\end{tabular}\n\end{center}"
+
+    if path != '':
+        file = open(path, 'w')
+        file.write(latex)
+        file.close()    
+
+    return latex
+
+
+def writeCXT( path, matrix, cols, rows ):
+    cxt = "B\n\n" + str(len(rows)) + "\n" + str(len(cols)) + "\n\n"
+
+    for it in rows:
+        cxt += it + "\n"
+
+    for it in cols:
+        cxt += it + "\n"
+
+    for i in range(len(rows)):
+        for j in range(len(cols)):
+            if matrix[i][j] == 1:
+                cxt += "X"
+            else:
+                cxt += "."
+        cxt += "\n"
+
+    if path != '':
+        file = open(path, 'w')
+        file.write(cxt)
+        file.close()    
+
+    return cxt
+    
+def writeFIMI( path, matrix, cols, rows ):
+
+    fimi = ""
+
+    for i in range(len(rows)):
+        for j in range(len(cols)):
+            if matrix[i][j] == 1:
+                fimi += str(j)+" "
+        fimi += "\n"
+
+    if path != '':
+        file = open(path, 'w')
+        file.write(fimi)
+        file.close()    
+
+    return fimi
\ No newline at end of file