NEO4J 函数+CYPHER

断言函数(Predicate functions)

ALL(identifier in collection WHERE predicate) 判断一个断言(predicate)是否满足集合(collection)里的所有元素
ANY(identifier in collection WHERE predicate) 判断一个断言(predicate)是否至少满足集合(collection)里的一个元素
NONE(identifier in collection WHERE predicate) 如果集合(collection)里的元素不满足断言(predicate)则返回true
SINGLE(identifier in collection WHERE predicate) 如果集合(collection)里的只有一个元素满足断言(predicate)则返回true

标量函数(Scalar functions)

LENGTH( collection ) 返回集合的元素个数
TYPE( relationship ) 返回关系的类型
ID( property-container ) 返回节点或者关系的ID
COALESCE( expression [, expression]* ) 返回expressions列表里第一个不为空的值
HEAD( expression ) 返回一个集合 (collection) 里的第一个元素
LAST( expression ) 返回一个集合 (collection) 里最后一个元素

集合函数(Collection functions)

NODES( path ) 返回一个路径的所有节点
RELATIONSHIPS( path ) 返回一个路径的所有关系
EXTRACT( identifier in collection : expression ) 返回一个结果集合:对集合(collection)的所有元素执行expression的操作得到的结果
FILTER(identifier in collection : predicate) 返回集合(collection)中所有满足断言(predicate)的元素组成的集合
TAIL( expression ) 返回集合中除了第一个之外的所有元素
RANGE( start, end [, step] ) 返回从start开始,end结束(闭区间)内步长为step(非0)的所有整数数字

数学函数(Mathematical functions)

ABS( expression ) 返回expression得到的数值的绝对值
ROUND( expression ) 取整函数:返回小于等于expression得到的数值的最大整数(还是返回离expression得到的数值最近的整数)
SQRT( expression ) 返回expression得到的数值的平方根
SIGN( expression ) 符号函数:如果expression得到的数值,为0则返回0;为负数则返回-1;为正数则返回1

聚合函数(Aggregate functions)

COUNT( expression ) 返回expression得到的结果的个数,expression也可为"*"
SUM( expression ) 返回expression得到结果相加的和
AVG( expression ) 返回expression得到结果的平均值
MAX( expression ) 返回expression得到结果的最大值
MIN( expression ) 返回expression得到结果的最小值
COLLECT( expression ) 把expression得到的结果以list的形式返回

CYPHER

删除重复关系

MATCH (a)-[rel:has_test_rel]->(b)
WITH a, b, TAIL (COLLECT (rel)) as rr
WHERE size(rr)>0
FOREACH (r IN rr | DELETE r)
#备注:(a)-[rel:has_test_rel]-(b) 不管关系的方向 只保留一条关系

根据标签筛选

MATCH data = (n:LABEL)-[*1…5]->(m) where any(label in labels(m) where label in [label1,label2]) RETURN data LIMIT 30

更改关系类型

MATCH (n)-[r]-(m)
CREATE (n)-[r2]->(m)
// copy properties, if necessary
SET r2 = r
WITH r
DELETE r

删除重复结点

MATCH (pp)
WITH pp
ORDER BY pp.NAME,size((pp)–()) DESC
WITH pp.NAME as name, collect(pp) AS nodes
WHERE size(nodes) > 1
UNWIND nodes[1…] AS n
DETACH DELETE n

导出CSV

#NEO4J CONJ
apoc.import.file.use_neo4j_config=true
apoc.export.file.enabled=true
apoc.import.file.enabled=true
dbms.directories.import=import
dbms.security.allow_csv_import_from_file_urls=true
###起止结点及关系
WITH “MATCH path = (n)-[R]->(m)
RETURN n.NAME AS START_NAME,m.NAME AS END_NAME,TYPE® AS RELATION_NAME LIMIT 50” AS query
CALL apoc.export.csv.query(query, “kg.csv”, {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;
###结点ID,名称,标签
WITH “MATCH (n)
RETURN id(n) as NODE_ID,n.NAME AS NODE_NAME,LABELS(n) AS NODE_LABEL LIMIT 50” AS query
CALL apoc.export.csv.query(query, “nodes.csv”, {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;
###关系名
WITH "MATCH (n)-[r]-(m)
RETURN distinct TYPE® AS RELATION_NAME " AS query
CALL apoc.export.csv.query(query, “relation.csv”, {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值