I have been trying to build the example GetAll neo4j server extension, but unfortunately I cannot make it work. I installed the Windows version of neo4j and run it as a server. I also installed Python neo4jrestclient and I am accessing neo4j through Python scripts. The following works fine:
from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase("http://localhost:7474/db/data/")
print gdb.extensions
It gives me "CypherPlugin" and "GremlinPlugin". I want to build the example GetAll server extension, which is Java. I am using Eclipse. I am able to create the jar file in the folder "c:\neo4j_installation_root\neo4j-community-1.7\plugins\GetAll.jar", but when I restart the neo4j server and run the neo4jrestclient it does not show the GetAll server extension. I searched a lot, but in vain. I have lots of experience with C++ and Python, but new to Java. I will really appreciate some help to be able to build neo4j server extensions. It is critically important for my evaluation of neo4j.
Are you sure there is a META-INF/services etc listing the plugin class, and the jar file is created with intermediate dirs (which is not the default in Eclipse export settings) so dirs are seen by the classloader?
Check out the tips at http://docs.neo4j.org/chunked/snapshot/server-plugins.html
You can do get-all with Bulbs (http://bulbflow.com) without building an extension:
>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.vertices.get_all()
>>> g.edges.get_all()
Custom models work the same way:
# people.py
from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime
class Person(Node):
element_type = "person"
name = String(nullable=False)
age = Integer()
class Knows(Relationship):
label = "knows"
created = DateTime(default=current_datetime, nullable=False)
And then call get_all on the model proxies:
>>> from people import Person, Knows
>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.add_proxy("people", Person)
>>> g.add_proxy("knows", Knows)
>>> james = g.people.create(name="James")
>>> julie = g.people.create(name="Julie")
>>> g.knows.create(james, julie)
>>> g.people.get_all()
>>> g.knows.get_all()
Related
Where is MobyLCPSolver?
ImportError: cannot import name 'MobyLCPSolver' from 'pydrake.all' (/home/docker/drake/drake-build/install/lib/python3.8/site-packages/pydrake/all.py)
I have the latest Drake and cannot import it.
Can anyone help?
As of pydrake v1.12.0, the MobyLcp C++ API is not bound in Python.
However, if you feed an LCP into Solve() then Drake can choose Moby to solve it. You can take advantage of this to create an instance of MobyLCP:
import numpy as np
from pydrake.all import (
ChooseBestSolver,
MakeSolver,
MathematicalProgram,
)
prog = MathematicalProgram()
x = prog.NewContinuousVariables(2)
prog.AddLinearComplementarityConstraint(np.eye(2), np.array([1, 2]), x)
moby_id = ChooseBestSolver(prog)
moby = MakeSolver(moby_id)
print(moby.SolverName())
# The output is: "Moby LCP".
# The C++ type of the `moby` object is drake::solvers::MobyLCP.
That only allows for calling Moby via the MathematicalProgram interface, however. To call any MobyLCP-specific C++ functions like SolveLcpFastRegularized, those would need to be added to the bindings code specifically before they could be used.
You can file a feature request on the Drake GitHub page when you need access to C++ classes or functions that aren't bound into Python yet, or even better you can open a pull request with the bindings that you need.
I'm learning how to use Serverless Functions, I'm working trying to connect a Watson assistant through webhooks using a python action that is processing a small dataset, I'm still struggling to succeed on it.
I’ve done my coding on Jupyter environment calling raw csv dataset from Github and using pandas to handle it. The issue is when I’m invoking the action into IBM Functions works 10% of the times. I did debug on Jupyter and Visual Studio environments and the code seems to be ok, but once I move the code to the IBM Functions environment it doesn't perform.
import sys
import csv
import json
import pandas as pd
location = ('Germany') #Passing country parameter for testing purpose
data = pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-24-2020.csv')
def main(args):
location = args.get("location")
for index, row in data.iterrows():
currentLoc = row['Country/Region']
if currentLoc == location:
covid_statistics = {
"Province/State": row['Province/State'],
"Country/Region": row['Country/Region'],
"Confirmed":row['Confirmed'],
"Deaths":row['Deaths'],
"Recovered":row['Recovered']
}
return {"message": covid_statistics}
else:
return {"message": "Data not available"}
I am having some issues using the Neomodel and py2neo clients with Neo4j. I have installed Neomodel and py2neo in seperate anaconda virtual environments and tested each individually. Neo4j is installed/docked using docker.
Neomodel
The code
from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,UniqueIdProperty, RelationshipTo, RelationshipFrom)
config.DATABASE_URL = 'bolt://neo4j:password#localhost:7687'
class Country(StructuredNode):
code = StringProperty(unique_index=True, required=True)
# traverse incoming IS_FROM relation, inflate to Person objects
inhabitant = RelationshipFrom('Person', 'IS_FROM')
class Person(StructuredNode):
uid = UniqueIdProperty()
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True, default=0)
# traverse outgoing IS_FROM relations, inflate to Country objects
country = RelationshipTo(Country, 'IS_FROM')
jim = Person(name='Jim', age=3).save()
jim.age = 4
jim.save() # validation happens here
jim.delete()
jim.refresh() # reload properties from neo
jim.id # neo4j internal id
While Neomodel generates the node viewed on the neo4j webapp. The node created is Jim with age=3 i.e. It does not seem to have recorded the fact that Jims age changed from 3 -> 4. Also, I am assuming that jim.delete() would have deleted the node which it did not neither. Lastly, it prompts the following error (below is a snippet of the last lines of the error).
Error
...
File "/Users/sjamal/.conda/envs/tneo/lib/python3.6/site-
packages/neomodel/core.py", line 452, in inflate
if db_property in node.properties:
AttributeError: 'Node' object has no attribute 'properties'
Now I did find this post where the user "Jack Daniel" mentioned that neomodel does not support neo4j 3. So I tried docking the Neo4j v.2.3 image but then I receive the following error (note that its a snippet of the last few lines of the error)
Error when docking image Neo4j 2.3
File "/Users/sjamal/.conda/envs/tneo/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/Users/sjamal/.conda/envs/tneo/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/Users/sjamal/.conda/envs/tneo/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
Py2neo
I started looking into using p2neo due to the issues I had with Neomodel but I cannot seem to get my configurations right.
The code
from py2neo import Node, Relationship, Graph
graph = Graph("localhost", user='neo4j', password='password', bolt=None)
alice = Node("Person", name="Alice")
bob = Node("Person", name="Bob")
alice_knows_bob = Relationship(alice, "KNOWS", bob)
graph.create(alice_knows_bob)
Error
File "/Users/sjamal/.conda/envs/py2neo_test/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 459, in acquire
connection = self.connector(address)
File "/Users/sjamal/.conda/envs/py2neo_test/lib/python3.6/site-packages/neo4j/v1/bolt.py", line 46, in <lambda>
pool = ConnectionPool(lambda a: connect(a, security_plan.ssl_context, **config))
File "/Users/sjamal/.conda/envs/py2neo_test/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 601, in connect
raise ProtocolError("Connection to %r closed without handshake response" % (address,))
neo4j.bolt.connection.ProtocolError: Connection to ('localhost', 7687) closed without handshake response
Thanks to anyone looking into this. I would be happy to receive any suggestion or explanation on how to set up Py2neo irrespective if I get Neomodel to work or not.
So I have managed to solve my issue with Py2neo but not the issue I had with Neomodel. If I do find a way to get Neomodel working I will post it and either link to this post or post as a comment in this thread.
Py2neo solution with py2neo v4.0 and neo4j v3.o
I tried various combinations, starting with neo4j 2.3 together with different versions of py2neo such as 3.1.2 and then did the same with neo4j v3.0.
I am posting my script that I used to create the node and the graph connection as I was going mad when trying to figure out if I set up the configuration poorly or there was a bug in the package, driver etc.
Py2neo script
from py2neo import Node, Relationship, Graph
graph = Graph('http://localhost:7474/db/data',user='neo4j',pass word='password1234')
tx = graph.begin()
a = Node(label='hero',name='Sabri')
tx.create(a)
tx.commit()
Outdated driver py2neo v3.1.2 in tandem with Neo4j v3.4
As discussed in this Github issue report https://github.com/neo4j/neo4j-python-driver/issues/252 the user who reported the issue was using py2neo 3.1.2 together with Neo4jv3.4. The suspicion was that it was due to an outdated driver (v1.1) that came with py2neo 3.1.2. The new distribution of Neo4j v3.4 seems to come with the new driver 1.6.
Upgrading py2neo to v4.0 and sticking to latest version of Neo4j server i.e. v3.4
When doing this I ran into a different error
File "/Users/sjamal/.conda/envs/py2neo.v4/lib/python3.6/site-packages/py2neo/internal/http.py", line 26, in <module>
from neo4j.addressing import SocketAddress
ModuleNotFoundError: No module named 'neo4j.addressing'
It was discussed in this stackoverflow thread (ModuleNotFoundError: No module named 'neo4j.addressing' and ModuleNotFoundError: No module named 'neo4j') that the issue might be that the driver 1.6 driver might have to be manually installed through pip, which I did.
pip install neo4j-driver==1.6.2
I now received a new error where TypeError was caught when calling a map object.
File "/Users/sjamal/.conda/envs/py2neo.v4/lib/python3.6/site-packages/py2neo/internal/http.py", line 74, in fix_parameters
raise TypeError("Parameters of type {} are not supported".format(type(value).__name__))
TypeError: Parameters of type map are not supported
I found this github issue posted by speters-cmri https://github.com/technige/py2neo/issues/688 which contained the following github commit (https://github.com/technige/py2neo/compare/v4...CMRI-ProCan:v4) to resolve the issue by modifying a json.py script in the py2neo package
I ran my script again to add a test node and it ran without any issues.
If you are too lazy or simply too frustrated to go through a long explanation here is a summary
1. Make sure neo4j v3.0+ is installed. I suggest you look into docker to install neo4j using a docker image
2. pip install py2neo==v4.0
3. pip install neo4j-driver==1.6.2
4. Modify json.py file as described here https://github.com/technige/py2neo/compare/v4...CMRI-ProCan:v4
5. Run py2neo script outlined above
I'm trying to import a SQLite3 database into Neo4J using batch-import. Being a Neo4J noob, I followed Max De Marzi's post : Batch Importer – Part 2.
I get this error:
# java -server -Xmx2G -jar /opt/batch-import/target/batch-import-jar-with-dependencies.jar /var/lib/neo4j/data/graph.db nodes.csv relations.csv
Usage: Importer data/dir nodes.csv relationships.csv [node_index node-index-name fulltext|exact nodes_index.csv rel_index rel-index-name fulltext|exact rels_index.csv ....]
Using: Importer /var/lib/neo4j/data/graph.db nodes.csv relations.csv
Using Existing Configuration File
..
Importing 271544 Nodes took 2 seconds
Total import time: 4 seconds
Exception in thread "main" org.neo4j.graphdb.NotFoundException: id=271565
at org.neo4j.unsafe.batchinsert.BatchInserterImpl.getNodeRecord(BatchInserterImpl.java:917)
at org.neo4j.unsafe.batchinsert.BatchInserterImpl.createRelationship(BatchInserterImpl.java:471)
at org.neo4j.batchimport.Importer.importRelationships(Importer.java:136)
at org.neo4j.batchimport.Importer.doImport(Importer.java:214)
at org.neo4j.batchimport.Importer.main(Importer.java:78)
But the node exists :
$ grep ^271565 nodes.csv
271565 'la Callas' 'n_term' 0.0
Has anyone else had this issue?
Thanks.
Can you show your file headers?
As you can see you only imported 271544 nodes. So there is no way there is a node with the node-id 271565.
The id in the relationship file refers to the row number in the nodes-file not to what is in your own "id" column (how could it know).
The only thing you can do here is to use id:id which is a special type and will force the neo4j-id's to correspond to your provided id's. And in the relationship-file use start:id, end:id.
You can try an alternate method to import bulk-data into neo4j.
First convert your database into csv files and import it into Gephi - a graph visualization tool. Then by using the Gephi plugin for neo4j database support, you should be able to export your database (from Gephi) into neo4j format.
Finally just copy the exported file into appropriate neo4j directory.
For importing database into Gephi, you will need two csv files - one with all the nodes and other with all the relationships. Follow this tutorial : http://blog.neo4j.org/2013/01/fun-with-beer-and-graphs.html
Get Gephi from here: https://gephi.org/
Get the Plugin from here : https://marketplace.gephi.org/plugin/neo4j-graph-database-support/
Hope this helps.
Can you supply your input files to test? What branch are you using?
I found a similar error reported here: https://github.com/jexp/batch-import/issues/59
Right now I'm using the neo4jrestclient python package to list extensions:
from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase("http://localhost:7474/db/data/")
ext = gdb.extensions
Is there a direct shell command I can use do this? I also don't see anything on the web interface. I'm using 1.8.
Thanks!
Since this is the top answer in Google and the accepted answer is out of date for v3.0+, here's a new answer.
On this page, they show a number of new procedures, and the one in question to get a list of all procedures in the database (including plugins) is "dmbs.procedures()", and I find it most useful to have the signature of the procedure as well as the name. The query for that is:
CALL dbms.procedures() YIELD name, signature RETURN name, signature
Run
curl -v http://localhost:7474/db/data/
From the command line. Extensions aren't available on the web interface.
You have the extensions documentation for neo4j-rest-client:
>>> gdb.extensions
{u'GetAll': <Neo4j ExtensionModule: [u'get_all_nodes', u'getAllRelationships']>}
>>> gdb.extensions.GetAll
<Neo4j ExtensionModule: [u'get_all_nodes', u'getAllRelationships']>
>>> gdb.extensions.GetAll.getAllRelationships()[:]
[<Neo4j Relationship: http://localhost:7474/db/data/relationship/0>,
<Neo4j Relationship: http://localhost:7474/db/data/relationship/1>,
<Neo4j Relationship: http://localhost:7474/db/data/relationship/2>,
<Neo4j Relationship: http://localhost:7474/db/data/relationship/3>]
In newer versions, it's
SHOW PROCEDURES yield name, description, signature