You are here

function taxonomy_xml_term_as_rdf_data in Taxonomy import/export via XML 7

When asked for a RDF representation of a taxonomy term, return a merge of both the extrinsic RDF statements that have been made about that term (using the RDF repository-triplestore and cannonic taxonomy/term/n notation) and also the Drupal internal fields that make up that term.

As a bonus, also list the children and parents of this term.

2 calls to taxonomy_xml_term_as_rdf_data()
taxonomy_xml_rdf_export_term in ./taxonomy_xml_rdf.inc
Similar to rdf_rdf_export_node()
taxonomy_xml_rdf_export_vocabulary in ./taxonomy_xml_rdf.inc
Return an RDF representation of the requested vocab.

File

./taxonomy_xml_rdf.inc, line 30

Code

function taxonomy_xml_term_as_rdf_data($term) {

  // Expect an object, but the menu callback may have just provided the tid
  $term = is_numeric($term) ? taxonomy_term_load($term) : $term;
  $subject_uri = url('taxonomy/term/' . $term->tid, array(
    'absolute' => TRUE,
  ));
  $subject_curi = 'term:' . $term->tid;
  $subject = rdf_is_valid_curie($subject_curi) ? rdf_qname_to_uriref($subject_curi) : rdf_uri($subject_curi);
  $data = rdf_query($subject_uri);

  // $data is something called  RDF_QueryIterator extends AppendIterator ??
  // I have no idea how to add things to that. Flatten that (we were about to do that anyway)
  // and add more statements
  $data = rdf_normalize($data);

  #dpm($term);

  // Get normal internal $term values from Drupal
  // and represent them as RDF statements
  $statements = array(
    'rdf:type' => rdf_qname_to_uriref('rdfs:Class'),
    'rdfs:label' => rdf_literal($term->name),
    'rdfs:isDefinedBy' => rdf_uri(url('taxonomy/vocabulary/' . $term->vid, array(
      'absolute' => TRUE,
    ))),
  );
  if (!empty($term->description)) {
    $statements['rdfs:comment'] = rdf_literal($term->description);
  }
  foreach ((array) $term->parents as $ptid) {
    $statements['rdfs:subClassOf'][$ptid] = rdf_uri(url('taxonomy/term/' . $ptid, array(
      'absolute' => TRUE,
    )));
  }
  foreach ((array) $term->children as $ctid => $child) {
    $statements['rdfs:superClassOf'][$ctid] = rdf_uri(url('taxonomy/term/' . $ctid, array(
      'absolute' => TRUE,
    )));
  }
  foreach ((array) $term->synonyms as $i => $synonym) {
    $statements['owl:equivalentClass'][$i] = rdf_literal($synonym);
  }
  foreach ((array) $term->related as $i => $seealso) {
    $statements['rdfs:seeAlso'][$i] = rdf_uri(url('taxonomy/term/' . $seealso, array(
      'absolute' => TRUE,
    )));
  }
  $data = convert_statements_to_rdf_data($subject_uri, $statements);
  return $data;
}