EzDevInfo.com

neo4j-rest-client

Object-oriented Python library to interact with Neo4j standalone REST server neo4j-rest-client’s documentation — neo4j-rest-client 2.0.0 documentation

Change neo4j database location within python

I understand that I can set the database location by changing the following line in /conf/neo4j-server.properties

org.neo4j.server.database.location=data/graph.db

Is it possible to do this within a python instance? For example, I'm using neo4jrestclient

neo4j_login = {
    "username" : "neo4j",
    "password" : "supersecret",
    "url" : "http://localhost:7474"
}

from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase(**neo4j_login)

Can I somehow set the location of the database I'd like to open to a local directory?


Source: (StackOverflow)

find pattern relationships using rest cypher

how can I find pattern relationships using rest cypher?

My query running on terminal :-

MATCH (n)<-[:DEPENDS_ON*]-(dependent) RETURN n.host as Host,

count(DISTINCT dependent) AS Dependents ORDER BY Dependents DESC LIMIT 1**

output is :-

+--------------------+ | Host | Dependents |

+--------------------+ | "SAN" | 20 | +--------------------+

where as equivalent query with rest :-

String query = "{\"query\" : \"MATCH (website)<-[rel]-(dependent) " +
                "WHERE TYPE(rel) = {rtype} RETURN website.host as Host," +
                "count(DISTINCT dependent) AS Dependents ORDER BY Dependents DESC LIMIT 1" +
                " \", \"params\" : {\"rtype\" : \"DEPENDS_ON*\"}}";     

and output is empty(no records) !!!

Any help appreciated.

P.S- When we dont use "*" in our query everything goes ok. IE both queries give same result


Source: (StackOverflow)

Advertisements

How to export neo4j data to csv/json

I am using Neo4j Python REST Client and I want to use D3.js for the visualisation of my data. I am creating the data like this:

gdb = GraphDatabase("http://localhost:7474/db/data/")
alice = gdb.nodes.create(name="Alice",isTeacher=False)
bob = gdb.nodes.create(name="Bob"isTeacher=True)
bob.relationships.create("Knows", alice,strength = 0.4)

Is it possible to transform my data into json/csv in order to use that in D3? Thanks in advance.


Source: (StackOverflow)

SET label : pass label name as parameter

I have a query like this:

unwind {data} as row with row MERGE (p:Book{guid:row.bookGuid}) set p.name=row.name, p:Science

I want to pass the label 'Science' as a parameter as this label is not same for all the rows which I am passing in {data}.

I tried below query, but this is throwing syntax error.

with parameter like: { guid:1, name:"testName1",label1:"Histroy"}

unwind {data} as row with row MERGE (p:Book{guid:row.bookGuid}) set p.name=row.name, p:row.label1

Any workaround?

Thanks


Source: (StackOverflow)

neo4j: creating the same relationship towards multiple nodes using neo4j-restclient

Using the Python neo4j-restclient, I'm trying to find out if I can simplify the creation of the same relationship emanating from the same node to different nodes. So currently, I have

alice = g.nodes.create(name='Alice')
bob = g.nodes.create(name='Bob')
chuck = g.nodes.create(name='Chuck')
darryl = g.nodes.create(name='Darryl')
eve = g.nodes.create(name='Eve')

alice.relationships.create("is friends with", bob)
alice.relationships.create("is friends with", chuck)
alice.relationships.create("is friends with", darryl)
alice.relationships.create("is friends with", eve)

Is there any simpler way to do this, without having to invoke relationships.create a dozen times?


Source: (StackOverflow)

No Module Named neo4j in Travis-CI integrated with Python Django

I have built a small python application in Django framework, with Neo4j database hosted on Graphene db. I am integrating Travis-CI for continuous integration with the application on github, however, I am stuck on getting an error in Travis like: ImportError: No module named 'neo4j' Below is my .travis.yml file:

language: python
python:
 - "3.4"
 - "2.7"
# command to install dependencies
install:
 - pip install -q Django==$DJANGO_VERSION
 - pip install py2neo
 - pip install neo4django
 - pip install -r requirements.txt
# command to run tests
script: python eb_django_app/neo4j/manage.py test
env:
 - DJANGO_VERSION=1.8.3
branches:
 only:
  - master

manage.py :

import os
import sys
from py2neo import neo4j
from py2neo import ServiceRoot
graphenedb_url = os.environ.get("graphene db url", "http://localhost:7474/")
graph = ServiceRoot(graphenedb_url).graph
if __name__ == "__main__":
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "neo4j.settings")
  from django.core.management import execute_from_command_line
  execute_from_command_line(sys.argv)

The folder structure of python application is:

eb_django_app
    |_ .travis.yml
    |_ requirements.txt
    |_ eb_django_app
       |_python codebase
       |_manage.py
       |_neo4j
           |_manage.py
           |_tests.py

I am new to both Travis and Python. Am i missing something? Can someone please help me out with a solution to resolve this error, would really appreciate some immediate response?


Source: (StackOverflow)

Lucene full-text index: all indexed nodes with same score?

I have been trying solving this issue since days.

I want to do a START query against full-text, ordered by relevance, so to paginate results.

Gladly, I finally found this thread on full-text indexing and neo (and using python as driver).

