Exporting graph in to a file and viewing in Gephi

1,565 views
Skip to first unread message

Dilan Ranasinghe

unread,
Feb 14, 2018, 2:54:51 AM2/14/18
to JanusGraph users
Hi,

I need to export graph in to a file and view in Gephi.
As I understood,  possible ways to export a graph from gremlin console is as graphml, graphson or gyro.
But, since my graph has multi valued properties gremlin console complains when i try to export it as a graphml file.
I was successful in exporting as a json file. But Gephi doesn't accept json.
So my question is, is there a way to export a graph using gremlin console as a csv or as any other format supported by Gephi  (GEXF, GraphML, Pajek NET, GDF, GML, Tulip TLP, CSV)?

Thanks,
Dilan

Stephen Mallette

unread,
Feb 14, 2018, 7:06:31 AM2/14/18
to JanusGraph users
The GraphMLWriter doesn't support multi-properties because GraphML doesn't have such support in their specification and thus you get:

gremlin> graph = TinkerFactory.createTheCrew()
==>tinkergraph[vertices:6 edges:14]
gremlin> graph.io(graphml()).writeGraph('/tmp/crew.xml')
Multiple properties exist for the provided key, use Vertex.properties(location)
Type ':help' or ':h' for help.
Display stack trace? [yN]

I think that the only work around is to subgraph(), convert the multi-properties to single properties and then export the subgraph to GraphML.

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/590eba70-8e86-4893-a226-4551e7684542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dilan Ranasinghe

unread,
Feb 14, 2018, 8:32:37 PM2/14/18
to JanusGraph users
Thank you Stephen.

Does that mean I can use a gremlin query to convert multi properties in to subgraph and then export?
Can you please provide me a gremlin sample for doing that?

Thanks,
Dilan.


On Wednesday, February 14, 2018 at 8:06:31 PM UTC+8, Stephen Mallette wrote:
The GraphMLWriter doesn't support multi-properties because GraphML doesn't have such support in their specification and thus you get:

gremlin> graph = TinkerFactory.createTheCrew()
==>tinkergraph[vertices:6 edges:14]
gremlin> graph.io(graphml()).writeGraph('/tmp/crew.xml')
Multiple properties exist for the provided key, use Vertex.properties(location)
Type ':help' or ':h' for help.
Display stack trace? [yN]

I think that the only work around is to subgraph(), convert the multi-properties to single properties and then export the subgraph to GraphML.
On Wed, Feb 14, 2018 at 2:54 AM, Dilan Ranasinghe <dila...@gmail.com> wrote:
Hi,

I need to export graph in to a file and view in Gephi.
As I understood,  possible ways to export a graph from gremlin console is as graphml, graphson or gyro.
But, since my graph has multi valued properties gremlin console complains when i try to export it as a graphml file.
I was successful in exporting as a json file. But Gephi doesn't accept json.
So my question is, is there a way to export a graph using gremlin console as a csv or as any other format supported by Gephi  (GEXF, GraphML, Pajek NET, GDF, GML, Tulip TLP, CSV)?

Thanks,
Dilan

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.

Stephen Mallette

unread,
Feb 15, 2018, 7:43:10 AM2/15/18
to JanusGraph users
I was referring to subgraph() step:


so yes, you would do this with Gremlin. using The Crew toy graph i first get the "develops" subgraph:

gremlin> graph = TinkerFactory.createTheCrew()
==>tinkergraph[vertices:6 edges:14]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]
gremlin> subgraph = g.V().hasLabel('person').outE('develops').subgraph('sg').cap('sg').next()
==>tinkergraph[vertices:5 edges:5]
gremlin> sg = subgraph.traversal()
==>graphtraversalsource[tinkergraph[vertices:5 edges:5], standard]

in this case "location" is a multi-property on "person" vertices:

gremlin> sg.V().hasLabel('person').valueMap()
==>[name:[marko],location:[san diego,santa cruz,brussels,santa fe]]
==>[name:[stephen],location:[centreville,dulles,purcellville]]
==>[name:[matthias],location:[bremen,baltimore,oakland,seattle]]

then just write some Gremlin on the subgraph to flatten the multi-properties - here's the pattern that strips out all but the most recently added "location":

gremlin> sg.V().hasLabel('person').
......1>    map(properties('location').
......2>        group().
......3>          by(key()).
......4>          by(value()))
==>[location:santa fe]
==>[location:purcellville]
==>[location:seattle]

Note that i'm relying on TinkerGraph ordering here - not sure how JanusGraph will produce the subgraph so you might need to be smarter about how you choose the value from the multilist that you want. The traversal above was just meant to show the mechanics of how to flatten multiproperties to a single property, but you then need to write them back to the subgraph:

gremlin> sg.V().hasLabel('person').as('p').
......1>    map(properties('location').
......2>        group().
......3>          by(key()).
......4>          by(value())).as('n').
......5>    select('p').
......6>    property(select('n').by(keys).unfold(),
......7>             select('n').by(values).unfold())
==>v[1]
==>v[7]
==>v[8]
gremlin> sg.V().hasLabel('person').valueMap()
==>[name:[marko],location:[santa fe]]
==>[name:[stephen],location:[purcellville]]
==>[name:[matthias],location:[seattle]]

You can now write the subgraph to graphml.
















To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/0fcfc00f-ae20-449a-aaac-a10a523324b1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages