Gephi finds no node/relation properties on import - neo4j

I want to visualize my Neo4j dataset with Gephi. After installing apoc and get it working, I called call apoc.export.graphml.all("/tmp/test2.graphml",{}) and I get the right file. Now I import/open this .graphml-file in Gephi 0.9.1 but in the import-window I can´t see any properties. Also in the graph itself there´re no properties on the nodes / relations.
Does anyknow know, what I´m doing wrong or have I forgot to set the right configuration-parameters?
Thanks in advance
UDPATE
this is my procedure call:
call apoc.export.graphml.all("/tmp/test2.graphml",{}) yield nodes, relationships, properties, time
this is the snapchot from the Neo4j browser
I´ve loaded this file from my server and openend it in Gephi, resulted in this:
Like you see, my properties are still not there...

Apoc has a custom procedure, that exports data to Gephi in one single step. You will need to download a graph streaming plugin for Gephi,so you will be able to easily export data from Neo4j to Gephi using apoc.gephi procedures.
Example:
MATCH path = (:Person)-[:KNOWS]->(:Person)
CALL apoc.gephi.add(null,'workspace1',path,'weight') yield nodes
RETURN distinct("success")
Check out the docs and this tutorial for more info.

Related

how to let neo4j NSMNTX respect rdf:ID when importing rdf from multiple sources

I am trying to import multiple rdf files into neo4j as described here
My problem is that even though elements have the same rdf:ID they end up being imported as different neo4j nodes with different uris prefixed by the different file names like file:/x.xml#_00141f6c-69b1-4a1a-a83b-333d0bb9d586 and file:/y.xml#_00141f6c-69b1-4a1a-a83b-333d0bb9d586.
I have tried to use:
call semantics.addNamespacePrefix("local","file:/x.xml#")
call semantics.addNamespacePrefix("local","file:/y.xml#")
before importing but to no avail. I have additionally tried to set handleVocabUris: "MAP" as an option for the import function.
Is there an import option that I am missing which allows these nodes to be unified? Is there generally an elegant way to reunify them after importing?
My current workaround is to copy each file into a temp file before loading so that the prefixes are the same. Neo4j joins the nodes with the same uri into one, which is exactly what I need.
Still happy to hear about an elegant way to do this though..

Importing data from two files into neo4j using LOAD CSV

I am trying to import data into neo4j using LOAD CSV
The resource file contains names of all the nodes I need to create
resource1
resource2
resource3
In another file I have all the properties of that resource
resource1,name,xyz
resource1,year,1920
resource1,age,100
resource2,length,300
resource2,age,30
I Managed to load the nodes into neo4j but how do I import the second file so that I can add the data to that particular node as properties, I tried setting the key dynamically
USING PERIODIC COMMIT
LOAD CSV FROM 'file:///infobox.csv' AS line
MERGE (:Node{line[1]:line[2]})
neo4j doesn't allow setting the key dynamically?
How do I solve this?
Natively, Neo4j doesn't allow setting the key dynamically. But you can install APOC Procedures use apoc.create.setProperty to do this.
Try something like:
USING PERIODIC COMMIT
LOAD CSV FROM 'file:///infobox.csv' AS line
// match the node by resource1, resource2, etc
MATCH(node:Node{resource_id : line[0]})
CALL apoc.create.setProperty(node, line[1], line[2])
RETURN *
Note: Remember to install APOC procedures according the version of Neo4j you are using. Take a look in the Version Compatibility Matrix.

Unable to export query results as csv in neo4j

I have an employee database with 1800 employees and 45000 messages in between them. I am trying to export the results of the following query into a csv file by clicking the export option in the neo4j browser.
LOAD CSV WITH HEADERS FROM
'file:///employees.csv' AS line
WITH line
MATCH(e:Employee{pkey:line.profile_key})-[r:Message]->(b:Employee) RETURN
e.pkey, b.pkey, COUNT(r)
ORDER BY e.pkey;
But its not working. I only get the initial 100 rows.I have also changed the number of rows to 10000 in the browser settings, but then again after the execution of the query my browser stops responding and closes automatically. I am using neo4j community edition 3.2.1 on windows. Is there any other way to export the results other than the browser option in windows? Thanks in advance!
You might want to use the APOC procedures and run them from the Cypher shell. Example :
neo4j> CALL apoc.export.csv.query("MATCH(p:Part) RETURN p.name","/var/tmp/parts.csv", {});
This does require you to setup the apoc plugin and add the following parameter to neo4j.conf
apoc.export.file.enabled=true
Hope this helps,
Tom

