(G, start, arg_node=None, type_constraint=True)
| 326 | |
| 327 | |
| 328 | def none_function(G, start, arg_node=None, type_constraint=True): # type_constraint is false for WebQSP |
| 329 | if arg_node is not None: |
| 330 | arg = G.nodes[arg_node]['function'] |
| 331 | path = list(nx.all_simple_paths(G, start, arg_node)) |
| 332 | assert len(path) == 1 |
| 333 | arg_clause = [] |
| 334 | for i in range(0, len(path[0]) - 1): |
| 335 | edge = G.edges[path[0][i], path[0][i + 1], 0] |
| 336 | if edge['reverse']: |
| 337 | relation = '(R ' + edge['relation'] + ')' |
| 338 | else: |
| 339 | relation = edge['relation'] |
| 340 | arg_clause.append(relation) |
| 341 | |
| 342 | # Deleting edges until the first node with out degree > 2 is meet |
| 343 | # (conceptually it should be 1, but remember that add edges is both directions) |
| 344 | while i >= 0: |
| 345 | flag = False |
| 346 | if G.out_degree[path[0][i]] > 2: |
| 347 | flag = True |
| 348 | G.remove_edge(path[0][i], path[0][i + 1], 0) |
| 349 | i -= 1 |
| 350 | if flag: |
| 351 | break |
| 352 | |
| 353 | if len(arg_clause) > 1: |
| 354 | arg_clause = binary_nesting(function='JOIN', elements=arg_clause) |
| 355 | # arg_clause = ' '.join(arg_clause) |
| 356 | else: |
| 357 | arg_clause = arg_clause[0] |
| 358 | |
| 359 | return '(' + arg.upper() + ' ' + none_function(G, start) + ' ' + arg_clause + ')' |
| 360 | |
| 361 | # arg = -1 |
| 362 | # for nei in G[start]: |
| 363 | # if G.nodes[nei]['function'].__contains__('arg'): |
| 364 | # arg = nei |
| 365 | # arg_function = G.nodes[nei]['function'] |
| 366 | # if arg != -1: |
| 367 | # edge = G.edges[start, arg, 0] |
| 368 | # if edge['reverse']: |
| 369 | # relation = '(R ' + edge['relation'] + ')' |
| 370 | # else: |
| 371 | # relation = edge['relation'] |
| 372 | # G.remove_edge(start, arg, 0) |
| 373 | # return '(' + arg_function.upper() + ' ' + none_function(G, start) + ' ' + relation + ')' |
| 374 | |
| 375 | if G.nodes[start]['type'] != 'class': |
| 376 | return G.nodes[start]['id'] |
| 377 | |
| 378 | end_num = get_end_num(G, start) |
| 379 | clauses = [] |
| 380 | |
| 381 | if G.nodes[start]['question'] and type_constraint: |
| 382 | clauses.append(G.nodes[start]['id']) |
| 383 | for key in end_num.keys(): |
| 384 | for i in range(0, end_num[key]): |
| 385 | if not G.edges[start, key, i]['visited']: |
no test coverage detected