function taxonomy_xml_canonicize_predicates in Taxonomy import/export via XML 6.2
Same name and namespace in other branches
- 6 taxonomy_xml.module \taxonomy_xml_canonicize_predicates()
- 7 taxonomy_xml.process.inc \taxonomy_xml_canonicize_predicates()
Convert aliased predicates into common ones.
Given a term with a collection of named predicate relations, convert those into canonic (known, defined) terms. This involves some duplication as the original and true names are both packed into the $term->predicates array. Only the true names are looked at later however.
3 calls to taxonomy_xml_canonicize_predicates()
- taxonomy_xml_mesh_parse in ./
mesh_format.inc - Reads a XML file and creates the term definitions found in it.
- taxonomy_xml_rdf_make_term in ./
rdf_format.inc - Create the placeholder and fill in the values for this term - NOT its relationships yet.
- taxonomy_xml_tcs_parse in ./
tcs_format.inc - Reads a TCS file and creates the term definitions found in it.
File
- ./
taxonomy_xml.module, line 954 - This module makes it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_canonicize_predicates(&$term) {
// Translate the predicate statements into what we need
if (empty($term->predicates)) {
$term->predicates = array();
}
// $predicate_synonyms is a translation array to match synonyms from various syntaxes with Drupal concepts
$predicate_synonyms = taxonomy_xml_relationship_synonyms();
foreach ($term->predicates as $predicate => $values) {
$original_predicate = $predicate;
// First translate misc terminology synonyms to the cannonic predicate I use everywhere
// This allows us to interpret several XML dialects at once
if (isset($predicate_synonyms[$predicate]) && ($cannonic = $predicate_synonyms[$predicate])) {
$predicate = $cannonic;
}
# drupal_set_message(t("Applying '$predicate' ($predicate) value of ". print_r($values, 1) ." found in $guid"));
switch ($predicate) {
case TAXONOMY_XML_DESCRIPTION:
$term->description = taxonomy_xml_get_literal_string($values);
break;
case TAXONOMY_XML_NAME:
// In the (hopefully never) case that a term has, eg, both a 'name'
// and a 'title' set, and different, we may have conflicts to resolve.
// Pre-empt this here by noting both, but revisit if we can come up
// with better logic, eg ordering priority of synonyms.
$val = taxonomy_xml_get_literal_string($values);
if (isset($term->name) && $val != $term->name) {
$term->name .= ' (' . $val . ')';
}
else {
$term->name = $val;
}
break;
case TAXONOMY_XML_PARENT:
foreach ($values as $i => $target_uri) {
$term->predicates[$predicate][$i] = $target_uri;
$strings = array(
'%predicate' => $predicate,
'%subject' => isset($term->name) ? $term->name : $term->guid,
'%target_uri' => $target_uri,
);
}
break;
case TAXONOMY_XML_RELATED:
case TAXONOMY_XML_CHILD:
// A term relationship.
// Translate each referred item from URI to its label or handle,
// and save to be linked in later
foreach ($values as $i => $target_uri) {
$term->predicates[$predicate][$i] = $target_uri;
}
break;
case TAXONOMY_XML_HAS_SYNONYM:
$term->synonyms_array = isset($term->synonyms_array) ? array_merge($term->synonyms_array, $values) : $values;
$term->synonyms = implode("\n", array_unique($term->synonyms_array));
break;
case TAXONOMY_XML_IN_VOCABULARY:
/* currently not used very much - more than one vocab per input file is rare
// This term need to be in the vocabulary referred to by this URI
// check our known vocabs to see if they are recognised
// Do we know a vocab with an ID matching this 'isdefinedby' value?
dpm(array('looking for vocab' => $values));
foreach ($values as $value) { // probably just one...
if (isset($vocabularies[$value])) {
// I know this vocab!
$term->vid = $vocabularies[$value]->vid;
}
}
*/
break;
case 'type':
// These are already done. Ignore
case TAXONOMY_XML_UNUSED:
// Explicitly ignore these
break;
case TAXONOMY_XML_OTHER_PREDICATE:
// These ones we'll try to save as RDF statements, attached to the term URI
foreach ($values as $value) {
$term->rdf[] = array(
'subject' => NULL,
'predicate' => $original_predicate,
'object' => $value,
);
}
watchdog('taxonomy_xml', "\n Found a useful predicate '<b>%predicate</b> = %value'.\n Making a note of it for pure-RDF storage.\n ", array(
'%predicate' => "{$predicate} ({$original_predicate})",
'%subject' => isset($term->name) ? $term->name : $term->guid,
'%value' => $value,
), WATCHDOG_INFO);
break;
default:
// A valid, but unrecognised statement was found when flattening the input
watchdog('taxonomy_xml', "\n Dunno what to do with '<b>%predicate</b>'.\n Subject '%subject' has value(s) = <pre>!values</pre>\n A later content type may absorb this info,\n but it's not a core term property.", array(
'%predicate' => $predicate,
'%subject' => isset($term->name) ? $term->name : $term->guid,
'!values' => print_r($values, 1),
), WATCHDOG_DEBUG);
}
}
if (!empty($term->guid)) {
taxonomy_xml_set_term_guid($term, $term->guid);
}
#dpm(array(__FUNCTION__ => $term, 'transformed predicates are' => $term->predicates));
}