Neo4j-Apoc

APOC

https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_virtual_nodes_rels

提供的函数 存储过程应有尽有, 也可以自行实现添加

CALL apoc.help("dijkstra")

Apoc配置:

apoc.trigger.enabled=false/true  :  Enable triggersapoc.ttl.enabled=false/true:  Enable time to live background taskapoc.jdbc.<key>.uri=jdbc-url-with-credentials :  配置数据库连接串apoc.es.<key>.uri=es-url-with-credentials:  ES连接apoc.mongodb.<key>.uri=mongodb-url-with-credentials: mongodb连接apoc.couchbase.<key>.uri=couchbase-url-with-credentials: couchbase连接apoc.jobs.scheduled.num_threads=number-of-threads: APOC调度器的线程池apoc.jobs.pool.num_threads=number-of-threads: 执行器的线程池

有用的函数方法:

解析域名: WITH 'http://www.example.com/all-the-things' AS url RETURN apoc.data.domain(url) // will return 'www.example.com'日期函数: apoc.date.parse('2015/03/25 03-15-59',['s'],['yyyy/MM/dd HH/mm/ss'])apoc.date.add(12345, 'ms', -365, 'd') 格式转换:return apoc.number.format(12345.67) as valuereturn apoc.number.format(12345, '#,##0.00;(#,##0.00)', 'it') as value数学运算:RETURN apoc.number.exact.add(stringA,stringB)RETURN apoc.number.exact.sub(stringA,stringB)ETURN apoc.number.exact.mul(stringA,stringB,[prec],[roundingModel]RETURN apoc.number.exact.div(stringA,stringB,[prec],[roundingModel])RETURN apoc.number.exact.toInteger(string,[prec],[roundingMode])RETURN apoc.number.exact.toFloat(string,[prec],[roundingMode])RETURN apoc.number.exact.toExact(number)比较节点不同:apoc.diff.nodes([leftNode],[rightNode])

图算法:

路径扩展(选择走哪些边, 哪些节点, 几层, 什么时候结束等等):CALL apoc.path.expand(startNode <id>|Node, relationshipFilter, labelFilter, minLevel, maxLevel )MATCH (user:User) WHERE user.id = 460CALL apoc.path.expandConfig(user,{relationshipFilter:"RATED",minLevel:3,maxLevel:3,bfs:false,uniqueness:"NONE"}) YIELD pathRETURN count(*);apoc.path.subgraphAll(startNode <id>Node/list, {maxLevel, relationshipFilter, labelFilter, bfs:true, filterStartNode:true, limit:-1}) yield nodes, relationshipsMATCH (user:User) WHERE user.id = 460CALL apoc.path.subgraphNodes(user, {}) YIELD nodeRETURN node;Closeness Centrality:CALL apoc.algo.closeness(['TYPE'],nodes,'INCOMING') YIELD node, scoreBetweenness Centrality:CALL apoc.algo.betweenness(['TYPE'],nodes,'BOTH') YIELD node, scorepageRank:CALL apoc.algo.pageRank(nodes) YIELD node, score// only compute over relationships of types TYPE_1 or TYPE_2CALL apoc.algo.pageRankWithConfig(nodes,{types:'TYPE_1|TYPE_2'}) YIELD node, score// peroform 10 page rank iterations, computing only over relationships of type TYPE_1CALL apoc.algo.pageRankWithConfig(nodes,{iterations:10,types:'TYPE_1'}) YIELD node, scoredijkstra:apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance') YIELD path, weightapoc.algo.dijkstraWithDefaultWeight(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', 10) YIELD path, weightexample:MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'})CALL apoc.algo.dijkstra(from, to, 'ROAD', 'd') yield path as path, weight as weightRETURN path, weightcommunity: 标签传播的社区发现算法apoc.algo.community(times,labels,partitionKey,type,direction,weightKey,batchSize)example:  遍历25轮, CALL apoc.algo.community(25,null,'partition','X','OUTGOING','weight',10000)aStar: A*遍历算法apoc.algo.aStar(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance','lat','lon') YIELD path, weightcliques: 聚类社区算法:apoc.algo.cliques(minSize) YIELD cliqueapoc.algo.cliquesWithNode(startNode, minSize) YIELD clique各种距离算法:apoc.algo.cosineSimilarity([vector1], [vector2])   cosin相似度apoc.algo.euclideanDistance([vector1], [vector2])  欧几里得距离apoc.algo.euclideanSimilarity([vector1], [vector2])  欧几里得相似度

Virtual Nodes/Rels: 虚拟节点, 关系 类似视图的概念

MATCH (a)-[r]->(b)
WITH head(labels(a)) AS l, head(labels(b)) AS l2, type(r) AS rel_type, count(*) as count
CALL apoc.create.vNode([l],{name:l}) yield node as a
CALL apoc.create.vNode([l2],{name:l2}) yield node as b
CALL apoc.create.vRelationship(a,rel_type,{count:count},b) yield rel
RETURN *;CALL apoc.create.vPattern({_labels:['Person'],name:'Mary'},'KNOWS',{since:2012},{_labels:['Person'],name:'Michael'})CALL apoc.create.vPattern({_labels:['Person', 'Woman'],name:'Mary'},'KNOWS',{since:2012},{_labels:['Person', 'Man'],name:'Michael'})CALL apoc.create.vPatternFull(['British','Person'],{name:'James', age:28},'KNOWS',{since:2009},['Swedish','Person'],{name:'Daniel', age:30})