Neo4j APOC import error

I have a data model that starts with a single record, this has a custom "recordId" that's a uuid, then it relates out to other nodes and they then in turn relate to each other. That starting node is what defines the data that "belongs" together, as in if we had separate databases inside neo4j. I need to export this data, into a backup data-set that can be re-imported into either the same or a new database with ease
After some help, I'm using APOC to do the export:
call apoc.export.cypher.query("MATCH (start:installations)
WHERE start.recordId = \"XXXXXXXX-XXX-XXX-XXXX-XXXXXXXXXXXXX\"
CALL apoc.path.subgraphAll(start, {}) YIELD nodes, relationships
RETURN nodes, relationships", "/var/lib/neo4j/data/test_export.cypher", {})
There are then 2 problems I'm having:
Problem 1 is the data that's exported has internal neo4j identifiers to generate the relationships. This is bad if we need to import into a new database and the UNIQUE IMPORT ID values already exist. I need to have this data generated with my own custom recordIds as the point of reference.
Problem 2 is that the import doesn't even work.
call apoc.cypher.runFile("/var/lib/neo4j/data/test_export.cypher") yield row, result
returns:
Failed to invoke procedure apoc.cypher.runFile: Caused by: java.lang.RuntimeException: Error accessing file /var/lib/neo4j/data/test_export.cypher
I'm hoping someone can help me figure out what may be going on, but I'm not sure what additional info is helpful. No one in the Neo4j slack channel has been able to help find a solution.
Thanks.
problem1:
The exported file does not contain any internal neo4j ids. It is not safe to use neo4j ids out of the database, since they are not globally unique. So you should not use them to transfer data from one database to another.
If you are about to use globally uniqe ids, you can use an external plugin like GraphAware UUID plugin. (disclaimer: I work for GraphAware)
problem2:
If you cannot access the file, then possible reasons:
apoc.import.file.enabled=true is not set in neo4j.conf
os level
permission is not set

Where to run neo4j spatial queries and code?

Beeing till now a RDBMS user its difficult for me to understand the interface of neo4j server when it comes using spatial plugin.
I am used to the interfaces of oracle spatial and postgis in which someone can use the provided gui to create a table with geometry etc.
I have two questions.
1) How can I create a node in neo4j server (I am using version 1.9) with spatial features (coordinates)I read the manual from here:
http://neo4j-contrib.github.io/spatial/
and I know that I have to create a spatial index, then create a node and later to add the node to the index. But doing this through the console of neo4j 1.9 is not efficient. Is there an interface which I can use to do this?
2) In this website: http://neo4j-contrib.github.io/spatial/#spatial-import-shapefile
they show a way to import shapefiles in neo4j. What I don't understand (might besimple but as I said all these things are new to me) is where should I execute this code.
GraphDatabaseService database = new EmbeddedGraphDatabase(databasePath);
try {
ShapefileImporter importer = new ShapefileImporter(database);
importer.importFile("shp/highway.shp", "highway", Charset.forName("UTF-8"));
} finally {
database.shutdown();
}
Although neo4j and its spatial extension is very promising and interesting I think the community is very small and the existing examples very few. I hope I get some help.
Thank you.
D.
For a very clear explanation I kindly suggest you to visit this post: http://www.markhneedham.com/blog/2013/03/10/neo4jcypher-finding-football-stadiums-near-a-city-using-spatial/
All you have to do is adding a property to your nodes as for example: { "wtk": "POINT(-2.20024 53.483)" }. If you're familiar with java or some other language you could implement a small piece of code to create these nodes and add them to the index, as Mark did.
I also wrote something on my blog: http://inserpio.wordpress.com/2014/04/03/artworks-spatial-search/
Once again, the code you pasted have to be execute as a simple java program that connects to the graph db and import shape files with a well-known format.
Finally you'll be able to inquiry your node by executing Cypher queries like:
start m=node:museumLocation('withinDistance:[51.5086,-0.1283,0.1]') return m;
where "museumLocation" is the index name, (51.5086,-0.1283) is the center of a circle, 0.1 is the radius within it you want to find some museums.
Cheers,
Lorenzo

Resources