Moving to py2neo 2.0 and streaming - py2neo

I upgraded to py2neo 2.0 and the code I used for streaming and writing results to file doesn't work any more. The error I am getting is TypeError: 'CypherResource' object is not callable.
from py2neo import Graph
from py2neo.packages.httpstream import http
http.socket_timeout = 9999
graph = Graph()
query="""
MY QUERY
"""
result=graph.cypher(graph,query)
with open('myfile','w') as f:
for record in result.stream():
v=record.values
I assume the error is in graph.cypher(graph,query), but I was not successful in fixing the error.

You are using Graph.cypher incorrectly. This is an object with execution and transaction management methods, not a callable itself. Please read the docs at:
http://py2neo.org/2.0/cypher.html

Related

Graph Data Science Error (APOC Metadata Procedure Unavailable)

I have imported my data into my dbms and installed the plugins APOC (4.2.0.0) and the Graf Data Science Library (1.4.1).
When I open the playground i get the following error:
error-msg
I added following lines into my neo4j config,
dbms.security.procedures.unrestricted=jwt.security.*,apoc.*,gds.*
dbms.security.procedures.allowlist=jwt.security.*,apoc.*,gds.*
but still getting the same error.
I have done a little research and found someone with the same error and he said:
"It turned out to be a problem with the schema - I had a node with a label that had a space in it "
Is that really an option it is not working for me?
I did my import with neo4j-admin like this:
bin/neo4j-admin import --database=neo4j --id-type=INTEGER --multiline-fields=true --skip-duplicate-nodes --skip-bad-relationships=true --nodes=commits=import/nodes-commits.csv --nodes=packages=import/nodes-packages.csv --nodes=users=import/nodes-users.csv --relationships=commits=import/relationship-projects_commits.csv
with some further relationships.
I also tried then newest version of the dbms, apoc and GDS, but the same error came up.
Anybody have any idea if it can be the import or is it some other error.
Thanks a lot

Not able to save pyspark iforest model using pyspark

Using iforest as described here: https://github.com/titicaca/spark-iforest
But model.save() is throwing exception:
Exception:
scala.NotImplementedError: The default jsonEncode only supports string, vector and matrix. org.apache.spark.ml.param.Param must override jsonEncode for java.lang.Double.
Followed the code snippet mentioned under "Python API" section on mentioned git page.
from pyspark.ml.feature import VectorAssembler
import os
import tempfile
from pyspark_iforest.ml.iforest import *
col_1:integer
col_2:integer
col_3:integer
assembler = VectorAssembler(inputCols=in_cols, outputCol="features")
featurized = assembler.transform(df)
iforest = IForest(contamination=0.5, maxDepth=2)
model=iforest.fit(df)
model.save("model_path")
model.save() should be able to save model files.
Below is the output dataframe I'm getting after executing model.transform(df):
col_1:integer
col_2:integer
col_3:integer
features:udt
anomalyScore:double
prediction:double
I have just fixed this issue. It was caused by an incorrect param type. You can checkout the latest codes in the master branch, and try it again.

A apoc.import.json procedure with can't read url error

I've installed a neo4j in my lab's centOS server.I want to import a json file into neo4j.
I've already put the apoc-3.3.0.1.jar in the NEO4J_HOME/plugins and add the
apoc.import.file.enabled=true
into neo4j.conf
Then i open the web UI of neo4j with my PC(windows 10) and input the cypher
call apoc.load.json("file:///C://Users//stefen//Desktop//test.json")yield value as company
create(c:company)
with c,company
unwind company.organizationInformationList as a
set c = a
The json file is saved in my pc.
And error info is:
Failed to invoke procedure apoc.load.json: Caused by: java.lang.RuntimeException: Can't read url file:/C://Users//stefen//Desktop//test.json as json: /C:/Users/stefen/Desktop/test.json
I have no idea where is the problem.Please help me.
PS:my neo4j version is 3.3.1
I'm sorry. I have made a mistake that i forget to put the data file in my server.
Now i have solved the question.

GCE Python API: oauth2client.util:execute() takes at most 1 positional argument (2 given)

I'm trying to get started with the Python API for Google Compute Engine using their "hello world" tutorial on https://developers.google.com/compute/docs/api/python_guide#setup
Whenever making the call response = request.execute(auth_http) though, I get the following error signaling that I can't authenticate:
WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given)
I'm clearly only passing one positional argument (auth_http), and I've looked into oauth2client/util.py, apiclient/http.py, and oauth2client/client.py for answers, but nothing seems amiss. I found another stack overflow post that encountered the same issue, but it seems that in the constructor of the OAuth2WebServerFlow class in oauth2client/client.py, 'access_type' is set to 'offline' already (though to be honest I don't completely understand what's going on here in terms of setting up oauth2.0 flows).
Any suggestions would be much appreciated, and thanks in advance!
Looking at the code, the #util.positional(1) annotation is throwing the warning. Avoid it using named parameters.
Instead of:
response = request.execute(auth_http)
Do:
response = request.execute(http=auth_http)
https://code.google.com/p/google-api-python-client/source/browse/apiclient/http.py#637
I think documentation is wrong. Please use the following:
auth_http = credentials.authorize(http)
# Build the service
gce_service = build('compute', API_VERSION, http=auth_http)
project_url = '%s%s' % (GCE_URL, PROJECT_ID)
# List instances
request = gce_service.instances().list(project=PROJECT_ID, filter=None, zone=DEFAULT_ZONE)
response = request.execute()
You can do one of three things here:
1 Ignore the warnings and do nothing.
2 Suppress the warnings and set the flag to ignore:
import oauth2client
import gflags
gflags.FLAGS['positional_parameters_enforcement'].value = 'IGNORE'
3 Figure out where the positional parameter is being provided and fix it:
import oauth2client
import gflags
gflags.FLAGS['positional_parameters_enforcement'].value = 'EXCEPTION'
# Implement a try and catch around your code:
try:
pass
except TypeError, e:
# Print the stack so you can fix the problem, see python exception traceback docs.
print str(e)

AttributeError: 'TraversalDescription' object has no attribute 'evaluator'

Im trying to traversal a graph using
from neo4jrestclient.client import GraphDatabase
G = GraphDatabase("http://localhost:7474/db/data/")
# G is generated here in my program but for space purpose I removed these steps
traverser = G.traversal().evaluator(my_evaluator).traverse(root)
I borrowed my_evaluator function from stackoverflow which is
def my_evaluator(path):
# Filter on end node property
if path.end['value'] == 105:
return Evaluation.INCLUDE_AND_CONTINUE
# Filter on last relationship type
if path.last_relationship.type.name() == 'edge':
return Evaluation.INCLUDE_AND_PRUNE
# You can do even more complex things here, like subtraversals.
return Evaluation.EXCLUDE_AND_CONTINUE
When I tried to execute the code I got the following error message:
Traceback (most recent call last):
File "C:\Users\firas\Desktop\ACO_neo4j.py", line 747, in
traverser = G.traversal().evaluator(my_evaluator).traverse(root)
AttributeError: 'TraversalDescription' object has no attribute 'evaluator'
Can you help me in this please. Thanks.
Firas
You can always use a Cypher query to to the same.
The problem here is that the evaluator funcion may be borrowed from the native driver by Neo4j guys, the embedded Python driver. So far, there is some limitations on traversing the graph using the neo4-rest-client traversals. Because underneath it is using the REST interface, the only way to write a evaluator is by writing a Javascript function, AFAIK.

Resources