当前位置:   article > 正文

Neo4j-Apoc

apoc.algo.cliques

APOC

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

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

CALL apoc.help("dijkstra")

Apoc配置:

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

有用的函数方法:

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

图算法:

  1. 路径扩展(选择走哪些边, 哪些节点, 几层, 什么时候结束等等):
  2. CALL apoc.path.expand(startNode <id>|Node, relationshipFilter, labelFilter, minLevel, maxLevel )
  3. MATCH (user:User) WHERE user.id = 460
  4. CALL apoc.path.expandConfig(user,{relationshipFilter:"RATED",minLevel:3,maxLevel:3,bfs:false,uniqueness:"NONE"}) YIELD path
  5. RETURN count(*);
  6. apoc.path.subgraphAll(startNode <id>Node/list, {maxLevel, relationshipFilter, labelFilter, bfs:true, filterStartNode:true, limit:-1}) yield nodes, relationships
  7. MATCH (user:User) WHERE user.id = 460
  8. CALL apoc.path.subgraphNodes(user, {}) YIELD node
  9. RETURN node;
  10. Closeness Centrality:
  11. CALL apoc.algo.closeness(['TYPE'],nodes,'INCOMING') YIELD node, score
  12. Betweenness Centrality:
  13. CALL apoc.algo.betweenness(['TYPE'],nodes,'BOTH') YIELD node, score
  14. pageRank:
  15. CALL apoc.algo.pageRank(nodes) YIELD node, score
  16. // only compute over relationships of types TYPE_1 or TYPE_2
  17. CALL apoc.algo.pageRankWithConfig(nodes,{types:'TYPE_1|TYPE_2'}) YIELD node, score
  18. // peroform 10 page rank iterations, computing only over relationships of type TYPE_1
  19. CALL apoc.algo.pageRankWithConfig(nodes,{iterations:10,types:'TYPE_1'}) YIELD node, score
  20. dijkstra:
  21. apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance') YIELD path, weight
  22. apoc.algo.dijkstraWithDefaultWeight(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', 10) YIELD path, weight
  23. example:
  24. MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'})
  25. CALL apoc.algo.dijkstra(from, to, 'ROAD', 'd') yield path as path, weight as weight
  26. RETURN path, weight
  27. community: 标签传播的社区发现算法
  28. apoc.algo.community(times,labels,partitionKey,type,direction,weightKey,batchSize)
  29. example: 遍历25轮,
  30. CALL apoc.algo.community(25,null,'partition','X','OUTGOING','weight',10000)
  31. aStar: A*遍历算法
  32. apoc.algo.aStar(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance','lat','lon') YIELD path, weight
  33. cliques: 聚类社区算法:
  34. apoc.algo.cliques(minSize) YIELD clique
  35. apoc.algo.cliquesWithNode(startNode, minSize) YIELD clique
  36. 各种距离算法:
  37. apoc.algo.cosineSimilarity([vector1], [vector2]) cosin相似度
  38. apoc.algo.euclideanDistance([vector1], [vector2]) 欧几里得距离
  39. apoc.algo.euclideanSimilarity([vector1], [vector2]) 欧几里得相似度

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

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

Cypher Exectuion: 批量执行脚本

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

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

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

Index Management:

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

Triggers : 触发器

apoc.trigger.enabled=true

Locking: 锁

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

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

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

Sehema: 查看各种索引, 约束

  1. apoc.schema.assert({indexLabel:[indexKeys],…​},{constraintLabel:[constraintKeys],…​}, dropExisting : true) yield label, key, unique, action
  2. apoc.schema.nodes() yield name, label, properties, status, type
  3. apoc.schema.relationships() yield name, type, properties, status
  4. apoc.schema.node.indexExists(labelName, properties)
  5. apoc.schema.node.constraintExists(labelName, properties)
  6. 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/11365325.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/1013765
推荐阅读
相关标签
  

闽ICP备14008679号