[Neo4j] Exporting a Neo4J graph to RDF/XML

Paul A. Jackson Paul.Jackson at pb.com
Fri Jun 4 19:37:39 CEST 2010


Thanks so much for the quick replies.  I recognize both your names from my research the last few days.

I was able to get the export to GraphML working using Blueprints and was happy with it.  I was also hoping to support RDF - not that I have a specific reason, but as I am trying to build a robust commercial product (http://www.pbinsight.com/products/data-management/data-quality-and-enrichment/enterprise-data-quality), I was basically hoping to be able to check the box.

Is it the case that an RDF export is a reasonable thing to offer, but just not as common/open/flexible, or are the problems I am running into the result of a fundamental problem with the idea?

Thanks,
-Paul

-----Original Message-----
From: user-bounces at lists.neo4j.org [mailto:user-bounces at lists.neo4j.org] On Behalf Of Marko Rodriguez
Sent: Friday, June 04, 2010 1:08 PM
To: Neo4j user discussions
Subject: Re: [Neo4j] Exporting a Neo4J graph to RDF/XML

Hi,

You can use Gremlin or just Blueprints [ http://blueprints.tinkerpop.com ] straight up. Its pretty straightforward:

http://tinkerpop.com/maven2/com/tinkerpop/blueprints/0.1.1/api/

e.g.

GraphMLReader.inputGraph(Graph graph, InputStream graphmlStream)

GraphMLWriter.outputGraph(Graph graph, OutputStream graphmlStream)

If you do use Gremlin, use Gremlin 0.2.2 in downloads [ http://github.com/tinkerpop/gremlin/downloads ] as the repository's code is being re-written right now for Gremlin 1.0 coming out soon. In other words, don't build from source right now.

Good luck,
Marko.

http://tinkerpop.com
http://markorodriguez.com


On Jun 4, 2010, at 10:56 AM, Peter Neubauer wrote:

> Paul,
> I would recommend to export the graph to GraphML. Currently, the
> easiest way would be to have your graph opened through Gremlin,
> http://gremlin.tinkerpop.com:
> 
> 
> java -jar ~/code/gremlin/target/gremlin-xxx-standalone.jar
> 
>         \,,,/
>         (o o)
> -----oOOo-(_)-oOOo-----
> gremlin> $_g := neo4j:open('path/to/neo4j-db')
> gremlin> g:save('export.xml')
> 
> 
> This will give you export.xml as GraphML that you can load with
> 
> gremlin> g:load('export.xml')
> 
> back into a new graph.
> 
> Would that work?
> 
> Cheers,
> 
> /peter neubauer
> 
> COO and Sales, Neo Technology
> 
> GTalk:      neubauer.peter
> Skype       peter.neubauer
> Phone       +46 704 106975
> LinkedIn   http://www.linkedin.com/in/neubauer
> Twitter      http://twitter.com/peterneubauer
> 
> http://www.neo4j.org               - Your high performance graph database.
> http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
> 
> 
> 
> On Fri, Jun 4, 2010 at 5:26 PM, Paul A. Jackson <Paul.Jackson at pb.com> wrote:
>> Disclaimer: I am new to this (but am committed to working the problem).
>> 
>> I am interested in exporting my neo4j graphs to any of the supported xml formats (n3, turtle, etc.). I am interested in this because I am assuming that doing so will increase the interoperability of my graph database. Having spent some time on this I am beginning to question that assumption (because I perceive that RDF has restrictions that my graphs do not - requirements for URIs, each must be connected to something, etc.) I am interested in feedback on that assumption. That said, I am having a more immediate problem just getting the data into an RDF format. I have tried using neo4j->rdf->sail->sesame but didn't find much to be gained beyond the RDF layer. The closest I was able to achieve this was the following code, which does not work, I think because RDFStore.getStatements is not implemented for cases where both the subject and object are wildcards - it returns an iterable to an empty set.
>> 
>>    graph = new EmbeddedGraphDatabase(physicalPath);
>>    indexService = new LuceneIndexService(graph);
>>    rdfStore = new VerboseQuadStore(graph, indexService);
>>    ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>    RDFWriter rdfWriter = Rio.createWriter(RioFormat.getRDFFormat(ExportFormat.TURTLE), bos);
>>    WildcardStatement wildcardStatement = new WildcardStatement(new Wildcard("?s"), new Wildcard("?p"), new Wildcard("?o"), new Wildcard("?g"));
>>    Iterable<CompleteStatement> statements = rdfStore.getStatements(wildcardStatement, false);
>> 
>>    Transaction tx = graph.beginTx();
>>    try
>>    {
>>      rdfWriter.startRDF();
>>      for (CompleteStatement neoStatement : statements)
>>      {
>>        Statement sailStatement = GraphDatabaseSesameMapper.createStatement(neoStatement, true);
>>        rdfWriter.handleStatement(sailStatement);
>>      }
>>      rdfWriter.endRDF();
>>    }
>>    catch (RDFHandlerException e)
>>    {
>>      tx.failure();
>>      throw new GraphException("Exception thrown while exporting graph database " + getName(), e);
>>    }
>>    finally
>>    {
>>      tx.finish();
>>    }
>>    String result = bos.toString();
>> 
>> What is the best/easiest/recommended way to do this? Is it an edge case that most people wouldn't want to do - dumping the whole db to xml? Is there an approach that doesn't start with a query (like something that uses graph.listAllNodes())?
>> 
>> On a side note, I was able to get GraphML working using the 0.1.2-SNAPSHOT version of tinkerpop's blueprints package.
>> 
>> Thanks in advance.
>> 
>> -Paul
>> _______________________________________________
>> Neo4j mailing list
>> User at lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>> 
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

_______________________________________________
Neo4j mailing list
User at lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user



More information about the User mailing list