-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhtml.lisp
81 lines (70 loc) · 1.99 KB
/
html.lisp
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
;;;; HTML output
;;;; File for HTML outputs of objects in CL-CONLLU
;;; Usage overview:
;;
;; (format-html confusion-matrix)
(in-package :conllu.html)
(defparameter *confusion-matrix-style*
"table, th, td {border: 1px solid black;border-collapse: collapse;padding: 5px;}
th, td {text-align: center;}
tr:first-child {color:blue; font-weight: bold;}
td:first-child { color:red; font-weight: bold;}
p {margin:0px;}
html * {font-family: Helvetica;}
table {overflow: hidden;}
tr:hover {background-color: #ffa;}
td, th {position: relative;}
td:hover::after,th:hover::after
{
content: \"\";
position: absolute;
background-color: #ffa;
left: 0;
top: -5000px;
height: 10000px;
width: 100%;
z-index: -1;
}"
"HTML for styling the confusion matrix.")
(defgeneric format-html (object)
(:documentation "Outputs a HTML string for the object."))
;;; for confusion matrices
(defun write-columns-headers (column-labels)
"Auxiliary function for format-html for confusion-matrix."
(mapcar
(lambda (col)
(cl-markup:markup
(:td
col)))
column-labels))
(defun write-rows (row-labels column-labels cm)
"Auxiliary function for format-html for the confusion-matrix CM."
(mapcar
(lambda (row)
(cl-markup:markup
(:tr
(:td row)
(mapcar
(lambda (column)
(cl-markup:markup
(:td
(format nil "~a"
(conllu.evaluate:confusion-matrix-cell-count
row column cm
:default-if-undefined t)))))
column-labels))))
row-labels))
(defmethod format-html ((cm conllu.evaluate:confusion-matrix))
(let ((cl-markup:*output-stream* nil)
(columns (conllu.evaluate:confusion-matrix-columns-labels cm))
(style *confusion-matrix-style*))
(cl-markup:html
(:style
style)
(:table
(:tr (:td "")
(write-columns-headers columns))
(write-rows
(conllu.evaluate:confusion-matrix-rows-labels cm)
columns
cm)))))