@@ -723,35 +723,61 @@ def _mutate_deep_narrow_path_helper(
723
723
children = [
724
724
c if fit_to_live (c ) else orig_child
725
725
for c in children
726
- ]
726
+ ]
727
727
if children :
728
728
child = random .choice (list (children ))
729
729
return child , fixed
730
730
731
731
732
732
def mutate_deep_narrow_path (
733
733
child , sparql , timeout , gtp_scores ,
734
+ _rec_depth = 0 ,
735
+ start_node = None ,
734
736
min_len = config .MUTPB_DN_MIN_LEN ,
735
737
max_len = config .MUTPB_DN_MAX_LEN ,
736
738
term_pb = config .MUTPB_DN_TERM_PB ,
739
+ recursion_look_ahead = config .MUTPB_DN_LOOK_AHEAD_LIMIT ,
740
+ rec_limit = config .MUTPB_DN_RECURSION_LIMIT ,
737
741
):
738
742
assert isinstance (child , GraphPattern )
739
743
nodes = list (child .nodes )
740
- start_node = random .choice (nodes )
741
- # target_nodes = set(nodes) - {start_node}
744
+ if start_node is None :
745
+ start_node = random .choice (nodes )
746
+ fixed_for_start_node = start_node
747
+ fixed_gp = child
742
748
gp = child
743
749
hop = 0
750
+ false_fixed_count = 0
744
751
while True :
745
752
if hop >= min_len and random .random () < term_pb :
746
753
break
747
754
if hop >= max_len :
748
755
break
749
756
hop += 1
750
757
new_triple , var_node , var_edge = _mutate_expand_node_helper (start_node )
758
+ orig_gp = gp
751
759
gp += [new_triple ]
752
760
gp , fixed = _mutate_deep_narrow_path_helper (
753
761
sparql , timeout , gtp_scores , gp , var_edge , var_node )
754
- start_node = var_node
762
+ if fixed :
763
+ fixed_for_start_node = start_node
764
+ fixed_gp = orig_gp
765
+ false_fixed_count = 0
766
+ start_node = var_node
767
+ if not fixed :
768
+ false_fixed_count += 1
769
+ if false_fixed_count > recursion_look_ahead :
770
+ _rec_depth += 1
771
+ if _rec_depth > rec_limit :
772
+ return gp
773
+ start_node = fixed_for_start_node
774
+ gp = mutate_deep_narrow_path (
775
+ fixed_gp , sparql , timeout , gtp_scores ,
776
+ _rec_depth ,
777
+ start_node = start_node
778
+ )
779
+ return gp
780
+ start_node = var_node
755
781
return gp
756
782
757
783
0 commit comments