You are here

function _rdfx_fetch_terms in RDF Extensions 7.2

1 call to _rdfx_fetch_terms()
_rdfx_extract_schema in ./rdfx.terms.inc
Queries a set of triples for classes and properties, and builds an associative array describing the vocabulary and any classes and properties found.

File

./rdfx.terms.inc, line 540
Functions for managing RDF Terms.

Code

function _rdfx_fetch_terms(&$model) {
  $terms = array();
  $term_uris = array();

  // Retrieve the queries for term retrieval. This may have been modified by
  // other modules.
  $term_type_groups = rdfx_term_types();
  foreach ($term_type_groups as $term_type_group => $group) {
    foreach ($group['term_types'] as $term_type => $term) {
      $query = array(
        array(
          '?',
          'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
          $term['uri'],
        ),
      );
      foreach ($term['inference'] as $inference_uri => $query_types) {
        foreach ($query_types as $query_type) {
          switch ($query_type) {
            case 'subject':
              $query[] = array(
                '?',
                $inference_uri,
                null,
              );
              break;
            case 'object':
              $query[] = array(
                null,
                $inference_uri,
                '?',
              );
              break;
          }
        }
      }
      $term_uris[$term_type] = _rdfx_query_find_uris($model, $query);

      // Add term details and various relationships for each term, as defined
      // in rdfx_term_types() and altered by hook_rdfx_term_types_alter().
      $query_x = array();
      foreach ($term_uris[$term_type] as $term_uri) {
        $terms[$term_type][$term_uri] = _evoc_query_for_term_description($model, $term_uri);
        foreach ($group['description'] as $property => $queries) {
          foreach ($queries as $predicate_uri => $query_types) {
            foreach ($query_types as $query_type) {
              switch ($query_type) {
                case 'subject':
                  $query_x[$term_uri][$property][] = array(
                    '?',
                    $predicate_uri,
                    $term_uri,
                  );
                  break;
                case 'object':
                  $query_x[$term_uri][$property][] = array(
                    $term_uri,
                    $predicate_uri,
                    '?',
                  );
                  break;
              }
            }
          }
          $terms[$term_type][$term_uri][$property] = _rdfx_query_find_uris($model, $query_x[$term_uri][$property]);
        }
      }
    }
  }
  return $terms;
}