I'm working up support for rdf representation of taxonomy terms (to be read/write compatible with my taxonomy_xml and other public vocabularies)
Chugging along OK, but I found that when setting my $data to contain simple text strings or URIs (as opposed to full RDF_ object entities) the serializer didn't play along, although the code there almost did.
Looks like the use of an undeclared variable due to a mistype.


    foreach ($predicates as $predicate => $objects) {
      $qname = rdf_uri_to_qname($predicate);
      $qname = $base_prefix ? preg_replace('/^' . preg_quote($base_prefix, '/') . ':/', '', $qname) : $qname;

      foreach (is_array($objects) ? $objects : array($object) as $object) {

... $object in the last line was undeclared, inaccurate, and ended up repeating the value of a valid predicate into the spot reserved for all other predicates. quite wrong

a 1-character patch attached.

-      foreach (is_array($objects) ? $objects : array($object) as $object) {
+      foreach (is_array($objects) ? $objects : array($objects) as $object) {

now works as expected.

(not sure if this serialization problem is different from the 'data export' category... it's the closest I can see)

Comments

dman’s picture

StatusFileSize
new1.25 KB

ALSO - new, also-small issue.

Support for rdf:type was not working - only if the supplied 'rdf:type' was an array of types.
I'm not sure when one entity would/should be more than one 'type' or whether just using the first one of those values found as the 'real' type (as happens now) would be the right thing to do.

But in any case, I'd expect to be able to set ONE type and be able to use that.
Updated (cumulative) patch attached.

-        $type = rdf_uri_to_qname(array_shift($objects));
+        $type = rdf_uri_to_qname(array_shift(rdf_objects($objects)));

sample snippet:

  $statements = array(
    'rdf:type' => rdf_qname_to_uriref('rdfs:Class'),
    'rdfs:isDefinedBy' => url('taxonomy/vocabulary/'. $term->vid, array('absolute' => TRUE)),
  );
  #...
  // Convert CURIE statements to full statement resource refs
  foreach($statements as $predicate => $object){
    $predicate = rdf_is_valid_curie($predicate) ? rdf_qname_to_uriref($predicate) : rdf_uri($predicate);
    $object    = rdf_is_valid_uri($object)      ? rdf_uri($object) : $object;
    // Add this data to the entity 
    $data[$subject_uri][$predicate->uri] = $object;
  }
  rdf_export($data, 'taxonomy_term-'.$term->tid);

Produced the incorrect:

<rdf:RDF rdf:about="http://taxonomy.drupal6.gadget/taxonomy/term/813">
  <rdfs:subClassOf rdf:resource="http://taxonomy.drupal6.gadget/taxonomy/term/785"/>
  <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  <rdfs:isDefinedBy rdf:resource="http://taxonomy.drupal6.gadget/taxonomy/vocabulary/1"/>
</rdf:RDF>

With the fix, it produces the expected, correctly type-structured:

<rdf:RDF>
  <rdfs:Class rdf:about="http://taxonomy.drupal6.gadget/taxonomy/term/813">
    <rdfs:subClassOf rdf:resource="http://taxonomy.drupal6.gadget/taxonomy/term/785"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdfs:isDefinedBy rdf:resource="http://taxonomy.drupal6.gadget/taxonomy/vocabulary/1"/>
  </rdfs:Class>
</rdf:RDF>
smustgrave’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)