“ 这可能是全网唯一且首次总结Cypher统计节点、关系、属性数量的文章,干货在手,点击在看。”
统计所有节点总数
match (n) return count(n)
统计所有关系总数
match ()-[r]->() return count(r)
统计所有节点属性总数
match (n)
with size(keys((properties(n)))) as l
return sum(l)
统计所有关系属性总数
match ()-[r]->()
with size(keys(properties(r))) as l
return sum(l)
统计节点类型即labels数量
CALL db.labels() YIELD label return size(collect(label))
match (n)
with distinct labels(n) as l
return reduce(s=0, x in collect(size(l))|s + x)
match (n)
with distinct labels(n) as l
unwind l as ls
return size(collect(ls))
统计关系类型即type数量
match ()-[r]->()
with collect(distinct type(r)) as l
return size(l)
列出节点类型即labels
CALL db.labels() YIELD label return collect(label)
match (n)
with distinct labels(n) as l
unwind l as ls
return collect(ls)
列出关系类型即type
match ()-[r]->()
with collect(distinct type(r)) as l
return l
统计节点每种类型即每种labels的数量
match (n)
with distinct labels(n) as l, n
unwind l as label
return label, count(n)
match (n)
with distinct labels(n) as l
unwind l as label
match(m) where label in labels(m)
return label, count(m)
统计关系每种类型即每种type的数量
match ()-[r]->() return distinct type(r), count(*)
原创不易,求转发,求点“在看”,喜欢请关注,在这里有最真实的分享!
Python与知识图谱
建了一个知识图谱的交流群,欢迎技术相关的朋友入群交流!
可以加我个人微信入群
(微信号:yangzhi1278085188,暗号:neo4j)
更多内容请访问:IT源点
注意:本文归作者所有,未经作者允许,不得转载