Extract and Store Subgraph - Example


Ravee <raveendranat...@...>
 

Hi,

I'm using Gremlin Server in the JanusGraph package and trying to extract a subgraph.

:> sg = g.V(86056).repeat(__.outE().subgraph('subGraph').inV()).until(outE().count().is(0)).cap('subGraph').next()
==>tinkergraph[vertices:11 edges:10]
:> sg.io(IoCore.graphml()).writeGraph("/tmp/mygraph.xml")

or 

:> g.V(86056).repeat(__.outE().subgraph('subGraph').inV()).until(outE().count().is(0)).cap('subGraph').next().io(IoCore.graphml()).writeGraph("/tmp/mygraph.xml")

Appreciate some help to get around this. Am I missing any configuration or setting to enable subgraph to be written as graphml?

-Ravee


Jason Plurad <plu...@...>
 

Can you provide more details on what is going wrong? It is a bit hard to debug your situation without any graph data.

I tried this...

$ ./bin/janusgraph.sh start

Forking Cassandra...

Running `nodetool statusthrift`.. OK (returned exit status 0 and printed string "running").

Forking Elasticsearch...

Connecting to Elasticsearch (127.0.0.1:9300).. OK (connected to 127.0.0.1:9300).

Forking Gremlin-Server...

Connecting to Gremlin-Server (127.0.0.1:8182).... OK (connected to 127.0.0.1:8182).

Run gremlin.sh to connect.


$
./bin/gremlin.sh
gremlin
> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin
> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin
> GraphOfTheGodsFactory.load(graph)
==>null

gremlin> g.V().has('name', 'pluto').id()

==>4296

gremlin> g.V(4296).repeat( outE().subgraph('sg').inV().simplePath() ).until( outE().count().is(0) ).cap('sg').next().io(IoCore.graphml()).writeGraph('/tmp/mygraph.xml')
==>null
gremlin
> new File('/tmp/mygraph.xml').text
==><?xml version='1.0' encoding='UTF-8'?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">...

Notice I added a simplePath() into the repeat loop to avoid cyclic path looping. Keep in mind, I ran this all on the same machine. If you sent a command to a remote Gremlin Server, the file under /tmp would be located on the remote server, not on your client machine.

-- Jason

On Thursday, March 9, 2017 at 9:16:19 AM UTC-5, Ravee wrote:
Hi,

I'm using Gremlin Server in the JanusGraph package and trying to extract a subgraph.

:> sg = g.V(86056).repeat(__.outE().subgraph('subGraph').inV()).until(outE().count().is(0)).cap('subGraph').next()
==>tinkergraph[vertices:11 edges:10]
:> sg.io(IoCore.graphml()).writeGraph("/tmp/mygraph.xml")

or 

:> g.V(86056).repeat(__.outE().subgraph('subGraph').inV()).until(outE().count().is(0)).cap('subGraph').next().io(IoCore.graphml()).writeGraph("/tmp/mygraph.xml")

Appreciate some help to get around this. Am I missing any configuration or setting to enable subgraph to be written as graphml?

-Ravee