function taxonomy_xml_add_terms_as_rdf in Taxonomy import/export via XML 6
Same name and namespace in other branches
- 5.2 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
- 5 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
- 6.2 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
Given a list of terms, append definitions of them to the passed DOM container
Following w3c, SUMO and Wordnet examples (tho not any explicit instructions, taxonomy terms are modelled as rdfs:Class objects structured using rdfs: subClassOf statements.
Sample from Wordnet:
<Class rdf:about="http://xmlns.com/wordnet/1.6/Cat"> <label>Cat [ 1 ]</label> <comment>feline mammal usually having thick soft fur and being unable to roar; domestic cats; wildcats</comment> <subClassOf> <Class rdf:about="http://xmlns.com/wordnet/1.6/Feline" /> </subClassOf> </Class>
I'm copying that syntax.
Parameters
$termlist a FLAT array of all terms, internally cross-referenced to: each other defining the tree stucture
1 call to taxonomy_xml_add_terms_as_rdf()
- taxonomy_xml_rdf_create in ./
rdf_format.inc - Return an XML/RDF document representing this vocab
File
- ./
rdf_format.inc, line 621 - Include routines for RDF parsing and taxonomy/term creation.
Code
function taxonomy_xml_add_terms_as_rdf(&$domcontainer, $termlist) {
if (!$termlist) {
return;
}
$dom = $domcontainer->ownerDocument;
foreach ($termlist as $term) {
module_invoke_all('taxonomy_term_load', $term);
#dpm($term);
$termnode = $dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:Class');
$termnode
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:ID', 'term-' . $term->tid);
$domcontainer
->appendchild($termnode);
if (isset($term->uri)) {
$termnode
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:about', $term->uri);
}
else {
if (isset($term->field_uri)) {
$termnode
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:about', $term->field_uri[0]['#value']);
}
}
$termnode
->appendchild($dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:label', xmlentities($term->name)));
if ($term->description) {
$termnode
->appendchild($dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:comment', xmlentities($term->description)));
}
$vocab_ref = $dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:isDefinedBy');
$vocab_ref
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:resource', '#vocabulary-' . $term->vid);
$termnode
->appendchild($vocab_ref);
foreach ((array) taxonomy_get_related($term->tid) as $relatedid => $relatedterm) {
$related_node = $dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:seeAlso', xmlentities($relatedterm->name));
$related_node
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:resource', '#term-' . $relatedid);
$termnode
->appendchild($related_node);
}
$synonyms = taxonomy_get_synonyms($term->tid);
// TODO - figure out the right syntax for synonym
// I'm using 'equivalentClass' ... although that's really intended for merging different vocabs.
foreach ((array) $synonyms as $synonymname) {
$synonymnode = $parent_node = $dom
->createelementns(TAXONOMY_XML_OWL_NS, 'owl:equivalentClass', xmlentities($synonymname));
$termnode
->appendchild($synonymnode);
}
foreach ((array) $term->parents as $parentid) {
$parentlist = array();
if ($parentid) {
$parentlist[$parentid] = $parent = taxonomy_get_term($parentid);
$parent_node = $dom
->createelementns(TAXONOMY_XML_RDFS_NS, 'rdfs:subClassOf', xmlentities($parent->name));
$parent_node
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:resource', '#term-' . $parentid);
$termnode
->appendchild($parent_node);
}
}
# dpm(array('adding term to rdf' => $term));
#$termnode->appendchild($dom->createcomment(print_r($term, 1)));
// workaround for large vocabs - extend runtime indefinately
set_time_limit(10);
}
// Done all terms in list
}