0

I am using EasyRdf to create a few nodes in the graph. My problem is that I am trying to create a new blank node and also set an rdf:about property to it that points to the correct resource.

$rdf = new EasyRdf_Graph(); 

$datapoint_resource = $rdf->newBNode(
    'rdf:Description'
);

The problem with this code is that it creates a new rdf:Description node but there's no way I can add rdf:about as a property to it.

<rdf:Description>
    <!-- Some resources here -->
</rdf:Description>

What I need is

<rdf:Description rdf:about="http://link.to/my/resource/id">
    <!-- Some resources here -->
</rdf:Description>

I've tried adding rdf:about as a resource but the W3C validator outputs the error "rdf:about is not allowed as an element tag here".

   <rdf:Description>
     <rdf:about rdf:resource="http://ordex.probook/rdf/datapoint/5813af3dbf552b25ed30fd5c9f1eea0b"/>
   </rdf:Description>

So this doesn't work and it probably isn't a good idea either.


How can I add rdf:about when creating a new blank node or what other things do you suggest?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Daniel Luca CleanUnicorn
  • 1,087
  • 1
  • 12
  • 30
  • While `rdf:about` is a URI and you _could_, I suppose, use it as a property, it's not being used as an RDF property here. Rather, it's used in the RDF/XML serialization of an RDF graph to indicate the URI of a resource. If you're trying to a create a blank node (I assume that's what `newBNode` does), then it won't have a URI, and so you won't see an `rdf:about` attribute in the RDF/XML serialization. if you want ``, then you need to create one with [Graph->resource(uri)](http://www.easyrdf.org/docs/api/EasyRdf_Graph.html#method_resource). – Joshua Taylor Feb 27 '14 at 16:04

1 Answers1

1

rdf:about is used in the RDF/XML serialization of an RDF graph to indicate the URI of a resource. Blank nodes, which you're creating with Graph.newBNode() don't have URIs. To create a URI resource, you Graph.resource(uri). Thus, you should do this instead:

$datapoint_resource = $rdf->resource('http://link.to/my/resource/id');

For more about how rdf:about is used; see the RDF 1.1 XML Syntax. It includes, for instance, this example:

The Figure 2 graph consists of some nodes that are IRIs (and others that are not) and this can be added to the RDF/XML using the rdf:about attribute on node elements to give the result in Example 2:

EXAMPLE 2 Node Elements with IRIs added

<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
  <ex:editor>
    <rdf:Description>
      <ex:homePage>
        <rdf:Description rdf:about="http://purl.org/net/dajobe/">
        </rdf:Description>
      </ex:homePage>
    </rdf:Description>
  </ex:editor>
</rdf:Description>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • The problem with this is that I need more datapoint_resources and if I do this all the properties I am adding to them will be added to the same datapoint_resource (the first one, a second one does not exist). The docs say "Get or create a resource stored in a graph". I need a new resource everytime. – Daniel Luca CleanUnicorn Feb 27 '14 at 16:11
  • I'm not sure I follow you; why wouldn't you be using, e.g., `http://link.to/my/resource/id001`, `http://link.to/my/resource/id002`, `http://link.to/my/resource/id003`, etc.? of course, you can still use blank nodes to represent your datapoints, if you want; you just won't see `rdf:about` identifying their URIs because they're blank nodes and don't have URIs. The only difference between resources that are blank nodes and resources that are URI resources is that blank nodes don't have URIs. An `rdf:about` attribute is used in the XML serialization of RDF to indicate the URI of a _non-blank_ – Joshua Taylor Feb 27 '14 at 16:13
  • @hydrarulz resource, i.e., a URI resource. If you're successful in working around the API somehow and adding an `rdf:about` attribute in the XML, then you no longer have a blank node; you have an URI resource with the specified URI. You can't have a resource be both blank and identified by a URI. – Joshua Taylor Feb 27 '14 at 16:15
  • I think my whole approach was wrong because I was depending on blank nodes to be able to create more "resources" in the RDF instead of properly identifying my resources by type + uri. Thanks for the help, you nudged me in the correct direction. – Daniel Luca CleanUnicorn Feb 27 '14 at 16:42
  • I'm not quite sure I follow you; you can use multiple blank nodes to represent your data points instead of URI resources, and you can still give them types, could still give them IDs with an :hasID property, etc. For instance, take a look at the data at http://paste.lisp.org/display/141402. – Joshua Taylor Feb 27 '14 at 16:51