MCPcopy Create free account
hub / github.com/LHRLAB/ChatKBQA / none_function

Function none_function

executor/logic_form_util.py:279–360  ·  view source on GitHub ↗
(G, start, arg_node=None, type_constraint=True)

Source from the content-addressed store, hash-verified

277
278
279def none_function(G, start, arg_node=None, type_constraint=True):
280 if arg_node is not None:
281 arg = G.nodes[arg_node]['function']
282 path = list(nx.all_simple_paths(G, start, arg_node))
283 assert len(path) == 1
284 arg_clause = []
285 for i in range(0, len(path[0]) - 1):
286 edge = G.edges[path[0][i], path[0][i + 1], 0]
287 if edge['reverse']:
288 relation = '(R ' + edge['relation'] + ')'
289 else:
290 relation = edge['relation']
291 arg_clause.append(relation)
292
293 # Deleting edges until the first node with out degree > 2 is meet
294 # (conceptually it should be 1, but remember that add edges is both directions)
295 while i >= 0:
296 flag = False
297 if G.out_degree[path[0][i]] > 2:
298 flag = True
299 G.remove_edge(path[0][i], path[0][i + 1], 0)
300 i -= 1
301 if flag:
302 break
303
304 if len(arg_clause) > 1:
305 arg_clause = binary_nesting(function='JOIN', elements=arg_clause)
306 # arg_clause = ' '.join(arg_clause)
307 else:
308 arg_clause = arg_clause[0]
309
310 return '(' + arg.upper() + ' ' + none_function(G, start) + ' ' + arg_clause + ')'
311
312 # arg = -1
313 # for nei in G[start]:
314 # if G.nodes[nei]['function'].__contains__('arg'):
315 # arg = nei
316 # arg_function = G.nodes[nei]['function']
317 # if arg != -1:
318 # edge = G.edges[start, arg, 0]
319 # if edge['reverse']:
320 # relation = '(R ' + edge['relation'] + ')'
321 # else:
322 # relation = edge['relation']
323 # G.remove_edge(start, arg, 0)
324 # return '(' + arg_function.upper() + ' ' + none_function(G, start) + ' ' + relation + ')'
325
326 if G.nodes[start]['type'] != 'class':
327 return G.nodes[start]['id']
328
329 end_num = get_end_num(G, start)
330 clauses = []
331
332 if G.nodes[start]['question'] and type_constraint:
333 clauses.append(G.nodes[start]['id'])
334 for key in end_num.keys():
335 for i in range(0, end_num[key]):
336 if not G.edges[start, key, i]['visited']:

Callers 3

graph_to_logical_formFunction · 0.70
count_functionFunction · 0.70

Calls 3

binary_nestingFunction · 0.70
get_end_numFunction · 0.70
set_visitedFunction · 0.70

Tested by

no test coverage detected