Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community : added support for pickle networkx graph import #27068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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