简体   繁体   中英

Creating RDF from RDF graphs

I'm trying to create RDF/XML from below RDF graph. I understand the basic concepts, like Subject/Predicate/Object, Resource, Property, Value/Literal, and based on same, I created an RDF graph.

But I want to know how to translate (convert) the same graph into RDF/XML format? Is there any tool where I generate RDF graph and it will produce RDF/XML?

I'm using Jena, since I have familiarity with Java.

图形

You didn't mention how you created the graph that you've shown an image of. If you're creating it programmatically, you can do the same using the Jena API: just create a model, create resources and add properties. The Javadocs for Jena are pretty thorough, and the Jena website has some tutorials.

In this case, however, I think the easiest course of action is to just write the graph using a human-readable-writable format like Turtle, and then to use Jena or another library to convert that to RDF/XML. In this case, you could write something like:

@prefix : <urn:ex:>

:JavaClass :belongsTo :Domain1, :Domain2, :DomainN ;
           :hasMethod :Method1, :Method2, :MethodN .

If you're programmatically generating that, you might use a less abbreviated form, like:

<urn:ex:JavaClass> <urn:ex:belongsTo> <urn:ex:Domain1> .
<urn:ex:JavaClass> <urn:ex:belongsTo> <urn:ex:Domain2> .
<urn:ex:JavaClass> <urn:ex:belongsTo> <urn:ex:DomainN> .
<urn:ex:JavaClass> <urn:ex:hasMethod> <urn:ex:Method1> .
<urn:ex:JavaClass> <urn:ex:hasMethod> <urn:ex:Method2> .
<urn:ex:JavaClass> <urn:ex:hasMethod> <urn:ex:MethodN> .

In either case, you can use any number of tools to convert that into RDF/XML. Eg, with the rdfcat command line utility that comes with Jena, you could just do:

$ rdfcat -out RDF/XML-ABBREV data.n3
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="urn:ex:">
  <rdf:Description rdf:about="urn:ex:JavaClass">
    <belongsTo rdf:resource="urn:ex:Domain1"/>
    <belongsTo rdf:resource="urn:ex:Domain2"/>
    <belongsTo rdf:resource="urn:ex:DomainN"/>
    <hasMethod rdf:resource="urn:ex:Method1"/>
    <hasMethod rdf:resource="urn:ex:Method2"/>
    <hasMethod rdf:resource="urn:ex:MethodN"/>
  </rdf:Description>
</rdf:RDF>

However, I didn't find any tool which generates RDF/XML against the given graph. But, I found the graph display on https://www.w3.org/RDF/Validator/ very much helpful. It takes RDF/XML as an input, validates it, and then generate graph and triples. In my case, I'm using JENA to create RDF/XML and then I use W3C Validator to view in graph format. This is equally helpful in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM