Neo4j-Apoc

    <!-- 作者区域 -->

    <!-- 文章内容 -->
<div data-note-content="" class="show-content">
<div class="show-content-free">
<p>APOC</p>

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

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

CALL apoc.help("dijkstra")

Apoc配置:

apoc.trigger.enabled=false/true  :  Enable triggers

apoc.ttl.enabled=false/true:  Enable time to live background task

apoc.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(<span class="hljs-string"><span class="hljs-string">'2015/03/25 03-15-59'</span></span>,[<span class="hljs-string"><span class="hljs-string">'s'</span></span>],[<span class="hljs-string"><span class="hljs-string">'yyyy/MM/dd HH/mm/ss'</span></span>])

apoc.date.add(<span class="hljs-number"><span class="hljs-number">12345</span></span>, <span class="hljs-string"><span class="hljs-string">'ms'</span></span>, <span class="hljs-number"><span class="hljs-number">-365</span></span>, <span class="hljs-string"><span class="hljs-string">'d'</span></span>)

格式转换:

<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> apoc.number.format(<span class="hljs-number"><span class="hljs-number">12345.67</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">as</span></span> value

<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> apoc.number.format(<span class="hljs-number"><span class="hljs-number">12345</span></span>, <span class="hljs-string"><span class="hljs-string">'#,##0.00;(#,##0.00)'</span></span>, <span class="hljs-string"><span class="hljs-string">'it'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">as</span></span> value

数学运算:

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.add(stringA,stringB)

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.sub(stringA,stringB)

ETURN apoc.number.exact.mul(stringA,stringB,[prec],[roundingModel]

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.div(stringA,stringB,[prec],[roundingModel])

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.toInteger(string,[prec],[roundingMode])

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.toFloat(string,[prec],[roundingMode])

<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> apoc.number.exact.toExact(number)

比较节点不同:

apoc.diff.nodes([leftNode],[rightNode])

图算法:

路径扩展(选择走哪些边, 哪些节点, 几层, 什么时候结束等等):
CALL apoc.path.expand(startNode &lt;id&gt;|Node, relationshipFilter, labelFilter, minLevel, maxLevel )

MATCH (user:User) WHERE user.id = <span class="hljs-number"><span class="hljs-number">460</span></span>
CALL apoc.path.expandConfig(user,{relationshipFilter:<span class="hljs-string"><span class="hljs-string">"RATED"</span></span>,minLevel:<span class="hljs-number"><span class="hljs-number">3</span></span>,maxLevel:<span class="hljs-number"><span class="hljs-number">3</span></span>,bfs:<span class="hljs-keyword"><span class="hljs-keyword">false</span></span>,uniqueness:<span class="hljs-string"><span class="hljs-string">"NONE"</span></span>}) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> path
<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> count(*); apoc.path.subgraphAll(startNode &lt;id&gt;Node/<span class="hljs-keyword"><span class="hljs-keyword">list</span></span>, {maxLevel, relationshipFilter, labelFilter, bfs:<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>, filterStartNode:<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>, limit:<span class="hljs-number"><span class="hljs-number">-1</span></span>}) <span class="hljs-keyword"><span class="hljs-keyword">yield</span></span> nodes, relationships MATCH (user:User) WHERE user.id = <span class="hljs-number"><span class="hljs-number">460</span></span>
CALL apoc.path.subgraphNodes(user, {}) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node
<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> node;

Closeness Centrality:

CALL apoc.algo.closeness([<span class="hljs-string"><span class="hljs-string">'TYPE'</span></span>],nodes,<span class="hljs-string"><span class="hljs-string">'INCOMING'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, score

Betweenness Centrality:

CALL apoc.algo.betweenness([<span class="hljs-string"><span class="hljs-string">'TYPE'</span></span>],nodes,<span class="hljs-string"><span class="hljs-string">'BOTH'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, score

pageRank:

CALL apoc.algo.pageRank(nodes) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, score

<span class="hljs-comment"><span class="hljs-comment">// only compute over relationships of types TYPE_1 or TYPE_2</span></span>

CALL apoc.algo.pageRankWithConfig(nodes,{types:<span class="hljs-string"><span class="hljs-string">'TYPE_1|TYPE_2'</span></span>}) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, score

<span class="hljs-comment"><span class="hljs-comment">// peroform 10 page rank iterations, computing only over relationships of type TYPE_1</span></span>

CALL apoc.algo.pageRankWithConfig(nodes,{iterations:<span class="hljs-number"><span class="hljs-number">10</span></span>,types:<span class="hljs-string"><span class="hljs-string">'TYPE_1'</span></span>}) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, score

dijkstra:

apoc.algo.dijkstra(startNode, endNode, <span class="hljs-string"><span class="hljs-string">'KNOWS|&lt;WORKS_WITH|IS_MANAGER_OF&gt;'</span></span>, <span class="hljs-string"><span class="hljs-string">'distance'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> path, weight

apoc.algo.dijkstraWithDefaultWeight(startNode, endNode, <span class="hljs-string"><span class="hljs-string">'KNOWS|&lt;WORKS_WITH|IS_MANAGER_OF&gt;'</span></span>, <span class="hljs-string"><span class="hljs-string">'distance'</span></span>, <span class="hljs-number"><span class="hljs-number">10</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> path, weight

example:

    MATCH (from:Loc{name:<span class="hljs-string"><span class="hljs-string">'A'</span></span>}), (to:Loc{name:<span class="hljs-string"><span class="hljs-string">'D'</span></span>})
CALL apoc.algo.dijkstra(from, to, <span class="hljs-string"><span class="hljs-string">'ROAD'</span></span>, <span class="hljs-string"><span class="hljs-string">'d'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">yield</span></span> path <span class="hljs-keyword"><span class="hljs-keyword">as</span></span> path, weight <span class="hljs-keyword"><span class="hljs-keyword">as</span></span> weight
<span class="hljs-keyword"><span class="hljs-keyword">RETURN</span></span> path, weight

community: 标签传播的社区发现算法

apoc.algo.community(times,labels,partitionKey,type,direction,weightKey,batchSize)

example:  遍历<span class="hljs-number"><span class="hljs-number">25</span></span>轮, 

    CALL apoc.algo.community(<span class="hljs-number"><span class="hljs-number">25</span></span>,<span class="hljs-keyword"><span class="hljs-keyword">null</span></span>,<span class="hljs-string"><span class="hljs-string">'partition'</span></span>,<span class="hljs-string"><span class="hljs-string">'X'</span></span>,<span class="hljs-string"><span class="hljs-string">'OUTGOING'</span></span>,<span class="hljs-string"><span class="hljs-string">'weight'</span></span>,<span class="hljs-number"><span class="hljs-number">10000</span></span>)

aStar: A*遍历算法

apoc.algo.aStar(startNode, endNode, <span class="hljs-string"><span class="hljs-string">'KNOWS|&lt;WORKS_WITH|IS_MANAGER_OF&gt;'</span></span>, <span class="hljs-string"><span class="hljs-string">'distance'</span></span>,<span class="hljs-string"><span class="hljs-string">'lat'</span></span>,<span class="hljs-string"><span class="hljs-string">'lon'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> path, weight

cliques: 聚类社区算法:

apoc.algo.cliques(minSize) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> clique

apoc.algo.cliquesWithNode(startNode, minSize) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> 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 separated

CALL 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=<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>

asynchronously异步更新

apoc.autoIndex.async=<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>  

默认的异步更新参数:<span class="hljs-number"><span class="hljs-number">50000</span></span> operations <span class="hljs-keyword"><span class="hljs-keyword">or</span></span> <span class="hljs-number"><span class="hljs-number">5000</span></span> milliseconds 触发

apoc.autoIndex.queue_capacity=<span class="hljs-number"><span class="hljs-number">100000</span></span>
apoc.autoIndex.async_rollover_opscount=<span class="hljs-number"><span class="hljs-number">50000</span></span>
apoc.autoIndex.async_rollover_millis=<span class="hljs-number"><span class="hljs-number">5000</span></span>
apoc.autoIndex.tx_handler_stopwatch=<span class="hljs-keyword"><span class="hljs-keyword">false</span></span>

添加多个节点属性缩影 配合search用, 重复执行会先删除再创建: apoc.index.addAllNodes('index-name',{label1:['prop1',…​],…​}, {options})

options的选择(map形式给入):

type: fulltext/exact  全文索引/精确索引

to_lower_case: <span class="hljs-keyword"><span class="hljs-keyword">false</span></span>/<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>

analyzer: classname   用哪种classname of lucene analyzer 

similarity: classname   相似度计算的方式 classname <span class="hljs-keyword"><span class="hljs-keyword">for</span></span> lucene similarity 

autoUpdate:  <span class="hljs-keyword"><span class="hljs-keyword">true</span></span>/<span class="hljs-keyword"><span class="hljs-keyword">false</span></span>  是否自动更新

添加一个节点的属性索引(可以不存在这个属性字段) 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, weight

apoc.index.nodes('Label','prop:value*') YIELD node, weight

apoc.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 People

call apoc.index.nodes(<span class="hljs-string"><span class="hljs-string">'Person'</span></span>,<span class="hljs-string"><span class="hljs-string">'name:name100*'</span></span>) <span class="hljs-keyword"><span class="hljs-keyword">YIELD</span></span> node, weight <span class="hljs-keyword"><span class="hljs-keyword">return</span></span> * limit <span class="hljs-number"><span class="hljs-number">2</span></span>

Index Management:

CALL apoc.index.remove('Thing') 

展示: CALL apoc.index.list()

CALL apoc.index.forNodes('name',{config}) YIELD type,name,config

CALL 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.data

Map形式展示数据: 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, action

apoc.schema.nodes() yield name, label, properties, status, type

apoc.schema.relationships() yield name, type, properties, status

apoc.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'])

      </div>

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

Neo4j-Apoc的更多相关文章

  1. neo4j APOC与自定义存储过程环境搭建

    neo4j APOC与自定义存储过程环境搭建 主要参考资料:APOC官网https://neo4j-contrib.github.io/neo4j-apoc-procedures/APOC介绍 PPT ...

  2. Neo4j 安装插件APOC和GRAPH ALGORITHMS

    在 https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases 下载apoc扩展包JAR文件 在 https://github.co ...

  3. Neo4j高级应用技术专题系列 - APOC存储过程库-【1】概述

    Neo4j高级应用技术专题系列 - APOC存储过程库-[1]概述 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://bl ...

  4. 使用APOC技术从MYSQL数据库导数据到Neo4j图数据库(JDBC)

                                                     Neo4j 数据导入 一.安装与部署Neo4j 直接在官网下载安装包安装,解压即可. 2.mysql ...

  5. NEO4J 图数据库使用APOC数据导入

       Neo4j 数据导入 一.安装与部署 直接在官网下载安装包安装,解压即可. 二.下载相应的jar包 apoc 包下载链接: https://github.com/neo4j-contrib/ne ...

  6. neo4j安装APOC插件

    1.APOC下载地址:https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/3.4.0.1 只要下载.jar这一个压缩文件就好 ...

  7. Neo4j 3.0 存储过程

    Neo4j 3.0 提供一个新的功能“存储过程”,该功能并不是Neo4j-Server的扩展,而是可以直接运行的. 在写这篇文章的时候,只能通过预备好的语句去执行 1 CALL package.pro ...

  8. neo4j语法

    图数据库在社交网络.实时推荐.征信系统.人工智能等领域有广泛应用. 集群特征:主从复制,重选主服务器和容错:每个实例都有自己的本地缓冲 性能优势:查询内不跨网络:实时操作,具有快速和一致的响应时间:缓 ...

  9. Neo4j使用简单例子(转)

    Neo4j Versions Most of the examples on this page are written with Neo4j 2.0 in mind, so they skip th ...

  10. Neo4j配置文件neo4j.conf

    机器配置为256G内存,48核(物理核24)cpu,4T SAS盘(建议磁盘使用SSD) 图数据库Neo4j配置文件neo4j.conf 中常用参数: dbms.active_database=gra ...

随机推荐

  1. JavaWeb学习篇之----Jsp详解

    今天我们来看一下Jsp的相关知识,首先来看看一下Jsp的相关定义: 简介: JSP全称是JavaServer Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术 ...

  2. 听说“辣鸡小隔膜”出V1.3了?

    点击下载zip就送屠龙宝刀升级脚本(Version 1.2) 点击下载zip就送倚天宝剑种子测试器(Version 1.2) 顺便膜一波orz::Kevin

  3. lua数组和数据类型转换

    一.lua数组 Lua数组大小不固定,下标是从  1开始. --数组 arr={"aaa","bbb","ccc"} --使用数值 for通 ...

  4. NX二次开发-NX11创建表达式组NXOpen::ExpressionGroup

    NX11+VS2013 #include <uf.h> #include <uf_modl.h> #include <uf_part.h> #include < ...

  5. C语言-实例3个数由小到大排序

    VS2012 //C语言实例 3个数由小到大排序 #include <stdio.h> void main() { int a, b, c, t; printf("Please ...

  6. error C2443: operand size conflict

    #include <stdio.h> void main() { int a=98; __asm {     mov al,a     and al,11011111B     mov a ...

  7. PAT_A1043#Is It a Binary Search Tree

    Source: PAT A1043 Is It a Binary Search Tree (25 分) Description: A Binary Search Tree (BST) is recur ...

  8. Quartz2作业监听

    在本教程中,我们将展示/介绍如何创建一个JobListener,跟踪运行工作状态在作业完成等. P.S 这个例子是Quartz 2.1.5 1. Quartz 作业 作业 - 用于打印一个简单的信息, ...

  9. 运行mybatis项目,运行测试类,点击test后,出现Cannot start compilation: the output path is not specified for module "前......

    Cannot start compilation: the output path is not specified for module "前 后来发现是在pom.xml右击,有个+号,把 ...

  10. 转载:jQuery 获取屏幕高度、宽度

    做手机Web开发做浏览器兼容用到了,所以在网上找了些汇总下. alert($(window).height()); //浏览器当前窗口可视区域高度 alert($(document).height() ...