Cypher Exectuion: 批量执行脚本

CALL apoc.cypher.runFiles([files or urls],{config}) yield row, result   runs each statement in the files, all semicolon separatedCALL apoc.cypher.runFile(file or url,{config}) yield row, result
runs each statement in the file, all semicolon separated - currently no schema operations

Manual Index: 手工索引, 默认不会自动更新

synchronously同步更新 只有创建索引时指定autoUpdate:true, 才会真正生效, 更新图时性能上会有影响apoc.autoIndex.enabled=true  asynchronously异步更新apoc.autoIndex.async=true  默认的异步更新参数:50000 operations or 5000 milliseconds 触发apoc.autoIndex.queue_capacity=100000apoc.autoIndex.async_rollover_opscount=50000apoc.autoIndex.async_rollover_millis=5000apoc.autoIndex.tx_handler_stopwatch=false添加多个节点属性缩影 配合search用, 重复执行会先删除再创建: apoc.index.addAllNodes('index-name',{label1:['prop1',…​],…​}, {options})  options的选择(map形式给入):type: fulltext/exact  全文索引/精确索引to_lower_case: false/trueanalyzer: classname   用哪种classname of lucene analyzer similarity: classname   相似度计算的方式 classname for lucene similarity autoUpdate:  true/false  是否自动更新添加一个节点的属性索引(可以不存在这个属性字段) apoc.index.addNode(node,['prop1',…​])对于给定的标签,添加节点索引(索引名称的Label和node可以不一致): apoc.index.addNodeByLabel('Label',node,['prop1',…​])给索引命名 默认是Label作为名称:  apoc.index.addNodeByName('name',node,['prop1',…​])apoc.index.addNodeMap(node,{key:value})apoc.index.addNodeMapByName(index, node,{key:value})关系索引: apoc.index.addRelationship(rel,['prop1',…​])apoc.index.addRelationshipByName('name',rel,['prop1',…​])apoc.index.addRelationshipMap(rel,{key:value})apoc.index.addRelationshipMapByName(index, rel,{key:value})删除节点索引 apoc.index.removeNodeByName('name',node) remove node from an index for the given name索引模糊查询(计算编辑距离)  apoc.index.search('index-name', 'query') YIELD node, weightapoc.index.nodes('Label','prop:value*') YIELD node, weightapoc.index.relationships('TYPE','prop:value*') YIELD rel, weight没理解: apoc.index.between(node1,'TYPE',node2,'prop:value*') YIELD rel, weight示例:match (p:Person) call apoc.index.addNode(p,["name","age"]) RETURN count(*); // 129s for 1M Peoplecall apoc.index.nodes('Person','name:name100*') YIELD node, weight return * limit 2

Index Management:

CALL apoc.index.remove('Thing') 展示: CALL apoc.index.list() CALL apoc.index.forNodes('name',{config}) YIELD type,name,configCALL apoc.index.forRelationships('name',{config}) YIELD type,name,config

Triggers : 触发器

apoc.trigger.enabled=true

Locking: 锁

call apoc.lock.nodes([nodes])call apoc.lock.rels([relationships])call apoc.lock.all([nodes],[relationships])

Meta Graph: 展示节点, 关系标签的概览图

CALL apoc.meta.graphSample()CALL apoc.meta.graph有选择的展示一部分结果: CALL apoc.meta.subGraph({labels:[labels],rels:[rel-types],excludes:[label,rel-type,…​]})表格形式展示数据: CALL apoc.meta.dataMap形式展示数据: CALL apoc.meta.schema快速查看图中各种存在的节点,边: CALL apoc.meta.stats yield labelCount, relTypeCount, propertyKeyCount, nodeCount, relCount, labels, relTypes, stats

Sehema: 查看各种索引, 约束

apoc.schema.assert({indexLabel:[indexKeys],…​},{constraintLabel:[constraintKeys],…​}, dropExisting : true) yield label, key, unique, actionapoc.schema.nodes() yield name, label, properties, status, typeapoc.schema.relationships() yield name, type, properties, statusapoc.schema.node.indexExists(labelName, properties)apoc.schema.node.constraintExists(labelName, properties)apoc.schema.relationship.constraintExists(type, properties)

Streaming Data to Gephi: 导出数据到Gephi

apoc.gephi.add(url-or-key, workspace, data, weightproperty, ['exportproperty'])

原文地址:https://www.jianshu.com/p/851ab29420fd

转载于:https://www.cnblogs.com/jpfss/p/11393456.html

