py2neo

Loading data to neo4j from XML using py2neo

爷,独闯天下 提交于 2019-12-08 06:05:38
问题 Im trying to load data to neo4j db from xml file using py2neo this python script works fine but its too slow since Im adding the nodes first then the relationships with two exceptions handlers. besides that the XML file size is around 200MB. Im wondering if there is faster way to perform this task? XML file: <Persons> <person> <id>XA123</id> <first_name>Adam</first_name> <last_name>John</last_name> <phone>01-12322222</phone> </person> <person> <id>XA7777</id> <first_name>Anna</first_name>

Cypher query in py2neo

余生长醉 提交于 2019-12-07 16:18:21
问题 How do I perform the functions of shortestPath() and allShortestPaths() in py2neo? In Cypher, I'd execute something like: START beginning=node(4), end=node(452) MATCH p = shortestPath(beginning-[*..500]-end) RETURN p I've tried what I thought was the equivalent (below), but this doesn't work (these relationships work in cypher, and the node_* objects are indeed the correct nodes >>> rels = list(graph_db.match(start_node=node_4, end_node=node_452)) >>> rels [] 回答1: I don't want to steal

Importing a large xml file to Neo4j with Py2neo

懵懂的女人 提交于 2019-12-06 18:58:31
I have a problem in importing a very big XML file with 36196662 lines. I am trying to create a Neo4j Graph Database of this XML file with Py2neo my xml file look like that: http://imgur.com/pLylHeG and My python code to import the xml data into Neo4j is like that: from xml.dom import minidom from py2neo import Graph, Node, Relationship, authenticate from py2neo.packages.httpstream import http http.socket_timeout = 9999 import codecs authenticate("localhost:7474", "neo4j", "******") graph = Graph("http://localhost:7474/db/data/") xml_file = codecs.open("User_profilesL2T1.xml","r", encoding=

py2neo 2.0: ERROR:httpstream:! SocketError: timed out

半世苍凉 提交于 2019-12-06 17:29:06
问题 I execute a long running (5 mintues) Cypher query with py2neo 2.0: graph.cypher.run(query) or result = graph.cypher.execute(query) The query fails after ~60 sec with a Socket Error from httpstream: ERROR:httpstream:! SocketError: timed out The same happens when I use a Cypher transaction. This did not happen with the same query and py2neo 1.6.4. Can I increase the time py2neo waits for a response? I didn't find anything in the docs. Update I found a hard coded socket_timeout in py2neo

Py2neo的基本用法

馋奶兔 提交于 2019-12-06 14:06:00
neo4j目前是图数据库的主流,neo4j的Cypher语法简单直观,但是不便于流程化。如果习惯在python环境下处理数据,那么还是要用到python的neo4j库,即py2neo. py2neo本身并不复杂,但要先适应它的思考模式。另一个问题是py2neo文档的示例较少,而且不同版本的py2neo挺不相同,容易弄混。这里要讲的是目前的v4版本。 连接数据库和图 from py2neo import * # *中常用的是Node,Relationship,Graph graph = Graph(url,username='name',password='pw') 2.查看数据库的基本属性 graph.schema.node_labels # 查看图结构中节点标签的类别,返回结果是一个frozenset graph.schema.relationship_types # 查看图结构中关系的类型 3.数据操作 数据操作分为两种方式,一种是直接传入cypher语句,这里我们称之为cypher外壳;另一种是采用py2neo自己的数据结构和编写方式,我们称为py2neo方法。 在讲这两种方式之前,先提一下通用的pull()、push()等操作。 因为常需要从服务器端取数据,同时编写程序时本地也会产生Node,Relationship等数据,因此需要二者的版本协同。常规的处理方法如下:

How to insert Bulk data into Neo4j using Python

会有一股神秘感。 提交于 2019-12-06 06:21:50
问题 I want to insert some data into Neo4j using py2neo . Link to data file. I am new to Neo4j . Can someone tell me how to insert bulk data into Neo4j .Actually i want to do performance testing of Neo4j ..... I have tried this but this is just for small data set ... from pprint import pprint from py2neo import neo4j,node, rel graph_db = neo4j.GraphDatabaseService() def insert_data(): die_hard = graph_db.create( node(name="Bruce Willis"), node(name="John McClane"), node(name="Alan Rickman"), node

The right way to hydrate lots of entities in py2neo

喜欢而已 提交于 2019-12-06 03:27:52
this is more of a best-practices question. I am implementing a search back-end for highly structured data that, in essence, consists of ontologies, terms, and a complex set of mappings between them. Neo4j seemed like a natural fit and after some prototyping I've decided to go with py2neo as a way to communicate with neo4j, mostly because of nice support for batch operations. This is more of a best practices question than anything. What I'm getting frustrated with is that I'm having trouble with introducing the types of higher-level abstraction that I would like to in my code - I'm stuck with

Choices validation in WTForms does not update when database does

点点圈 提交于 2019-12-06 02:49:17
问题 I understand the SelectField method in WTForms takes can argument choices which has the form... choices=[("value1", "display of value 1"), ("value2", "display of value 2")] I need to populate my choices based on a call to the database. I'm using neo4j as my backend, so I can't use modelforms or the other built-in solutions for populating data in a form. def get_list_of_things(): query = 'start n = node:things("*:*") return ID(n), n.display_name;' t = cypher.execute(cdb, query)[0] for x in t:

How to combine cypher queries into a transaction in Py2neo v3

家住魔仙堡 提交于 2019-12-06 01:37:24
In py2neo v2.0, it was possible to use a transaction to execute Cypher statements: tx=graph.cypher.begin() tx.append("MERGE (n:Process {proc_nm : {proc_nm}}) ON CREATE SET n.count = 1 ON MATCH SET n.count = n.count +1", {proc_nm : 'wibble'}) tx.commit When processing complex files this allows very fast updates to be made to the Neo4J database. In py2neo v3.0 the syntax has changed to: graph.run(("MERGE (n:Process {proc_nm : {proc_nm}}) ON CREATE SET n.count = 1 ON MATCH SET n.count = n.count +1", {proc_nm : 'wibble'})) This means that I can run the cypher statements singly but the performance

Slow performance bulk updating relationship properties in Neo4j

冷暖自知 提交于 2019-12-05 15:55:58
I'm struggling to efficiently bulk update relationship properties in Neo4j. The objective is to update ~ 500,000 relationships (each with roughly 3 properties) which I chunk into batches of 1,000 and processing in a single Cypher statement, UNWIND {rows} AS row MATCH (s:Entity) WHERE s.uuid = row.source MATCH (t:Entity) WHERE t.uuid = row.target MATCH (s)-[r:CONSUMED]->(t) SET r += row.properties however each batch of 1,000 nodes takes around 60 seconds. There exists an index on UUID property for the :Entity label, i.e. I've previously run, CREATE INDEX ON :Entity(uuid) which means that