0

I have an RDF graph that I create with EasyRDF:

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/terms/"
         xmlns:foaf="http://xmlns.com/foaf/0.1/"

  <rdf:Description rdf:about="http://the-query-url">
    <dc:creator>me</dc:creator>
    <foaf:primaryTopic rdf:resource="genid1">
  </rdf:Description>

  <rdf:Description rdf:nodeID="genid1">
    <!-- stuff -->
  </rdf:Description>
</rdf:RDF>

The above is not correct - the reference to the blank node in foaf:primaryTopic should be _:genid1.

When I change that line to

$meta_block->add('foaf:primaryTopic', $graph->resource('_:' . $symbol_block->getBNodeId()));

EasyRdf nests the resources, like this:

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/terms/"
         xmlns:foaf="http://xmlns.com/foaf/0.1/"

  <rdf:Description rdf:about="http://the-query-url">
    <dc:creator>me</dc:creator>
    <foaf:primaryTopic>
      <rdf:Description>
        <!-- stuff -->
      </rdf:Description>
    </foaf:primaryTopic>
  </rdf:Description>
</rdf:RDF>

How do I stop EasyRdf from nesting the nodes? I want the output to be just like the first example, only with _:genid1 as resource for the foaf:primaryTopic.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
reggie
  • 3,523
  • 14
  • 62
  • 97

1 Answers1

1

You may be misunderstanding the RDF data model. Blank nodes are actually blank. While the might have something like a blank node id in a particular serialization or with a given API, it's not actually part of the data model. In the first snippet you've shown, the node with the genid nodeId is the object of the the foaf:primaryTopic triple. It's the same in the second snippet too; there's a foaf:primaryTopic triple, and the object is a blank node. You're getting the same RDF content. This might be easier to see if you serialize in a more human readable format, like Turtle, or N-Triples. For more about this issue, you may find some of the discussion in How to access OWL documents using XPath in Java? useful.

All that said, you probably can customize how easyRDF writes RDF/XML. It's not a library I've used, but you might look into seeing whether you can turn off syntactic abbreviations. For instance, with Jena (a Java library), you can specify that you want "RDF/XML" or "RDF/XML-ABBREV". RDF/XML-ABBREV is more like your second snippet, whereas it looks like you want something more like RDF/XML. But again, I do suggest that you try serializing to a format like N-Triples or Turtle, to see that the RDF content is actually the same. RDF doesn't have any blank node ids; that's just a concept in serializations that have to be able to refer to them.

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353