langchain_community.graphs.networkx_graph
.NetworkxEntityGraph¶
- class langchain_community.graphs.networkx_graph.NetworkxEntityGraph(graph: Optional[Any] = None)[source]¶
用于实体图操作的Networkx包装器。
- 安全提示: 确保数据库连接使用的凭据范围狭窄,仅包括必要的权限。
如果未能这样做,可能会导致数据损坏或丢失,因为调用代码可能会尝试执行会导致删除、变异数据(如果适当提示)或读取敏感数据(如果数据库中存在此类数据)的命令。 防范这些负面结果的最佳方法是(根据需要)限制授予此工具使用的凭据的权限。
有关更多信息,请参见 https://python.langchain.com/docs/security。
创建一个新的图。
Methods
__init__
([graph])创建一个新的图。
add_node
(node)在图中添加节点。
add_triple
(knowledge_triple)向图中添加一个三元组。
clear
()清除图表。
清除图的边缘。
delete_triple
(knowledge_triple)从图中删除一个三元组。
draw_graphviz
(**kwargs)提供更好的绘图
from_gml
(gml_path)get_entity_knowledge
(entity[, depth])获取有关实体的信息。
get_neighbors
(node)返回给定节点的邻居节点。
获取图中节点的数量。
按因果依赖关系排序的图中实体名称列表。
获取图中的所有三元组。
has_edge
(source_node, destination_node)如果图中存在给定节点之间的边,则返回True。
has_node
(node)如果图中有给定的节点,则返回。
remove_edge
(source_node, destination_node)从图中删除边。
remove_node
(node)从图中删除节点。
write_to_gml
(path)- Parameters
graph (Optional[Any]) –
- Return type
None
- __init__(graph: Optional[Any] = None) None [source]¶
创建一个新的图。
- Parameters
graph (Optional[Any]) –
- Return type
None
- add_triple(knowledge_triple: KnowledgeTriple) None [source]¶
向图中添加一个三元组。
- Parameters
knowledge_triple (KnowledgeTriple) –
- Return type
None
- delete_triple(knowledge_triple: KnowledgeTriple) None [source]¶
从图中删除一个三元组。
- Parameters
knowledge_triple (KnowledgeTriple) –
- Return type
None
- draw_graphviz(**kwargs: Any) None [source]¶
提供更好的绘图
在jupyter notebook中的使用:
>>> from IPython.display import SVG >>> self.draw_graphviz_svg(layout="dot", filename="web.svg") >>> SVG('web.svg')
- Parameters
kwargs (Any) –
- Return type
None
- classmethod from_gml(gml_path: str) NetworkxEntityGraph [source]¶
- Parameters
gml_path (str) –
- Return type
- get_entity_knowledge(entity: str, depth: int = 1) List[str] [source]¶
获取有关实体的信息。
- Parameters
entity (str) –
depth (int) –
- Return type
List[str]
- get_neighbors(node: str) List[str] [source]¶
返回给定节点的邻居节点。
- Parameters
node (str) –
- Return type
List[str]
- get_triples() List[Tuple[str, str, str]] [source]¶
获取图中的所有三元组。
- Return type
List[Tuple[str, str, str]]
- has_edge(source_node: str, destination_node: str) bool [source]¶
如果图中存在给定节点之间的边,则返回True。
- Parameters
source_node (str) –
destination_node (str) –
- Return type
bool