Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two parts to this answer. The first is that the particular structure of the XML used in the RDF/XML serialization doesn't matter (insofar as the RDF data is concerned; you're still free to have a preference about what it looks like). The second part is about getting what you want (for aesthetic reasons) out of RDF.rb.</p> <h2>The particular XML structure of RDF/XML doesn't matter</h2> <p>RDF is a <em>graph</em> based data representation. The basic piece of information in RDF is the triple, also called a statement, which has the form </p> <blockquote> <p>subject predicate object</p> </blockquote> <p>A whole bunch of those make up an RDF graph. Those RDF graphs can be serialized in a number of formats. Some are easy to read and write by hand, and others are more complex. Some serialization formats might have a single way of writing a given RDF graph, or define a canonical way, but most will given you a number of different ways to write the same RDF graph. </p> <p>For instance, the following data (in Turtle):</p> <pre class="lang-none prettyprint-override"><code>@prefix : &lt;http://example.org/&gt; . &lt;info:repository/videos/g91832990&gt; a :video ; :contributor &lt;info:repository/interviewees/g88129610&gt; ; :title "Test Video" . &lt;info:repository/interviewees/g88129610&gt; a :person ; :name "Creator" . </code></pre> <p>can be serialized in RDF/XML in different ways, because the format allows for lots of shorthand notation. For instance, with Jena, if I serialize as (plain) RDF/XML, I get:</p> <pre class="lang-xml prettyprint-override"><code>&lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://example.org/" &gt; &lt;rdf:Description rdf:about="info:repository/videos/g91832990"&gt; &lt;rdf:type rdf:resource="http://example.org/video"/&gt; &lt;contributor rdf:resource="info:repository/interviewees/g88129610"/&gt; &lt;title&gt;Test Video&lt;/title&gt; &lt;/rdf:Description&gt; &lt;rdf:Description rdf:about="info:repository/interviewees/g88129610"&gt; &lt;rdf:type rdf:resource="http://example.org/person"/&gt; &lt;name&gt;Creator&lt;/name&gt; &lt;/rdf:Description&gt; &lt;/rdf:RDF&gt; </code></pre> <p>but if I serialize as RDF/XML-ABBREV, I get:</p> <pre class="lang-xml prettyprint-override"><code>&lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://example.org/"&gt; &lt;video rdf:about="info:repository/videos/g91832990"&gt; &lt;contributor&gt; &lt;person rdf:about="info:repository/interviewees/g88129610"&gt; &lt;name&gt;Creator&lt;/name&gt; &lt;/person&gt; &lt;/contributor&gt; &lt;title&gt;Test Video&lt;/title&gt; &lt;/video&gt; &lt;/rdf:RDF&gt; </code></pre> <p>Those are <em>the same</em> RDF graph. The latter might be a bit more expensive to write, since it uses more abbreviations, but they are the <em>same</em> RDF graph.</p> <blockquote> <p>However, I'd like this XML representation to resolve the rdf:resource references. That is, I'd like the XML to look more like this (which is what I get when I do a dump of the whole repository/triplestore):</p> <pre class="lang-xml prettyprint-override"><code>&lt;ns0:video rdf:about="info:repository/videos/g91832990"&gt; &lt;ns1:contributor&gt; &lt;ns2:person rdf:about="info:repository/interviewees/g88129610"&gt; &lt;ns2:name&gt;Creator&lt;/ns2:name&gt; &lt;/ns2:person&gt; &lt;/ns1:contributor&gt; &lt;ns1:title&gt;Test Video&lt;/ns1:title&gt; &lt;!-- ... --&gt; &lt;/ns0:video&gt; </code></pre> </blockquote> <p>It's OK to have aesthetic preferences, as long as you recognize that dumping the model in one format versus another doesn't change what graph you're getting. The structure of the serialization won't affect the results of your SPARQL queries, since the SPARQL query is based on the RDF graph, not the serialization. In fact, trying to access RDF by using XML tools and the RDF/XML serialization is really a bad idea, as I've discussed in <a href="https://stackoverflow.com/a/17052385/1281433">this answer</a> to <a href="https://stackoverflow.com/q/17036871/1281433">How to access OWL documents using XPath in Java?</a>.</p> <h2>Getting abbreviated RDF/XML with RDF.rb</h2> <p>According to its website, RDF.rb supports a <a href="http://rdf.rubyforge.org/#RDF_Serialization_Formats" rel="nofollow noreferrer">number of serialization formats</a> (emphasis added):</p> <ul> <li>RDF::NTriples</li> <li>RDF::JSON (plugin)</li> <li>RDF::N3 (plugin)</li> <li><strong>RDF::Raptor::RDFXML (plugin)</strong></li> <li>RDF::Raptor::Turtle (plugin)</li> <li>RDF::RDFa (plugin)</li> <li><strong>RDF::RDFXML (plugin)</strong></li> <li>RDF::Trix (plugin)</li> </ul> <p>Note that there are two for RDFXML there, one through Raptor, and one from RDF.rb. At least one of those should provide support for the more concise bits of RDF/XML. I haven't used RDF.rb lately, but I seem to recall that the Raptor libraries provide a number of options, so that might be a good bet here. The built in one might have something too, of course.</p> <p>If you start digging around in the source for <code>rdf-rdfxml</code>, you'll find in the <code>writer</code>, that there's an initialization option that might help you out here:</p> <pre class="lang-xml prettyprint-override"><code># @option options [Integer] :max_depth (3) # Maximum depth for recursively defining resources </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload