Skip to content

Commit

Permalink
Update networkx_graph.py
Browse files Browse the repository at this point in the history
added support for pickle networkx graph import
  • Loading branch information
benx13 authored Oct 3, 2024
1 parent 907c758 commit 0b1370b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libs/community/langchain_community/graphs/networkx_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,19 @@ def from_gml(cls, gml_path: str) -> NetworkxEntityGraph:
)
graph = nx.read_gml(gml_path)
return cls(graph)


@classmethod
def from_pickle(cls, pickle_path: str) -> NetworkxEntityGraph:
try:
import pickle
except ImportError:
raise ImportError(
"Could not import pickle python package. "
"Please install it with `pip install pickle`."
)
graph = pickle.load(open(pickle_path, 'rb'))
return cls(graph)

def add_triple(self, knowledge_triple: KnowledgeTriple) -> None:
"""Add a triple to the graph."""
# Creates nodes if they don't exist
Expand Down

0 comments on commit 0b1370b

Please sign in to comment.