Neo4j-Apoc相关推荐

  1. neo4j安装_怎样安装Neo4j APOC扩展包?

    APOC - Awesome Procedures of Cypher 是Neo4j图数据库的扩展过程和函数库. Neo4j图数据库扩展是基于Neo4j相关API和开发框架.使用Java开发的.部署在 ...

  2. Neo4j apoc cycles(一)

    apoc.nodes.cycles - APOC Documentation (neo4j.com) Cycle Detection in TigerGraph

  3. 4j导入节点与关系_Neo4j Cypher 中怎样根据值动态指定关系类型?

    Neo4j的Cypher查询语言在创建节点之间关系时需要指定一个类型,例如: CREATE (n:Person{name:'张三'}) -[r:WORKS_FOR]-> (c:Company{n ...

  4. tensorflow中的一些基本函数

    原 Tensorflow一些常用基本概念与函数(1) 2016年08月08日 16:00:56 阅读数:104501 摘要:本文主要对tf的一些常用概念与方法进行描述. 1.tensorflow的基本 ...

  5. aws实例启动失败_AWS:启动安装了APOC的Neo4j实例

    aws实例启动失败 安装Neo4j之后,我要做的第一件事就是安装APOC库 ,但是我发现在AWS上旋转服务器时这是一个手动过程,所以我想简化一下. 已经有一个Neo4j AMI可以安装Neo4j 3. ...

  6. AWS:启动安装了APOC的Neo4j实例

    安装Neo4j之后,我要做的第一件事就是安装APOC库 ,但是我发现在AWS上旋转服务器时这是一个手动过程,所以我想简化一下. 已经有一个Neo4j AMI可以安装Neo4j 3.2.0 ,我的同事M ...

  7. Neo4j 图数据库高级应用系列 / 服务器扩展指南 APOC 8.8 - 图生成 完全图

    1.概述 apoc.generate.complete 本过程生成一个完全图.完全图中,每个节点有到所有其他节点的边.在无向图中,有N个节点的完全图有N x (N – 1) / 2个边.Neo4j在存 ...

  8. neo4j安装APOC、aglo插件

    安装方法 只要下载.jar这一个插件包就好了,将下载好的.jar文件直接放到neo4j安装目录下的plugins文件夹目录下,再修改一下配置文件就可以了. 1.插件下载: APOC 国内地址:http ...

  9. 【Neo4j构建知识图谱】配置知识图谱插件APOC与案例实现

    APOC (Awesome Procedures on Cypher) 是一个 Neo4j 的扩展库,可以在 Cypher 中使用各种额外的功能和过程. 目录 1.安装插件 2.验证是否安装成功 3. ...

  10. 图数据库-Neo4j(五):利用Apoc进行数据的导入、导出【Neo4j插件】【csv格式、json格式、Cypher脚本】

    一.APOC安装.配置 官方文档:neo4j-apoc 官方文档 1.配置 1.1 下载apoc包 直接在官网下载apoc安装包安装,解压即可. neo4的版本与apoc 版本要对应. neo4j-c ...

最新文章

  1. 推荐一款常用的IDE插件,越用越喜欢
  2. 编程入门:准备学Python入门编程 为什么前辈一直劝我不行?
  3. 如何使用Windows开发机为iPhone开发?
  4. a singleton implemention
  5. 怎么用计算机把浓度转换成PH,ph换算(ph和氢离子浓度的换算计算器)
  6. qlineedit文本改变时_PyQt5 QLineEdit(单行编辑器) 学习
  7. Qt Ctreator搭配VS2013调试——整合QML/C++调试需要的从属调试引擎无法被创建
  8. 【续上篇】推荐一款液晶电视测试软件
  9. sqlite 按拼音排序
  10. [转载] python输入一个年份、输出是否为闰年_Python程序检查给定年份是否为闰年
  11. ubuntu安装teamview
  12. nodpad 设置护眼_最详细的保护眼睛的方法,总有一个适合你。
  13. 矩阵相乘c语言代码用指针实现,矩阵相乘C语言实现
  14. android动态壁纸的制作教程,巧用Windows自带工具,简易制作动态壁纸教程
  15. 总线型,星型,环状,树形,网状拓扑结构
  16. Unity 实现两个向量夹角为0~360度
  17. 树莓派基础实验26:旋转编码器实验
  18. Agens Graph常用语法总结
  19. shell 小米system锁adb_忘记锁屏密码不用怕?支招小米手机解锁四种简单常用的方法...
  20. OpenHarmony在Amlogic A311D芯片平台的快速开发上手指南

热门文章

  1. 解决eclipse代码提示时卡死的问题
  2. kubectl logs 用法
  3. excel时间戳‘精准’转换为日期
  4. linux安装mysql8 一步一步超详细教程
  5. 人工智能(一)概述(树状图)
  6. OVA虚拟机从下载到安装
  7. Kepware助力宾夕法尼亚大学实现校园运营管理
  8. 十进制点分IP转换为32位二进制IP
  9. 【视频爬虫】简单代码实现守望先锋CG动画爬虫
  10. 【姿态估计】MediaPipe部分solution(手势,人体姿态,面部动作)的用法