[https://groups.google.com/forum/#!topic/neo4j/9G8fcjVuuLw]

I had imported my db with batch super-importer, and got a reply of @Michaelhunger who kindly noticed there was a bug, all scores would had been imported the same value.

So, now I am recreating the index, and checking the score via REST (&order=score)

http://localhost:7474/db/data/index/node/myInde?query=name:myKeyWord&order=score

and noticed that entries have still the same score.

(You've got to do an ajax query to see it cause if you use the web console you won't see all data!!)

My code to recreate a full-text lucene index, having each node property 'name': (here using neo4j-rest-client, but I will try also with py2neo as in the Google discussion):

from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase("http://localhost:7474/db/data/")

myIndex =  gdb.nodes.indexes.create("myIndex", type="fulltext", provider="lucene")

myIndex.add("name",node.get("name"),node)

results:

http://localhost:7474/db/data/index/node/myInde?query=name:DNA&order=score

data Object {id: 17062920, name: "DNA damage theory of aging"}
VM995:10 **score 11.097855567932129**
...
data Object {id: 17022698, name: "DNA (film)"}
VM995:10 **score 11.097855567932129**

In the documentation: [http://neo4j.com/docs/stable/indexing-lucene-extras.html#indexing-lucene-sort] it is written that Lucene does the sorting itself very well, so I understood it creates a ranking by itself in import; it does not.

What am I doing wrong or missing?


Source: (StackOverflow)

HTML Generation using neo4jrestclient

So I was using the neo4jrestclient, and I noticed that in the class of QuerySequece, there's a .to_html()function (https://github.com/versae/neo4j-rest-client/blob/master/neo4jrestclient/query.py) However, when I try using it I get the 'Unable to display the graph or the table' error.

I haven't found a working example of it. I was wondering if anyone has gotten this working.

Much thanks appreciated.


Source: (StackOverflow)

neo4jrestclient check relations

I am using neo4jrestclient with python. I would like to check if two nodes have a specific relation.

For example

alice = gdb.nodes.create(name="Alice", age=30)
bob = gdb.nodes.create(name="Bob", age=25)
alice.labels.add("Person")
bob.labels.add("Person")
alice.relationships.create("Knows", bob)

How can I check if Alice has the "Knows" relation with Bob? I tried to find something from documentation with no luck.


Source: (StackOverflow)

How to delete relationships in Neo4j using python neo4j-rest-client library?

I am not able to find the API to delete relationships from a Node, I could only find a create method. Please let me know how I can delete it.


Source: (StackOverflow)

neo4jrestclient - query get id

I am using the neo4jrestclient library.

from neo4jrestclient.client import GraphDatabase
from neo4jrestclient import client
from neo4jrestclient import query
gdb = GraphDatabase("http://localhost:7474/db/data/")
q = """MATCH n RETURN n;"""
result = gdb.query(q=q)
print(result[0])

When I am executing the query "MATCH n RETURN n, the output is:

[{
'all_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all', 
'all_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all/{-list|&|types}', 
'self': 'http://localhost:7474/db/data/node/1131', 
'labels': 'http://localhost:7474/db/data/node/1131/labels', 
'properties': 'http://localhost:7474/db/data/node/1131/properties', 
'create_relationship': 'http://localhost:7474/db/data/node/1131/relationships',
'outgoing_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out', 
'data': {
  'title': 'title', 
  'name': 'Poludnie'
}, 
'incoming_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in/{-list|&|types}', 
'property': 'http://localhost:7474/db/data/node/1131/properties/{key}', 
'paged_traverse': 'http://localhost:7474/db/data/node/1131/paged/traverse/{returnType}{?pageSize,leaseTime}', 
'incoming_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in', 
'outgoing_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out/{-list|&|types}', 
'traverse': 'http://localhost:7474/db/data/node/1131/traverse/{returnType}'}]

I see that the node’s id = 1131. The question is: can I obtain this id in raw forms without those links? I would like to have only the id together with the value of the ‘data’ field.


Source: (StackOverflow)

Neo4j on aws instance with java Rest Binding

I have created an AWS EC2 instance running Neo4j(Community AMI) and i have connected to the end point successfully through the browser.now i want to access my db from java application through the Restbinding

    `RestAPI graphDB = new RestAPIFacade("EC2_ENDPOINT:7474/db/data/");
    QueryEngine engine=new RestCypherQueryEngine(graphDB); 

     QueryResult<Map<String,Object>> result = engine.query("start n=node(*) return count(n) as total", Collections.EMPTY_MAP); 

     Iterator<Map<String, Object>> iterator=result.iterator(); 

     if(iterator.hasNext()) { 

       Map<String,Object> row= iterator.next(); 

       System.out.print("Total nodes: " + row.get("total")); ` 

i have tested this code for localhost and got results but when i try this this Exception occurs!

Exception in thread "main" java.lang.RuntimeException: Error reading as JSON '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /db/data/cypher. Reason:
<pre>    Not Found</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>   

can anyone help me here. Thank you


Source: (StackOverflow)

TypeError neo4jrestclient append() got an unexpected keyword argument 'data'

I am using neo4jrestclient for Neo4j in python and locally it works perfectly. When I host it using webfaction it returns the following error:

TypeError at /add/
append() got an unexpected keyword argument 'data'
Django Version: 1.6.1
Exception Type: TypeError
Exception Value:    
append() got an unexpected keyword argument 'data'
Exception Location: /home/kokos/lib/python2.7/neo4jrestclient/client.py in create, line 1036

I have no clue where the problem might be. Thanks in advance.


Source: (StackOverflow)