Skip to content

Commit

Permalink
community[patch]: Added functions in NetworkxEntityGraph class (#17535)
Browse files Browse the repository at this point in the history
- **Description:** 
1. Added _clear_edges()_ and _get_number_of_nodes()_ functions in
NetworkxEntityGraph class.
2. Added the above two function in graph_networkx_qa.ipynb
documentation.
  • Loading branch information
raunakshrivastava7 authored Feb 14, 2024
1 parent bfaa8c3 commit 685d62b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
33 changes: 30 additions & 3 deletions docs/docs/use_cases/graph/graph_networkx_qa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,34 @@
"id": "045796cf",
"metadata": {},
"outputs": [],
"source": []
"source": [
"loaded_graph.get_number_of_nodes()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d24b3407",
"metadata": {},
"outputs": [],
"source": [
"loaded_graph.clear_edges()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8afda51",
"metadata": {},
"outputs": [],
"source": [
"loaded_graph.clear()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.10.6 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -317,7 +339,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.6"
},
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
Expand Down
8 changes: 8 additions & 0 deletions libs/community/langchain_community/graphs/networkx_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ def clear(self) -> None:
"""Clear the graph."""
self._graph.clear()

def clear_edges(self) -> None:
"""Clear the graph edges."""
self._graph.clear_edges()

def get_number_of_nodes(self) -> int:
"""Get number of nodes in the graph."""
return self._graph.number_of_nodes()

def get_topological_sort(self) -> List[str]:
"""Get a list of entity names in the graph sorted by causal dependence."""
import networkx as nx
Expand Down

0 comments on commit 685d62b

Please sign in to comment.