Skip to content

Commit a3c2b97

Browse files
committed
NestedCall is no longer WithBlock, RDFNode base class added
1 parent 7fef018 commit a3c2b97

File tree

8 files changed

+78
-96
lines changed

8 files changed

+78
-96
lines changed

examples/notebooks/conditional-join-w-cmp.ipynb

Lines changed: 17 additions & 59 deletions
Large diffs are not rendered by default.

pyjviz/nested_call.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import ipdb
22
import sys, contextlib
3-
from . import wb_stack
43
from . import obj_tracking
54
from . import obj_utils
5+
from . import wb_stack
66
from . import fstriplestore
7+
from . import rdf_node
78

89
class profile_objs:
910
def __init__(self):
@@ -40,7 +41,7 @@ def dump_nested_call_refs(self, nested_call_uri):
4041
if ref_obj_state_uri:
4142
ts.dump_triple(nested_call_uri, "<nested-call-ref>", ref_obj_state_uri)
4243

43-
class NestedCall(wb_stack.WithBlock):
44+
class NestedCall(rdf_node.RDFNode):
4445
"""
4546
NestedCall object is to represent situation like this:
4647
```python
@@ -59,7 +60,11 @@ class NestedCall(wb_stack.WithBlock):
5960
The code then proceed and causes controlled call of `nested_call_func` via __call__ implementation. Results are saved as self.ret and later used by MethodCall.handle_end_method_call
6061
"""
6162
def __init__(self, arg_name, arg_func):
62-
super().__init__(label = f"nested_call({arg_name})", rdf_type = "NestedCall")
63+
super().__init__(rdf_type = "NestedCall", label = f"nested_call({arg_name})")
64+
rdfl = fstriplestore.triple_store
65+
parent_uri = wb_stack.wb_stack.stack_entries__[-1].uri
66+
rdfl.dump_triple(self.uri, "<part-of>", parent_uri)
67+
6368
#ipdb.set_trace()
6469
self.arg_name = arg_name
6570
self.arg_func = arg_func

pyjviz/obj_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def dump_Series_obj_state_cc(obj_state_uri, s, output_type):
7171
if output_type == 'head':
7272
ts.dump_triple(obj_state_cc_uri, "rdf:type", "<CCGlance>")
7373
ts.dump_triple(obj_state_cc_uri, "<shape>", f"{len(s)}")
74+
ts.dump_triple(obj_state_cc_uri, "<df-head>", '"NONE"')
7475
elif output_type == 'plot':
7576
ts.dump_triple(obj_state_cc_uri, "rdf:type", "<CCBasicPlot>")
7677
ts.dump_triple(obj_state_cc_uri, "<shape>", f"{len(s)}")

pyjviz/rdf_node.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import uuid
2+
3+
from . import fstriplestore
4+
5+
class RDFNode:
6+
def __init__(self, rdf_type, label):
7+
self.label = label
8+
self.rdf_type = rdf_type
9+
self.uri = f"<{self.rdf_type}#{str(uuid.uuid4())}>"
10+
11+
rdfl = fstriplestore.triple_store
12+
rdf_type_uri = f"<{self.rdf_type}>"
13+
rdfl.dump_triple(self.uri, "rdf:type", rdf_type_uri)
14+
label_obj = f'"{self.label}"' if self.label else 'rdf:nil'
15+
rdfl.dump_triple(self.uri, "rdf:label", label_obj)
16+

