jrtom/jung

Save common.graph.Network to database

Opened this issue · 2 comments

Hello,
I want to save my common.graph.Network to some persistent storage.
Is there any way I could do that?

Thanks,
Atul.

Hi @atulgirishkumar! I see that @jrtom hasn't responded yet, so I thought that I'd chip in my thoughts.

At the moment, JUNG 3.0 is still in development, so I understand that either there isn't a way in JUNG to save a common.graph.Network to disk, or that it's still in development. (I don't know if you know this, but common.graph.Network is actually a class from Guava.)

However, if we take JUNG out of the picture, then I can think of two ways that you could save a given Guava Network:

  1. Try serializing it to JSON with GSON or Jackson, and then saving the JSON as a string in your database.

    Then use GSON/Jackson to deserialize the JSON back into a network when needed.

    (If you decide to use GSON, then this link in the user guide looks promising: https://github.com/google/gson/blob/master/UserGuide.md#custom-serialization-and-deserialization)

  2. Use JGraphT's support for adapting Guava graphs, and then serialize the JGraphT adapter to a GraphViz DOT string using JGraphT's DOTExporter class as in the JGraphT user guide.

    Then when you want to deserialize the DOT string back into a network, create an empty Guava network wrapped in a JGraphT adapter, and then use JGraphT's DOTImporter class to deserialize the DOT string into the JGraphT adapter. Then work with the underlying Guava network straight afterwards as you see fit.

I realise that my description above is a bit complicated, so if you need help understanding or if you need code examples, then feel free to respond and I'll happily clarify things.

I hope this helps! :)

jrtom commented

@atulgirishkumar Sorry for the delay in response. Work was kind of crazy at the time that you posted your question. :)

JUNG 3.0 has not yet been released, but the current snapshot has a couple of different mechanisms in the io package that you could use: PajekNet{Writer, Reader} and GraphML{Writer, Reader}: https://github.com/jrtom/jung/tree/master/jung-io/src/main/java/edu/uci/ics/jung/io

We may change the APIs somewhat before our final release, but the basic capabilities in those classes should remain the same.

Hope this helps.