Skip to content

Commit a6a1fd0

Browse files
authored
Update graph_analysis.py
make directory if needed
1 parent ab27763 commit a6a1fd0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

GraphReasoning/graph_analysis.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,11 +1589,17 @@ def use_graph_and_reason_over_triples (path_graph, generate,
15891589
from copy import deepcopy
15901590
import numpy as np
15911591

1592+
# Function to create the directory if it doesn't exist
1593+
def ensure_directory_exists(directory):
1594+
if not os.path.exists(directory):
1595+
os.makedirs(directory)
1596+
15921597
def heuristic_path_with_embeddings_with_randomization_waypoints(G, embedding_tokenizer, embedding_model, source, target,
15931598
node_embeddings, top_k=3, second_hop=False,
15941599
data_dir='./', save_files=True, verbatim=False,
15951600
randomness_factor=0.5, num_random_waypoints=3):
15961601

1602+
15971603
"""
15981604
Finds a heuristic-based path between two nodes in a graph, utilizing node embeddings to estimate distances.
15991605
Additionally, introduces randomness and intermediate waypoints to create more diverse paths.
@@ -1680,8 +1686,7 @@ def heuristic_path_with_embeddings_with_randomization_waypoints(G, embedding_tok
16801686
print(path_list_for_vis_string)
16811687
else:
16821688
print("No valid path found.")
1683-
"""
1684-
1689+
"""
16851690
G = deepcopy(G)
16861691

16871692
if verbatim:
@@ -1781,6 +1786,8 @@ def sample_path_with_randomness(source, target, randomness_factor, num_random_wa
17811786
subgraph.add_edge(neighbor, second_hop_neighbor, **G.edges[neighbor, second_hop_neighbor])
17821787

17831788
if save_files:
1789+
ensure_directory_exists(data_dir)
1790+
17841791
time_part = datetime.now().strftime("%Y%m%d_%H%M%S")
17851792
nt = Network('500px', '1000px', notebook=True)
17861793

0 commit comments

Comments
 (0)