pyjviz/viz.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def dump_subgraph(g, cc_uri, out_fd, popup_output):
105105
node_bgcolor = "#88000022"
106106
href = make_table_popup_href(head, popup_output)
107107
elif obj_type.toPython() == "Series":
108-
glance_rq = "select ?shape { ?obj_state_cc <obj-state> ?obj_state; rdf:type ?target_cc_type; <shape> ?shape }"
109-
for shape in g.query(glance_rq, base = fstriplestore.base_uri, initBindings = bindings):
110-
shape = shape[0]
108+
glance_rq = "select ?shape ?head { ?obj_state_cc <obj-state> ?obj_state; rdf:type ?target_cc_type; <shape> ?shape; <df-head> ?head }"
109+
for shape, head in g.query(glance_rq, base = fstriplestore.base_uri, initBindings = bindings):
110+
shape = shape
111111
node_bgcolor = "#88000022"
112-
href = make_table_popup_href(None, popup_output)
112+
href = make_table_popup_href(head, popup_output)
113113
else:
114114
raise Exception(f"unknown obj_type {obj_type}")
115115
elif target_cc_type == cc_basic_plot_uri:
@@ -307,7 +307,7 @@ def print_dot(vertical = False, show_objects = False):
307307
g = fstriplestore.triple_store.get_graph()
308308
print(dump_dot_code(g, vertical = vertical, show_objects = show_objects))
309309

310-
def save_dot(dot_output_fn = None, vertical = False, show_objects = False, popup_output = False):
310+
def save_dot(dot_output_fn = None, vertical = False, show_objects = False, popup_output = True):
311311
ts = fstriplestore.triple_store
312312
if dot_output_fn is None:
313313
if hasattr(ts, 'output_fn') and ts.output_fn is not None:
@@ -327,5 +327,5 @@ def show(vertical = False, show_objects = False):
327327
raise Exception("triple sink is not in-memory file")
328328

329329
g = ts.get_graph()
330-
dot_code = dump_dot_code(g, vertical = vertical, show_objects = show_objects)
330+
dot_code = dump_dot_code(g, vertical = vertical, show_objects = show_objects, popup_output = False)
331331
nb_utils.show_method_chain(dot_code)

pyjviz/wb_stack.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import uuid
2-
31
from . import fstriplestore
2+
from . import rdf_node
43

5-
class WithBlock:
4+
class WithBlock(rdf_node.RDFNode):
65
"""
76
Code blocks in python - https://docs.python.org/3/reference/executionmodel.html#:~:text=A%20Python%20program%20is%20constructed,typed%20interactively%20is%20a%20block.
87
With PEP use of 'block' - https://peps.python.org/pep-0343/#specification-the-with-statement
@@ -11,23 +10,12 @@ class WithBlock:
1110
- uri - to identify itself in graph as node
1211
- rdf_type_uri - to identify node type
1312
"""
14-
def __init__(self, *, label, rdf_type):
15-
self.label = label
16-
self.rdf_type = rdf_type
17-
self.uri = None
18-
self.init_dump__()
19-
20-
def init_dump__(self):
13+
def __init__(self, *, rdf_type, label):
14+
super().__init__(rdf_type, label)
2115
rdfl = fstriplestore.triple_store
22-
self.uri = f"<{self.rdf_type}#{str(uuid.uuid4())}>"
23-
rdf_type_uri = f"<{self.rdf_type}>"
24-
rdfl.dump_triple(self.uri, "rdf:type", rdf_type_uri)
25-
label_obj = f'"{self.label}"' if self.label else 'rdf:nil'
26-
rdfl.dump_triple(self.uri, "rdf:label", label_obj)
2716
global wb_stack
2817
parent_uri = wb_stack.stack_entries__[-1].uri if wb_stack.size() > 0 else "rdf:nil"
2918
rdfl.dump_triple(self.uri, "<part-of>", parent_uri)
30-
self.dump_init_called = True
3119

3220
def __enter__(self):
3321
global wb_stack

pyjviz/wb_stack_entries.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@
1313
from .nested_call import NestedCall
1414

1515
class CodeBlock(wb_stack.WithBlock):
16-
def __init__(self, label = None, rdf_type = "CodeBlock"):
17-
super().__init__(label = label, rdf_type = rdf_type)
16+
def __init__(self, label = None):
17+
super().__init__(rdf_type = "CodeBlock", label = label)
1818

1919
CB = CodeBlock
2020

