@@ -400,6 +400,22 @@ def __init__(self,
400
400
edge_query = edge_query
401
401
)
402
402
403
+ @classmethod
404
+ def from_json (cls , d : dict ) -> 'ASTEdge' :
405
+ out = ASTEdgeForward (
406
+ edge_match = maybe_filter_dict_from_json (d , 'edge_match' ),
407
+ hops = d ['hops' ] if 'hops' in d else None ,
408
+ to_fixed_point = d ['to_fixed_point' ] if 'to_fixed_point' in d else DEFAULT_FIXED_POINT ,
409
+ source_node_match = maybe_filter_dict_from_json (d , 'source_node_match' ),
410
+ destination_node_match = maybe_filter_dict_from_json (d , 'destination_node_match' ),
411
+ source_node_query = d ['source_node_query' ] if 'source_node_query' in d else None ,
412
+ destination_node_query = d ['destination_node_query' ] if 'destination_node_query' in d else None ,
413
+ edge_query = d ['edge_query' ] if 'edge_query' in d else None ,
414
+ name = d ['name' ] if 'name' in d else None
415
+ )
416
+ out .validate ()
417
+ return out
418
+
403
419
e_forward = ASTEdgeForward # noqa: E305
404
420
405
421
class ASTEdgeReverse (ASTEdge ):
@@ -430,6 +446,22 @@ def __init__(self,
430
446
edge_query = edge_query
431
447
)
432
448
449
+ @classmethod
450
+ def from_json (cls , d : dict ) -> 'ASTEdge' :
451
+ out = ASTEdgeReverse (
452
+ edge_match = maybe_filter_dict_from_json (d , 'edge_match' ),
453
+ hops = d ['hops' ] if 'hops' in d else None ,
454
+ to_fixed_point = d ['to_fixed_point' ] if 'to_fixed_point' in d else DEFAULT_FIXED_POINT ,
455
+ source_node_match = maybe_filter_dict_from_json (d , 'source_node_match' ),
456
+ destination_node_match = maybe_filter_dict_from_json (d , 'destination_node_match' ),
457
+ source_node_query = d ['source_node_query' ] if 'source_node_query' in d else None ,
458
+ destination_node_query = d ['destination_node_query' ] if 'destination_node_query' in d else None ,
459
+ edge_query = d ['edge_query' ] if 'edge_query' in d else None ,
460
+ name = d ['name' ] if 'name' in d else None
461
+ )
462
+ out .validate ()
463
+ return out
464
+
433
465
e_reverse = ASTEdgeReverse # noqa: E305
434
466
435
467
class ASTEdgeUndirected (ASTEdge ):
@@ -460,6 +492,22 @@ def __init__(self,
460
492
edge_query = edge_query
461
493
)
462
494
495
+ @classmethod
496
+ def from_json (cls , d : dict ) -> 'ASTEdge' :
497
+ out = ASTEdgeUndirected (
498
+ edge_match = maybe_filter_dict_from_json (d , 'edge_match' ),
499
+ hops = d ['hops' ] if 'hops' in d else None ,
500
+ to_fixed_point = d ['to_fixed_point' ] if 'to_fixed_point' in d else DEFAULT_FIXED_POINT ,
501
+ source_node_match = maybe_filter_dict_from_json (d , 'source_node_match' ),
502
+ destination_node_match = maybe_filter_dict_from_json (d , 'destination_node_match' ),
503
+ source_node_query = d ['source_node_query' ] if 'source_node_query' in d else None ,
504
+ destination_node_query = d ['destination_node_query' ] if 'destination_node_query' in d else None ,
505
+ edge_query = d ['edge_query' ] if 'edge_query' in d else None ,
506
+ name = d ['name' ] if 'name' in d else None
507
+ )
508
+ out .validate ()
509
+ return out
510
+
463
511
e_undirected = ASTEdgeUndirected # noqa: E305
464
512
e = ASTEdgeUndirected # noqa: E305
465
513
@@ -472,7 +520,17 @@ def from_json(o: JSONVal) -> Union[ASTNode, ASTEdge]:
472
520
if o ['type' ] == 'Node' :
473
521
out = ASTNode .from_json (o )
474
522
elif o ['type' ] == 'Edge' :
475
- out = ASTEdge .from_json (o )
523
+ if 'direction' in o :
524
+ if o ['direction' ] == 'forward' :
525
+ out = ASTEdgeForward .from_json (o )
526
+ elif o ['direction' ] == 'reverse' :
527
+ out = ASTEdgeReverse .from_json (o )
528
+ elif o ['direction' ] == 'undirected' :
529
+ out = ASTEdgeUndirected .from_json (o )
530
+ else :
531
+ raise ValueError (f'Edge has unknown direction { o ["direction" ]} ' )
532
+ else :
533
+ raise ValueError ('Edge missing direction' )
476
534
else :
477
535
raise ValueError (f'Unknown type { o ["type" ]} ' )
478
536
return out
0 commit comments