annotate service/mqtt_to_rdf/inference/structured_log.py @ 1727:23e6154e6c11

file moves
author drewp@bigasterisk.com
date Tue, 20 Jun 2023 23:26:24 -0700
parents service/mqtt_to_rdf/structured_log.py@73abfd4cf5d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1694
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
1 import re
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
2 from pathlib import Path
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
3 from typing import List, Optional, Union, cast
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
4
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
5 import simple_html.render
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
6 from rdflib import Graph
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
7 from rdflib.term import Node
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
8 from simple_html.nodes import (SafeString, body, div, head, hr, html, span,
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
9 style, table, td, tr)
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
10
1727
23e6154e6c11 file moves
drewp@bigasterisk.com
parents: 1694
diff changeset
11 from inference.candidate_binding import CandidateBinding
23e6154e6c11 file moves
drewp@bigasterisk.com
parents: 1694
diff changeset
12 from inference.inference_types import Triple
23e6154e6c11 file moves
drewp@bigasterisk.com
parents: 1694
diff changeset
13 from inference.stmt_chunk import Chunk, ChunkedGraph
1694
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
14
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
15 CSS = SafeString('''
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
16 @import url('https://fonts.googleapis.com/css2?family=Oxygen+Mono&display=swap');
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
17
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
18 * {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
19 font-family: 'Oxygen Mono', monospace;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
20 font-size: 10px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
21 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
22 .arrow {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
23 font-size: 350%;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
24 vertical-align: middle;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
25 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
26 table {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
27 border-collapse: collapse;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
28 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
29 td {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
30 vertical-align: top;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
31 border: 1px solid gray;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
32 padding: 2px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
33 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
34 .consider.isNew-False {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
35 opacity: .3;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
36 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
37 .iteration {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
38 font-size: 150%;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
39 padding: 20px 0;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
40 background: #c7dec7;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
41 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
42 .timetospin {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
43 font-size: 150%;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
44 margin-top: 20 px ;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
45 padding: 10 px 0;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
46 background: #86a886;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
47 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
48 .looper {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
49 background: #e2e2e2;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
50 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
51 .alignedWorkingSetChunk tr:nth-child(even) {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
52 background: #bddcbd;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
53 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
54 .alignedWorkingSetChunk tr:nth-child(odd) {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
55 background: hsl(120deg 31% 72%);
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
56 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
57 .highlight, .alignedWorkingSetChunk tr.highlight {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
58 background: #ffffd6;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
59 outline: 1px solid #d2d200;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
60 padding: 2px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
61 line-height: 17px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
62 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
63 .node { padding: 0 2px; }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
64 .URIRef { background: #e0b3b3; }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
65 .Literal { background: #eecc95 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
66 .Variable { background: #aaaae8; }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
67 .BNode { background: orange; }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
68 .say {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
69 white-space: pre-wrap;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
70 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
71 .say.now.past.end {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
72 color: #b82c08;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
73 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
74 .say.restarts {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
75 color: #51600f;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
76 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
77 .say.advance.start {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
78 margin-top: 5px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
79 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
80 .say.finished {
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
81 border-bottom: 1px solid gray;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
82 display: inline-block;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
83 margin-bottom: 8px;
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
84 }
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
85 ''')
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
86
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
87
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
88 class StructuredLog:
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
89 workingSet: Graph
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
90
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
91 def __init__(self, output: Path):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
92 self.output = output
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
93 self.steps = []
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
94
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
95 def say(self, line):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
96 classes = ['say'] + [c for c in re.split(r'\s+|\W|(\d+)', line) if c]
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
97 cssList = ' '.join(classes)
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
98 self.steps.append(div.attrs(('class', cssList))(line))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
99
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
100 def startIteration(self, num: int):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
101 self.steps.extend([hr(), div.attrs(('class', 'iteration'))(f"iteration {num}")])
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
102
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
103 def rule(self, workingSet: Graph, i: int, rule):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
104 self.steps.append(htmlGraph('working set', self.workingSet))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
105 self.steps.append(f"try rule {i}")
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
106 self.steps.append(htmlRule(rule))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
107
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
108 def foundBinding(self, bound):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
109 self.steps.append(div('foundBinding', htmlBinding(bound.binding)))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
110
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
111 def looperConsider(self, looper, newBinding, fullBinding, isNew):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
112 self.steps.append(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
113 table.attrs(('class', f'consider isNew-{isNew}'))(tr(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
114 td(htmlChunkLooper(looper, showBindings=False)),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
115 td(div('newBinding', htmlBinding(newBinding))),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
116 td(div('fullBinding', htmlBinding(fullBinding))),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
117 td(f'{isNew=}'),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
118 )))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
119
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
120 def odometer(self, chunkStack):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
121 self.steps.append(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
122 table(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
123 tr(*[
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
124 td(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
125 table.attrs(('class', 'looper'))(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
126 tr(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
127 td(htmlChunkLooper(looper, showBindings=False)), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
128 td(div('newBinding'),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
129 htmlBinding(looper.localBinding()) if not looper.pastEnd() else '(pastEnd)'), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
130 td(div('fullBinding'),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
131 htmlBinding(looper.currentBinding()) if not looper.pastEnd() else ''), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
132 ))) for looper in chunkStack
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
133 ])))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
134
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
135 def render(self):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
136
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
137 with open(self.output, 'w') as out:
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
138 out.write(simple_html.render.render(html(head(style(CSS)), body(div(*self.steps)))))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
139
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
140
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
141 def htmlRule(r):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
142 return table(tr(td(htmlGraph('lhsGraph', r.lhsGraph)), td(htmlGraph('rhsGraph', r.rhsGraph))))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
143
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
144
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
145 def htmlGraph(label: str, g: Graph):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
146 return div(label, table(*[htmlStmtRow(s) for s in sorted(g)]))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
147
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
148
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
149 def htmlStmtRow(s: Triple):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
150 return tr(td(htmlTerm(s[0])), td(htmlTerm(s[1])), td(htmlTerm(s[2])))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
151
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
152
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
153 def htmlTerm(t: Union[Node, List[Node]]):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
154 if isinstance(t, list):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
155 return span('( ', *[htmlTerm(x) for x in t], ')')
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
156 return span.attrs(('class', 'node ' + t.__class__.__name__))(repr(t))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
157
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
158
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
159 def htmlBinding(b: CandidateBinding):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
160 return table(*[tr(td(htmlTerm(k)), td(htmlTerm(v))) for k, v in sorted(b.binding.items())])
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
161
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
162
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
163 def htmlChunkLooper(looper, showBindings=True):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
164 alignedMatches = []
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
165 for i, arc in enumerate(looper._alignedMatches):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
166 hi = arc.workingSetChunk == looper.currentSourceChunk
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
167 alignedMatches.append(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
168 tr.attrs(('class', 'highlight' if hi else ''))(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
169 td(span.attrs(('class', 'arrow'))('➢' if hi else ''), str(i)), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
170 td(htmlChunk(arc.workingSetChunk))))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
171 return table(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
172 tr(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
173 td(div(repr(looper)), div(f"prev = {looper.prev}")),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
174 td(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
175 div('lhsChunk'),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
176 htmlChunk(looper.lhsChunk), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
177 div('alignedMatches'),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
178 table.attrs(('class', 'alignedWorkingSetChunk'))(*alignedMatches) #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
179 ),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
180 td('localBinding', htmlBinding(looper.localBinding())) if showBindings else '',
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
181 td('currentBinding', htmlBinding(looper.currentBinding())) if showBindings else '',
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
182 ))
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
183
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
184
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
185 def htmlChunkedGraph(g: ChunkedGraph, highlightChunk: Optional[Chunk] = None):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
186 return table(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
187 tr(td('staticChunks'), td(*[div(htmlChunk(ch, ch == highlightChunk)) for ch in sorted(g.staticChunks)])),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
188 tr(td('patternChunks'), td(*[div(htmlChunk(ch, ch == highlightChunk)) for ch in sorted(g.patternChunks)])),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
189 tr(td('chunksUsedByFuncs'), td(*[div(htmlChunk(ch, ch == highlightChunk)) for ch in sorted(g.chunksUsedByFuncs)])),
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
190 )
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
191
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
192
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
193 def htmlChunk(ch: Chunk, highlight=False):
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
194 return span.attrs(('class', 'highlight' if highlight else ''))(
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
195 'subj=',
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
196 htmlTerm(ch.primary[0] if ch.primary[0] is not None else cast(List[Node], ch.subjList)), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
197 ' pred=',
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
198 htmlTerm(ch.predicate), #
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
199 ' obj=',
73abfd4cf5d0 new html log and other refactoring as i work on the advanceTheStack problems
drewp@bigasterisk.com
parents:
diff changeset
200 htmlTerm(ch.primary[2] if ch.primary[2] is not None else cast(List[Node], ch.objList)))