Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializing models and resolving references with spira/RDF.rb
    primarykey
    data
    text
    <p>I'm using <a href="https://github.com/ruby-rdf/spira" rel="nofollow">Spira</a> as a model/persistence layer for a Ruby application. I'm having trouble getting a suitable serialization (e.g., as RDF/XML) for my individual models. For example, when I dump a model that contains "associations", I get XML that looks like:</p> <pre class="lang-xml prettyprint-override"><code>&lt;ns0:video rdf:about="info:whatever/videos/g91832990"&gt; &lt;ns1:contributor rdf:resource="info:whatever/interviewees/g88129610"/&gt; &lt;ns1:title&gt;Test Video&lt;/ns1:title&gt; &lt;ns0:files rdf:resource="info:whatever/files/g91776800"/&gt; &lt;/ns0:video&gt; </code></pre> <p>However, I'd like this XML representation to resolve the <code>rdf:resource</code> 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> <p>The contributor element is expanded to contain the relevant metadata. I can get the first-level references with a SPARQL query like:</p> <pre class="lang-rb prettyprint-override"><code>sparql.construct([:o, :p2, :o2]).where([node, :p, :o], [:o, :p2, :o2]) </code></pre> <p>where node is my "about" node. However, I want to do this to arbitrary depth. I understand that this question might touch on bigger issues, like doing recursive queries in SPARQL/RDF. However, I was hoping there would be some switch or setting in Spira or RDF.rb that would just change the output format. </p> <p>Sorry about my terminology: I'm sure "resolving references" isn't the correct term to use.</p> <p><strong>EDIT</strong></p> <p>In Spira, models mixin <code>RDF::Enumerable</code>; they have an RDF representation comprising RDF statements from the triplestore where the <code>subject</code> is the model's URI. "Dumping a model" looks like:</p> <pre><code>v = Video.find 'RDF::Enumerable' v.dump(:rdfxml) </code></pre> <p>The RDF/XML generated contains only the model's RDF statements. It's also possible to dump the whole triplestore (e.g., my second example above) with the following command:</p> <pre><code>Spira.repository.dump(:rdfxml) </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.
 

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