21-
method_counter = 0 # NB: should be better way to cout method calls
21+
method_counter = 0 # NB: should be better way to count method calls
2222
class MethodCall(wb_stack.WithBlock):
23-
def __init__(self, method_name, pyjviz_opts = {}):
24-
super().__init__(label = method_name, rdf_type = "MethodCall")
23+
def __init__(self, method_name):
24+
super().__init__(rdf_type = "MethodCall", label = method_name)
2525
self.method_name = method_name
2626
self.method_bound_args = None
2727
self.nested_call_args = []
28-
self.pyjviz_opts = pyjviz_opts
2928

3029
def handle_start_method_call(self, method_name, method_signature, method_args, method_kwargs):
3130
if method_name == 'pin':

rdflog.shacl.ttl

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
@prefix dash: <http://datashapes.org/dash#> .
99

1010
<WithBlock> rdf:type rdfs:Class; rdf:type sh:NodeShape; dash:closedByType true;
11-
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
12-
sh:property [sh:path rdf:label; sh:minCount 1; sh:maxCount 1];
11+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1; sh:class <WithBlock>];
12+
sh:property [sh:path rdf:label; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
1313
sh:property [sh:path <part-of>; sh:minCount 1; sh:maxCount 1; sh:or ([sh:class <WithBlock>] [sh:node rdf:nil])].
1414

1515
<CodeBlock> rdf:type rdfs:Class; rdfs:subClassOf <WithBlock>; rdf:type sh:NodeShape; dash:closedByType true.
@@ -25,22 +25,37 @@
2525
sh:property [sh:path <method-call-arg2>; sh:minCount 0; sh:maxCount 1; sh:class <ObjState>];
2626
sh:property [sh:path <method-call-return>; sh:minCount 1; sh:maxCount 1; sh:class <ObjState>].
2727

28-
<NestedCall> rdf:type rdfs:Class; rdfs:subClassOf <WithBlock>; rdf:type sh:NodeShape; dash:closedByType true;
28+
<NestedCall> rdf:type rdfs:Class; rdf:type sh:NodeShape; sh:closed true;
2929
sh:property [sh:path <ret-val>; sh:minCount 1; sh:maxCount 1; sh:class <ObjState>].
3030

3131
<Obj> rdf:type rdfs:Class; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
32-
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
32+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1; sh:class <Obj>];
3333
sh:property [sh:path <obj-type>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
3434
sh:property [sh:path <obj-uuid>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
3535
sh:property [sh:path <obj-pyid>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:integer].
3636

3737
<ObjState> rdf:type rdfs:Class; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
38-
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
38+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1; sh:class <ObjState>];
3939
sh:property [sh:path <part-of>; sh:minCount 1; sh:maxCount 1; sh:class <WithBlock>];
4040
sh:property [sh:path <obj>; sh:minCount 1; sh:maxCount 1; sh:class <Obj>];
4141
sh:property [sh:path <version>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
4242
sh:property [sh:path <df-shape>; sh:minCount 1; sh:maxCount: 1; sh:datatype xsd:string];
4343
sh:property [sh:path <df-head>; sh:minCount 0; sh:maxCount: 1; ; sh:datatype xsd:string].
44-
4544

45+
<ObjStateCC> rdf:type rdfs:Class; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
46+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1; sh:class <ObjStateCC>];
47+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1; sh:class <CC>];
4648

49+
<CC> rdf:type rdfs:Class; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
50+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
51+
52+
<CCGlance> rdf:type rdfs:Class; rdfs:subClassOf <CC>; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
53+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
54+
sh:property [sh:path <shape>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
55+
sh:property [sh:path <head>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
56+
57+
<CCBasicPlot> rdf:type rdfs:Class; rdfs:subClassOf <CC>; rdf:type sh:NodeShape; sh:closed true; dash:closedByType true;
58+
sh:property [sh:path rdf:type; sh:minCount 1; sh:maxCount 1];
59+
sh:property [sh:path <shape>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
60+
sh:property [sh:path <plot-im>; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string];
61+

0 commit comments

Comments
 (0)