@@ -364,6 +364,12 @@ def _mutate_merge_var_helper(vars_):
364364
365365
366366def mutate_merge_var_mix (child ):
367+ """Merges two variables into one.
368+
369+ Considers both node variables and edge variables together.
370+ It is possible to merge an edge and a node too.
371+ Randomly chooses a variable to replace and a variable to merge into.
372+ """
367373 vars_ = child .vars_in_graph
368374 rand_vars , merge_able_vars = _mutate_merge_var_helper (vars_ )
369375
@@ -377,6 +383,12 @@ def mutate_merge_var_mix(child):
377383
378384
379385def mutate_merge_var_sep (child ):
386+ """Merges two variables into one.
387+
388+ Considers the node variables and edge variables separately.
389+ Either merges 2 node variables or 2 edge variable, depending on a random
390+ choice.Randomly chooses a variable to replace and a variable to merge into.
391+ """
380392 node_vars = {n for n in child .nodes if isinstance (n , Variable )}
381393 rand_node_vars , merge_able_node_vars = _mutate_merge_var_helper (node_vars )
382394
@@ -414,6 +426,13 @@ def mutate_del_triple(child):
414426
415427
416428def mutate_expand_node (child , pb_en_out_link ):
429+ """Expands a random node of the pattern by adding a new triple to it.
430+
431+ The variables to be attached to this node, to form a triple, are chosen
432+ randomly.Depending on the probability, makes it an outgoing edge or an
433+ incoming edge.
434+ :return: The modified child, with the added triple.
435+ """
417436 # TODO: can maybe be improved by sparqling
418437 nodes = list (child .nodes )
419438 node = random .choice (nodes )
@@ -427,6 +446,11 @@ def mutate_expand_node(child, pb_en_out_link):
427446
428447
429448def mutate_add_edge (child ):
449+ """Chooses any 2 nodes from the pattern, and adds an edge between them.
450+
451+ The edge is labeled with a new randomly chosen variable.
452+ :return: Modified child, with the new edge
453+ """
430454 # TODO: can maybe be improved by sparqling
431455 nodes = list (child .nodes )
432456 if len (nodes ) < 2 :
@@ -438,6 +462,12 @@ def mutate_add_edge(child):
438462
439463
440464def mutate_increase_dist (child ):
465+ """increases distance between source and target by one hop.
466+
467+ Adds a triple, to either the source var or the target var.
468+ Interchange the new node with source/target variable to increase distance.
469+ :return: The modified child, with the new triple.
470+ """
441471 if not child .complete ():
442472 return child
443473 var_node = gen_random_var ()
@@ -497,6 +527,10 @@ def mutate_fix_var(
497527 sample_n = config .MUTPB_FV_SAMPLE_MAXN ,
498528 limit = config .MUTPB_FV_QUERY_LIMIT ,
499529):
530+ """Chooses a random variable from the pattern(node or edge).
531+
532+ Substitutes it with all possible fixed variables.
533+ """
500534 assert isinstance (child , GraphPattern )
501535 assert isinstance (gtp_scores , GTPScores )
502536
0 commit comments