Browse Source

Fixed misnamed 'namespace' for vocabulary short names

Stephen Ficklin 8 years ago
parent
commit
c1ef066abd

+ 55 - 34
tripal/api/tripal.entities.api.inc

@@ -3,8 +3,8 @@
  * Retrieves a TripalTerm entity that matches the given arguments.
  *
  * @param $values
- *   An associative array used to match a term.  Valid keys may be 'namespace',
- *   'accession, or 'term_id'.  The keys 'namespace' and 'accession' must
+ *   An associative array used to match a term.  Valid keys may be 'vocabulary',
+ *   'accession, or 'term_id'.  The keys 'vocabulary' and 'accession' must
  *   always be used together to uniquely identify a term.  The key 'term_id'
  *   can be used alone to uniquely identify a term.
  *
@@ -12,18 +12,18 @@
  *   A TripalTerm entity object or NULL if not found.
  */
 function tripal_load_term_entity($values) {
-  $namespace = array_key_exists('namespace', $values) ? $values['namespace'] : '';
+  $vocabulary = array_key_exists('vocabulary', $values) ? $values['vocabulary'] : '';
   $accession = array_key_exists('accession', $values) ? $values['accession'] : '';
   $term_id = array_key_exists('term_id', $values) ? $values['term_id'] : '';
 
   $term = NULL;
 
-  if ($namespace and $accession) {
+  if ($vocabulary and $accession) {
     $query = db_select('tripal_term', 'tt');
     $query->join('tripal_vocab', 'tv', 'tv.id = tt.vocab_id');
     $query->fields('tt', array('id'))
-      ->fields('tv', array('namespace'))
-      ->condition('tv.namespace', $namespace)
+      ->fields('tv', array('vocabulary'))
+      ->condition('tv.vocabulary', $vocabulary)
       ->condition('tt.accession', $accession);
     $term = $query->execute()->fetchObject();
   }
@@ -46,21 +46,21 @@ function tripal_load_term_entity($values) {
  *
  * @param $values
  *   An associative array used to match a vocabulary.  The valid keys are
- *   'vocab_id' and 'namespace'.
+ *   'vocab_id' and 'vocabulary'.
  *
  * @return
  * A TripalVocab entity object or NULL if not found.
  */
 function tripal_load_vocab_entity($values) {
-  $namespace = array_key_exists('namespace', $values) ? $values['namespace'] : '';
+  $vocabulary = array_key_exists('vocabulary', $values) ? $values['vocabulary'] : '';
   $vocab_id = array_key_exists('vocab_id', $values) ? $values['vocab_id'] : '';
   $vocab = NULL;
 
   $query= db_select('tripal_vocab', 'tv')
     ->fields('tv');
 
-  if ($namespace) {
-    $query->condition('tv.namespace', $namespace);
+  if ($vocabulary) {
+    $query->condition('tv.vocabulary', $vocabulary);
   }
   if ($vocab_id) {
     $query->condition('tv.id', $vocab_id);
@@ -114,10 +114,10 @@ function tripal_load_bundle_entity($values) {
 /**
  * Creates a new Tripal Entity type (i.e. bundle).
  *
- * @param $namespace
- *   The abbreviated namespace for the vocabulary (e.g. RO, SO, PATO).
+ * @param $vocabulary
+ *   The abbreviated vocabulary for the vocabulary (e.g. RO, SO, PATO).
  * @param $accession
- *   The unique term ID in the vocabulary $namespace (i.e. an accession).
+ *   The unique term ID in the vocabulary $vocabulary (i.e. an accession).
  * @param $term_name
  *   A human-readable name for this term.  This will became the name that
  *   appears for the content type.  In practice, this should be the name
@@ -129,18 +129,18 @@ function tripal_load_bundle_entity($values) {
  * @return
  *  TRUE if the entity type (bundle) was succesfully created.  FALSE otherwise.
  */
-function tripal_create_bundle($namespace, $accession, $term_name, &$error = '') {
+function tripal_create_bundle($vocabulary, $accession, $term_name, &$error = '') {
 
   // First create the TripalVocab if it doesn't already exist.
-  $vocab = tripal_load_vocab_entity(array('namespace' => $namespace));
+  $vocab = tripal_load_vocab_entity(array('vocabulary' => $vocabulary));
   if (!$vocab) {
-    $vocab = entity_get_controller('TripalVocab')->create(array('namespace' => $namespace));
+    $vocab = entity_get_controller('TripalVocab')->create(array('vocabulary' => $vocabulary));
     $vocab->save();
   }
 
   // Next create the TripalTerm if it doesn't already exist.
   $term = tripal_load_term_entity(array(
-    'namespace' => $namespace,
+    'vocabulary' => $vocabulary,
     'accession' => $accession
   ));
   if (!$term) {
@@ -437,7 +437,7 @@ function hook_add_bundle_fields($entity_type, $bundle, $term) {
   $match = array(
     'dbxref_id' => array(
       'db_id' => array(
-        'name' => $vocab->namespace,
+        'name' => $vocab->vocabulary,
       ),
       'accession' => $term->accession
     ),
@@ -483,11 +483,11 @@ function hook_add_bundle_fields($entity_type, $bundle, $term) {
   $semantic_web = array(
     // The type is the term from a vocabulary that desribes this field..
     'name' => '',
-    // The accession in the namespace for this term.
+    // The accession in the vocabulary for this term.
     'accession' => '',
-    // The namepsace for the vocabulary (e.g. 'foaf').
-    'ns' => '',
-    // The URL for the namespace.  It must be that the type can be
+    // The vocabulary short name (e.g. 'foaf', 'SO', 'PATO', etc.).
+    'vocabulary' => '',
+    // The URL for the vocabulary.  It must be that the type can be
     // appended to the URL.
     'nsurl' => '',
   );
@@ -934,14 +934,15 @@ function hook_vocab_storage_info() {
   );
 }
 
+
 /**
  * Creates a form for specifying a term for TripalEntity creation.
  *
  * This hook allows the module that implements a vocabulary storage backend
  * to provide the form necessary to select a term that will then be used for
- * creating a new TripalEntity type.  Tripal will expect that a 'namespace' and
- * 'accession' are in the $form_state['storage'] array. The 'namespace' and
- * must be the abbreviated uppercase namespace for the vocabulary (e.g. 'RO',
+ * creating a new TripalEntity type.  Tripal will expect that a 'vocabulary' and
+ * 'accession' are in the $form_state['storage'] array. The 'vocabulary' and
+ * must be the abbreviated uppercase vocabulary for the vocabulary (e.g. 'RO',
  * 'SO', 'PATO', etc.).  The 'accession' must be the unique term ID (or
  * accession) for the term in the vocabulary.
  *
@@ -991,14 +992,14 @@ function hook_vocab_import_form_submit($form, &$form_state) {
  * about the term from the storage backend.  It must return an array with
  * a set of keys.
  *
- * @param $namespace
- *   The namespace of the vocabulary in which the term is found.
+ * @param $vocabulary
+ *   The vocabulary of the vocabulary in which the term is found.
  * @param $accession
  *   The unique identifier (accession) for this term.
  *
  * @return
  *   An array with at least the following keys:
- *     namespace : The namespace of the vocabulary.
+ *     vocabulary : The short name of the vocabulary (e.g. SO, PATO, foaf).
  *     accession : The name unique ID of the term.
  *     url : The URL for the term.
  *     name : The name of the term.
@@ -1006,10 +1007,30 @@ function hook_vocab_import_form_submit($form, &$form_state) {
  *   any other keys may be added as desired. Returns NULL if the term
  *   cannot be found.
  */
-function hook_vocab_get_term($namespace, $accession) {
+function hook_vocab_get_term($vocabulary, $accession) {
   // See the tripal_chado_vocab_get_term() function for an example.
 }
 
+/**
+ * Hook used by the default term storage backend to add new terms.
+ *
+ * @param $values
+ *   An associative array of key/value pairs used to add a new term.  The
+ *   keys are:
+ *     vocabulary : The vocabulary of the vocabulary.
+ *     accession : The name unique ID of the term.
+ *     url : The URL for the term.
+ *     name : The name of the term.
+ *     definition : The term's description.
+ * @return
+ *   TRUE if the term was added, FALSE otherwise.  If the term already exists
+ *   it will be updated and the return value will be TRUE,
+ */
+function hook_vocab_set_term($values) {
+  // See the tripal_chado_vocab_set_term() function for an example.
+}
+
+
 /**
  * Retrieves full information about a vocabulary term.
  *
@@ -1019,14 +1040,14 @@ function hook_vocab_get_term($namespace, $accession) {
  * hook_vocab_get_term() function for the database backend that is housing the
  * vocabularies and allow it to return the details about the term.
  *
- * @param $namespace
- *   The namespace of the vocabulary in which the term is found.
+ * @param $vocabulary
+ *   The vocabulary of the vocabulary in which the term is found.
  * @param $accession
  *   The unique identifier (accession) for this term.
  *
  * @return
  *   An array with at least the following keys:
- *     namespace : The namespace of the vocabulary.
+ *     vocabulary : The short name of the vocabulary (e.g. SO, PATO, foaf).
  *     accession : The name unique ID of the term.
  *     url : The URL for the term.
  *     name : The name of the term.
@@ -1034,7 +1055,7 @@ function hook_vocab_get_term($namespace, $accession) {
  *   any other keys may be added as desired. Returns NULL if the term
  *   cannot be found.
  */
-function tripal_get_term_details($namespace, $accession) {
+function tripal_get_term_details($vocabulary, $accession) {
   // TODO: we need some sort of administrative interface that lets the user
   // switch to the desired vocabulary type. For now, we'll just use the
   // first one in the list.
@@ -1044,7 +1065,7 @@ function tripal_get_term_details($namespace, $accession) {
     $module = $stores[$keys[0]]['module'];
     $function = $module . '_vocab_get_term';
     if (function_exists($function)) {
-      return $function($namespace, $accession);
+      return $function($vocabulary, $accession);
     }
   }
 }

+ 5 - 5
tripal/includes/TripalBundleUIController.inc

@@ -106,7 +106,7 @@ function tripal_tripal_bundle_form($form, &$form_state, $entityDataType) {
           'data' => 'Vocabulary',
           'class' => array('side-header')
         ),
-        $vocab->namespace
+        $vocab->vocabulary
       ),
       array(
         array(
@@ -450,20 +450,20 @@ function tripal_admin_add_type_form_validate($form, &$form_state) {
  *
  */
 function tripal_admin_add_type_form_submit($form, &$form_state) {
-  $namespace = '';
+  $vocabulary = '';
   $accession = '';
   if (array_key_exists('storage', $form_state)) {
     $storage = $form_state['storage'];
-    $namespace = array_key_exists('namespace', $storage) ? $storage['namespace'] : '';
+    $vocabulary = array_key_exists('vocabulary', $storage) ? $storage['vocabulary'] : '';
     $accession = array_key_exists('accession', $storage) ? $storage['accession'] : '';
     $term_name = array_key_exists('term_name', $storage) ? $storage['term_name'] : '';
 
     // Before we try to add this type, check to see if it already exists
     // as a bundle.
-    $term = tripal_load_term_entity(array('namespace' => $namespace, 'accession' => $accession));
+    $term = tripal_load_term_entity(array('vocabulary' => $vocabulary, 'accession' => $accession));
     if (!$term) {
       $error = '';
-      $success = tripal_create_bundle($namespace, $accession, $term_name, $error);
+      $success = tripal_create_bundle($vocabulary, $accession, $term_name, $error);
       if (!$success) {
         drupal_set_message($error, 'error');
         $form_state['redirect'] = "admin/structure/bio_data";

+ 3 - 3
tripal/includes/TripalEntityUIController.inc

@@ -221,7 +221,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
    foreach ($results['TripalEntity'] as $entity_id => $stub) {
      $entity = entity_load('TripalEntity', array($entity_id));
      $entity = reset($entity);
-     $namespace = '';
+     $vocabulary = '';
      $term_name = '';
 
      // Get the term
@@ -231,7 +231,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
        $term_name = $term->name;
        $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
        $vocab = reset($vocab);
-       $namespace = $vocab->namespace;
+       $vocabulary = $vocab->vocabulary;
      }
 
      // Retrieve details about the user who created this data.
@@ -240,7 +240,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
      // Add information to the table.
      $rows[] = array(
        l($entity->title, 'bio_data/' . $entity->id),
-       $namespace,
+       $vocabulary,
        $term_name,
        l($author->name, 'user/' . $entity->uid),
        $entity->status == 1 ? 'published' : 'unpublished',

+ 4 - 5
tripal/includes/TripalField.inc

@@ -270,12 +270,11 @@ class TripalField {
           'for the term "gene" in the Sequence Ontology, the accession is "0000704").'),
       '#default_value' => $settings['semantic_web']['accession'],
     );
-    $element['semantic_web']['ns'] = array(
+    $element['semantic_web']['vocabulary'] = array(
       '#type' => 'textfield',
-      '#title' => 'Vocabulary Namespace',
-      '#description' => t('The namespace for the vocabulary to which this term ' .
-          'belongs (e.g. the namespace for the Sequence Ontology is "SO"). This '.
-          'value is prefixed to the Term ID to form the complete id (e.g. "SO:0000704")'),
+      '#title' => 'Vocabulary Short Name',
+      '#description' => t('The short name for the vocabulary to which this term ' .
+          'belongs (e.g. SO, PATO, foaf). This value is prefixed to the Term ID to form the complete id (e.g. "SO:0000704")'),
       '#default_value' => $settings['semantic_web']['ns'],
     );
     $element['semantic_web']['nsurl'] = array(

+ 1 - 1
tripal/includes/TripalTerm.inc

@@ -24,7 +24,7 @@ class TripalTerm extends Entity {
       $module = $stores[$keys[0]]['module'];
       $function = $module . '_vocab_get_term';
       if (function_exists($function)) {
-        $term_details = $function($vocab->namespace, $this->accession);
+        $term_details = $function($vocab->vocabulary, $this->accession);
         $this->details = $term_details;
         if ($term_details and $term_details['definition']) {
           $this->definition = $term_details['definition'];

+ 2 - 2
tripal/includes/TripalVocabController.inc

@@ -12,7 +12,7 @@ class TripalVocabController extends EntityAPIController {
   }
 
   public function create(array $values = array()) {
-    $this->namespace = array_key_exists('namespace', $values) ? $values['namespace'] : '';
+    $this->vocabulary = array_key_exists('vocabulary', $values) ? $values['vocabulary'] : '';
     return parent::create($values);
   }
 
@@ -66,7 +66,7 @@ class TripalVocabController extends EntityAPIController {
 
       // Write out the entity record.
       $record = array(
-        'namespace' => $entity->namespace,
+        'vocabulary' => $entity->vocabulary,
         'created' => $entity->created,
         'changed' => time(),
       );

+ 2 - 2
tripal/includes/TripalVocabViewsController.inc

@@ -12,8 +12,8 @@ class TripalVocabViewsController extends EntityDefaultViewsController {
 
     $data['tripal_vocab']['table']['group'] = 'Tripal Content Vocabulary';
 
-    $data['tripal_vocab']['namespace']['title'] = 'Namespace';
-    $data['tripal_vocab']['namespace']['help'] = t('The namespace of the vocabulary.');
+    $data['tripal_vocab']['vocabulary']['title'] = 'Vocabulary';
+    $data['tripal_vocab']['vocabulary']['help'] = t('The short name of the vocabulary.');
 
 
     // It is not intended that the following fields will every be used by the

+ 2 - 2
tripal/includes/tripal.entity.inc

@@ -229,8 +229,8 @@ function tripal_entity_info_alter(&$entity_info){
     // or configuration associated with an entity type .We want to dynamically
     // add the bundles to the entity.
     $bundles = db_select('tripal_bundle', 'tb')
-    ->fields('tb')
-    ->execute();
+      ->fields('tb')
+      ->execute();
     while ($bundle = $bundles->fetchObject()) {
       $bundle_name = $bundle->name;
       $term_id = $bundle->term_id;

+ 4 - 4
tripal/tripal.install

@@ -478,8 +478,8 @@ function tripal_tripal_vocab_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
       ),
-      'namespace' => array(
-        'description' => 'The namespace for the vocabulary (e.g. SO, PATO, etc.).',
+      'vocabulary' => array(
+        'description' => 'The short name for the vocabulary (e.g. SO, PATO, etc.).',
         'type' => 'varchar',
         'length' => 10,
         'not null' => TRUE,
@@ -498,11 +498,11 @@ function tripal_tripal_vocab_schema() {
       ),
     ),
     'indexes' => array(
-      'namespace' => array('namespace'),
+      'vocabulary' => array('vocabulary'),
       'entity_changed' => array('changed'),
       'entity_created' => array('created'),
     ),
-    'unique keys' => array('namespace' => array('namespace')),
+    'unique keys' => array('vocabulary' => array('vocabulary')),
     'primary key' => array('id'),
   );
   return $schema;

+ 4 - 4
tripal/tripal.module

@@ -539,11 +539,11 @@ function tripal_add_bundle_fields($entity_type, $bundle, $term) {
       'semantic_web' => array(
         // The type is the term from a vocabulary that desribes this field..
         'name' => '',
-        // The accession of the term in the namespace.
+        // The accession of the term in the vocabulary.
         'accession' => '',
-        // The namepsace for the vocabulary (e.g. 'foaf').
-        'ns' => '',
-        // The URL for the namespace.  It must be that the type can be
+        // The short name for the vocabulary (e.g. SO, PATO, foaf).
+        'vocabulary' => '',
+        // The URL for the vocabulary.  It must be that the type can be
         // appended to the URL.
         'nsurl' => '',
       ),

+ 2 - 3
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -367,7 +367,7 @@ function tripal_insert_cv($name, $definition) {
     'definition' => $definition
   );
 
-  // see if the CV (default-namespace) exists already in the database
+  // see if the CV default exists already in the database
   $sel_values = array('name' => $name);
   $results = chado_select_record('cv', array('*'), $sel_values);
 
@@ -430,8 +430,7 @@ function tripal_insert_cv($name, $definition) {
  *        $term['id'] and it needs to be explicitly set.  Use this argument
  *        only if the database name cannot be specififed in the term ID
  *        (e.g. <DB>:<ACCESSION>).
- *    - namespace: the CV name for the term. DEPRECATED. Please use cv_name
- *       instead.
+ *    - namespace: DEPRECATED. Please use cv_name instead.
  * @param $options
  *   An associative array with the following keys:
  *    - update_existing: By default this is TRUE.  If the term exists it is

+ 2 - 2
tripal_chado/includes/fields/chado_base__dbxref_id.inc

@@ -97,7 +97,7 @@ class chado_base__dbxref_id extends TripalField {
 
     foreach ($items as $delta => $item) {
       if ($item['value']) {
-        $content = $item['value']['namespace'] . ':' . $item['value']['accession'];
+        $content = $item['value']['vocabulary'] . ':' . $item['value']['accession'];
         if ($item['value']['URL']) {
           $content = l($item['value']['URL'], $item['value']['URL']);
         }
@@ -279,7 +279,7 @@ class chado_base__dbxref_id extends TripalField {
 
       $entity->{$field_name}['und'][0] = array(
         'value' => array(
-          'namespace' => $dbxref->db_id->name,
+          'vocabulary' => $dbxref->db_id->name,
           'accession' => $dbxref->accession,
           'URL' => $URL,
         ),

+ 2 - 2
tripal_chado/includes/fields/chado_linker__dbxref.inc

@@ -114,7 +114,7 @@ class chado_linker__dbxref extends TripalField {
     $chado_table = $field['settings']['chado_table'];
     foreach ($items as $delta => $item) {
       if ($item['value']) {
-        $content = $item['value']['namespace'] . ':' . $item['value']['accession'];
+        $content = $item['value']['vocabulary'] . ':' . $item['value']['accession'];
         if ($item['value']['URL']) {
           $content = l($item['value']['URL'], $item['value']['URL']);
         }
@@ -301,7 +301,7 @@ class chado_linker__dbxref extends TripalField {
         $dbxref = $linker->dbxref_id;
         $entity->{$field_name}['und'][$i] = array(
           'value' => array(
-            'namespace' => $dbxref->db_id->name,
+            'vocabulary' => $dbxref->db_id->name,
             'accession' => $dbxref->accession,
             'URL' => $URL,
           ),

+ 2 - 2
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -57,8 +57,8 @@ class chado_linker__relationship extends TripalField {
         'base_table' => $table_name,
         'semantic_web' => array(
           'name' => 'relationship',
-          'accession' => 'relationship',
-          'ns' => 'local',
+          'accession' => '0000374',
+          'ns' => 'SBO',
           'nsurl' => '',
         ),
       ),

+ 4 - 4
tripal_chado/includes/fields/chado_organism__type_id.inc

@@ -52,10 +52,10 @@ class chado_organism__type_id extends TripalField {
           'chado_table' => 'organism',
           'chado_column' => 'type_id',
           'semantic_web' => array(
-            'name' => 'infraspecificTaxon',
-            'accession' => '0000046',
-            'ns' => 'TAXRANK',
-            'nsurl' => 'https://github.com/phenoscape/taxrank',
+            'name' => 'infraspecific_type',
+            'accession' => 'infraspecific_type',
+            'ns' => 'local',
+            'nsurl' => '',
           ),
         ),
       );

+ 36 - 4
tripal_chado/includes/tripal_chado.fields.inc

@@ -468,11 +468,43 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
   //
   // ORGANISM TABLE
   //
-  elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
-    $field['label'] = 'Description';
+  elseif ($field['field_settings']['chado_table'] == 'organism') {
+    if ($field['field_settings']['chado_column'] == 'comment') {
+      $field['label'] = 'Description';
+    }
+    elseif ($field['field_settings']['chado_column'] == 'genus') {
+      $field['field_settings']['semantic_web']['name'] = 'genus';
+      $field['field_settings']['semantic_web']['accession'] = '0000005';
+      $field['field_settings']['semantic_web']['ns'] = 'TAXRANK';
+      $field['field_settings']['semantic_web']['nsurl'] = 'https://github.com/phenoscape/taxrank';
+    }
+    elseif ($field['field_settings']['chado_column'] == 'species') {
+      $field['field_settings']['semantic_web']['name'] = 'species';
+      $field['field_settings']['semantic_web']['accession'] = '0000006';
+      $field['field_settings']['semantic_web']['ns'] = 'TAXRANK';
+      $field['field_settings']['semantic_web']['nsurl'] = 'https://github.com/phenoscape/taxrank';
+    }
+    elseif ($field['field_settings']['chado_column'] == 'infraspecific_name') {
+      $field['field_settings']['semantic_web']['name'] = 'infraspecies';
+      $field['field_settings']['semantic_web']['accession'] = '0000045';
+      $field['field_settings']['semantic_web']['ns'] = 'TAXRANK';
+      $field['field_settings']['semantic_web']['nsurl'] = 'https://github.com/phenoscape/taxrank';
+    }
+    elseif ($field['field_settings']['chado_column'] == 'common_name') {
+      $field['field_settings']['semantic_web']['name'] = 'common name';
+      $field['field_settings']['semantic_web']['accession'] = 'common_name';
+      $field['field_settings']['semantic_web']['ns'] = 'NCBITaxon';
+      $field['field_settings']['semantic_web']['nsurl'] = 'https://github.com/phenoscape/taxrank';
+    }
+    elseif ($field['field_settings']['chado_column'] == 'abbreviation') {
+      $field['field_settings']['semantic_web']['name'] = 'abbreviation';
+      $field['field_settings']['semantic_web']['accession'] = 'abbreviation';
+      $field['field_settings']['semantic_web']['ns'] = 'local';
+      $field['field_settings']['semantic_web']['nsurl'] = '';
+    }
   }
   //
-  // FEATURE TABLE
+  // PUB TABLE
   //
   elseif ($field['field_settings']['chado_table'] == 'pub' and $field['field_settings']['chado_column'] == 'uniquename') {
     $field['field_type'] = 'text';
@@ -647,7 +679,7 @@ function tripal_chado_get_bundle_fields($entity_type, $bundle, $term) {
   $match = array(
     'dbxref_id' => array(
       'db_id' => array(
-        'name' => $vocab->namespace,
+        'name' => $vocab->vocabulary,
       ),
       'accession' => $term->accession
     ),

+ 17 - 16
tripal_chado/includes/tripal_chado.migrate.inc

@@ -132,7 +132,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
       if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
         // Get all Tripal v2 node types from the chad_* linking table
         $sql =
-          "SELECT V.name AS type, X.accession, db.name AS namespace , count(*) AS num
+          "SELECT V.name AS type, X.accession, db.name AS vocabulary , count(*) AS num
               FROM {" . $table . "} T
               INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
               INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
@@ -144,11 +144,11 @@ function tripal_chado_migrate_form($form, &$form_state) {
               GROUP BY V.name, X.accession, db.name";
         $tv3_content_types = chado_query($sql);
         while($tv3_content_type = $tv3_content_types->fetchObject()) {
-          // We need to store namespace/accession/type for each checkbox in the key becuase
+          // We need to store vocabulary/accession/type for each checkbox in the key becuase
           // the value only allows 1 or 0
           $key = urlencode(
             'tv3_content_type--' .
-            $tv3_content_type->namespace . '--' .
+            $tv3_content_type->vocabulary . '--' .
             $tv3_content_type->accession . '--' .
             $tv3_content_type->type);
           $form['step2']['step2_container']['tv3_content_type'][$key] = array(
@@ -316,7 +316,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
  * @param $form_state
  */
 function tripal_chado_migrate_form_validate($form, &$form_state) {
- 
+
 }
 
 /**
@@ -381,7 +381,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
     $includes = array(
       module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.migrate'),
     );
-  
+
     if (count($config['cp_title']) > 0) {
       $args = array($config['cp_title']);
       tripal_add_job("Copy Title over to Tripal v3 Content", 'tripal_chado',
@@ -415,11 +415,11 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
         $key = urldecode($key);
         if (preg_match('/^tv3_content_type--(.+)--(.+)--(.+)/', $key, $matches) &&
             ($value == 1 || $values['tv3_migrate_all'] == 1)) {
-          $namespace = $matches[1];
+          $vocabulary = $matches[1];
           $accession = $matches[2];
           $type = $matches[3];
           $tv3_content_type [] = array(
-            'namespace' => $namespace,
+            'vocabulary' => $vocabulary,
             'accession' => $accession,
             'term_name' => $type
           );
@@ -507,7 +507,7 @@ function tripal_chado_get_tripal_v2_content_type_options($all_option = FALSE, $h
     else {
       if (in_array($obj->type, $tables)) {
         $options[$obj->type] = $obj->name;
-      }      
+      }
     }
   }
   return $options;
@@ -538,9 +538,10 @@ function tripal_chado_get_tripal_v2_content_type_options($all_option = FALSE, $h
 /**
  * Migrate all Tripal v2 content types
  *
- * Gather all available Tripal v2 content types and store the result in an associated array with
- * values of namespace, accession, term_name. The array is then pass to the function
- * tripal_chado_migrate_selected_types() that handles the migration
+ * Gather all available Tripal v2 content types and store the result in an
+ * associated array with values of vocabulary, accession, term_name. The array
+ * is then pass to the function tripal_chado_migrate_selected_types() that
+ * handles the migration.
  */
 function tripal_chado_migrate_all_types() {
   // Get all available Tripal v2 content types
@@ -556,7 +557,7 @@ function tripal_chado_migrate_all_types() {
     if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
       // Get all Tripal v2 node types from the chad_* linking table
       $sql = "
-        SELECT V.name AS type, X.accession, db.name AS namespace
+        SELECT V.name AS type, X.accession, db.name AS vocabulary
         FROM {" . $table . "} T
           INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
           INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
@@ -567,7 +568,7 @@ function tripal_chado_migrate_all_types() {
       $tv3_content_types = chado_query($sql);
       while($tv3_content_type = $tv3_content_types->fetchObject()) {
         array_push($types, array(
-          'namespace' => $tv3_content_type->namespace,
+          'vocabulary' => $tv3_content_type->vocabulary,
           'accession' => $tv3_content_type->accession,
           'term_name' => $tv3_content_type->type
         ));
@@ -575,14 +576,14 @@ function tripal_chado_migrate_all_types() {
     }
     else if ($table == 'organism') {
       array_push($types, array(
-        'namespace' => 'local',
+        'vocabulary' => 'local',
         'accession' => 'organism',
         'term_name' => 'organism'
       ));
     }
     else if ($table == 'analysis') {
       array_push($types, array(
-        'namespace' => 'local',
+        'vocabulary' => 'local',
         'accession' => 'analysis',
         'term_name' => 'analysis'
       ));
@@ -606,7 +607,7 @@ function tripal_chado_migrate_selected_types($tv3_content_types) {
     // If term doesn't exist, create a new bundle for this term
     if (!$term) {
       print("Creating bundle for term '" . $tv3_content_type['term_name'] . "'...\n");
-      $success = tripal_create_bundle($tv3_content_type['namespace'], $tv3_content_type['accession'], $tv3_content_type['term_name']);
+      $success = tripal_create_bundle($tv3_content_type['vocabulary'], $tv3_content_type['accession'], $tv3_content_type['term_name']);
       $term = tripal_load_term_entity($tv3_content_type);
     }
     // Create bundle name

+ 0 - 222
tripal_chado/includes/tripal_chado.term_storage.inc

@@ -1,222 +0,0 @@
-<?php
-/**
- * Implements hook_vocab_storage_info().
- */
-function tripal_chado_vocab_storage_info() {
-  return array(
-    'term_chado_storage' => array(
-      'label' => t('Chado storage'),
-      'module' => 'tripal_chado',
-      'description' => t('Integrates terms stored in the local Chado database with Tripal entities.'),
-      'settings' => array(),
-    ),
-  );
-}
-
-/**
- * Implements hook_vocab_get_term().
- */
-function tripal_chado_vocab_get_term($namespace, $accession) {
-  // Create an empty term array for returning if there is a problem.
-  $empty_term = array(
-    'namespace'  => $namespace,
-    'accession'  => $accession,
-    'name'       => '',
-    'definition' => 'Term is undefined.',
-    'url'  => '',
-    // The following are not required for the returned array but we'll
-    // add these for convenience later when we look at the TripalTerm
-    // objects and these will be there.
-    'cvterm'     => NULL,
-  );
-
-  // It's possible that Chado is not available (i.e. it gets renamed
-  // for copying) but Tripal has already been prepared and the
-  // entities exist.  If this is the case we don't want to run the
-  // commands below.
-  if (!chado_table_exists('cvterm')) {
-    return $empty_term;
-  }
-  $match = array(
-    'dbxref_id' => array(
-      'db_id' => array(
-        'name' => $namespace,
-      ),
-      'accession' => $accession,
-    ),
-  );
-  $cvterm = chado_generate_var('cvterm', $match);
-  if (!$cvterm) {
-    return $empty_term;
-  }
-  $cvterm = chado_expand_var($cvterm, 'field', 'cvterm.definition');
-  $term = array(
-    'namespace'  => $cvterm->dbxref_id->db_id->name,
-    'accession'  => $cvterm->dbxref_id->accession,
-    'name'       => $cvterm->name,
-    'url'        => '',
-    'definition' => (isset($cvterm->definition)) ? $cvterm->definition : '',
-    // The following are not required for the returned array but we'll
-    // add these for convenience later when we look at the TripalTerm
-    // objects and these will be there.
-    'cvterm'     => $cvterm,
-  );
-  if ($cvterm->dbxref_id->db_id->urlprefix) {
-    $term['url'] = $cvterm->dbxref_id->db_id->urlprefix .
-      $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession;
-  }
-  return $term;
-}
-
-/**
- * Implements hook_vocab_import_form();
- */
-function tripal_chado_vocab_import_form($form, &$form_state) {
-  module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader');
-  return tripal_cv_obo_form($form, $form_state);
-}
-/**
- * Implements hook_vocab_import_form_validate();
- */
-function tripal_chado_vocab_import_form_validate($form, &$form_state) {
-  module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader');
-  return tripal_cv_obo_form_validate($form, $form_state);
-}
-/**
- * Implements hook_vocab_import_form_submit();
- */
-function tripal_chado_vocab_import_form_submit($form, &$form_state) {
-  module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader');
-  return tripal_cv_obo_form_submit($form, $form_state);
-}
-/**
- * Implements hook_vocab_select_term_form().
- */
-function tripal_chado_vocab_select_term_form($form, &$form_state) {
-  $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
-
-  // If no term has been selected yet then provide the auto complete field.
-  $form['term_name'] = array(
-    '#title'       => t('Content Type'),
-    '#type'        => 'textfield',
-    '#description' => t("The content type must be the name of a term in
-        a controlled vocabulary and the controlled vocabulary should
-        already be loaded into Tripal.  For example, to create a content
-        type for storing 'genes', use the 'gene' term from the
-        Sequence Ontology (SO)."),
-    '#required'    => TRUE,
-    '#default_value' => $term_name,
-    '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
-  );
-  $form['select_button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Lookup Term'),
-    '#name' => 'select_cvterm',
-    '#ajax' => array(
-      'callback' => "tripal_chado_vocab_select_term_form_ajax_callback",
-      'wrapper' => "tripal-chado-vocab-select-form",
-      'effect' => 'fade',
-      'method' => 'replace'
-    ),
-  );
-
-  if ($term_name) {
-    $form['terms_list'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Matching Terms'),
-      '#description' => t('Please select the term the best matches the
-          content type you want to create. If the same term exists in
-          multiple vocabularies you will see more than one option below.')
-    );
-    $match = array(
-      'name' => $term_name,
-    );
-    $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
-    $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
-    $num_terms = 0;
-    foreach ($terms as $term) {
-      // Save the user a click by setting the default value as 1 if there's
-      // only one matching term.
-      $default = FALSE;
-      $attrs = array();
-      if ($num_terms == 0 and count($terms) == 1) {
-        $default = TRUE;
-        $attrs = array('checked' => 'checked');
-      }
-       $form['terms_list']['term-' . $term->cvterm_id] = array(
-         '#type' => 'checkbox',
-         '#title' =>  $term->name,
-         '#default_value' => $default,
-         '#attributes' => $attrs,
-         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name .
-             '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-             '<br><b>Definition:</b>  ' . $term->definition,
-       );
-       $num_terms++;
-    }
-    if ($num_terms == 0) {
-      $form['terms_list']['none'] = array(
-        '#type' => 'item',
-        '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
-      );
-    }
-    // Add in the button for the cases of no terms or too many.
-    $form['submit_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Use this term'),
-      '#name' => 'use_cvterm'
-    );
-  }
-
-  $form['#prefix'] = '<div id = "tripal-chado-vocab-select-form">';
-  $form['#suffix'] = '</div>';
-
-  return $form;
-}
-
-/**
- * Implements an AJAX callback for the tripal_chado_vocab_select_term_form.
- */
-function tripal_chado_vocab_select_term_form_ajax_callback($form, $form_state) {
-  return $form;
-}
-
-/**
- * Implements hook_vocab_select_term_form_validate().
- */
-function tripal_chado_vocab_select_term_form_validate($form, &$form_state) {
-
-  if (array_key_exists('clicked_button', $form_state) and
-      $form_state['clicked_button']['#name'] =='use_cvterm') {
-
-    $cvterm_id = NULL;
-
-    // Make sure we have a cvterm selected
-    $num_selected = 0;
-    foreach ($form_state['values'] as $key => $value) {
-      $matches = array();
-      if (preg_match("/^term-(\d+)$/", $key, $matches) and
-          $form_state['values']['term-' . $matches[1]]) {
-        $cvterm_id = $matches[1];
-        $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
-        $num_selected++;
-      }
-    }
-    if ($num_selected == 0) {
-      form_set_error('', 'Please select at least one term.');
-    }
-    else if ($num_selected > 1) {
-      form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
-    }
-    else {
-      $form_state['storage']['namespace'] = $term->dbxref_id->db_id->name;
-      $form_state['storage']['accession'] = $term->dbxref_id->accession;
-      $form_state['storage']['term_name'] = $term->name;
-    }
-  }
-  // For any other button click it's an AJAX call and we just want to reubild
-  // the form.
-  else {
-    $form_state['rebuild'] = TRUE;
-  }
-}

+ 37 - 0
tripal_chado/tripal_chado.install

@@ -54,6 +54,38 @@ function tripal_chado_uninstall() {
 //   ');
 }
 
+function tripal_chado_chado_semweb_schema(){
+  return array(
+    'fields' => array(
+      'chado_semweb_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE
+      ),
+      'chado_table' => array(
+        'type' => 'varchar',
+        'length ' => 128,
+      ),
+      'chado_column' => array(
+        'type' => 'text',
+        'length ' => 128,
+        'not null' => TRUE
+      ),
+      'cvterm_id' => array(
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+    ),
+    'primary key' => array(
+      0 => 'chado_semweb_id',
+    ),
+    'indexes' => array(
+      'chado_semweb_id_idx1' => array('cvterm_id'),
+      'chado_semweb_id_idx2' => array('chado_column'),
+      'chado_semweb_id_idx3' => array('chado_table', 'chado_table'),
+    )
+  );
+}
+
 /**
  * Table definition for the tripal_cv_obo table
  * @param $schema
@@ -154,6 +186,8 @@ function tripal_chado_schema() {
 
   // Links TripalEntity entities to the chado record.
   $schema['chado_entity'] = tripal_chado_chado_entity_schema();
+  $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
+
   $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
   $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
 
@@ -161,6 +195,7 @@ function tripal_chado_schema() {
   $schema['tripal_cv_defaults'] = tripal_chado_tripal_cv_defaults_schema();
   $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
 
+
   // if this module is already installed and enabled, then we want to provide
   // the schemas for all of the custom tables.  This will allow Views to
   // see the schemas.  We check if the module is installed because during
@@ -175,6 +210,8 @@ function tripal_chado_schema() {
     }
   }
 
+
+
   return $schema;
 }
 

+ 1 - 1
tripal_chado/tripal_chado.module

@@ -33,7 +33,7 @@ require_once 'api/modules/tripal_chado.stock.api.inc';
 // ways be included when the module is interpreted.
 require_once "includes/tripal_chado.entity.inc";
 require_once "includes/tripal_chado.schema.inc";
-require_once "includes/tripal_chado.term_storage.inc";
+require_once "includes/tripal_chado.vocab_storage.inc";
 require_once "includes/tripal_chado.field_storage.inc";
 require_once "includes/tripal_chado.fields.inc";
 

+ 62 - 43
tripal_ws/includes/tripal_ws.rest.inc

@@ -7,8 +7,8 @@ function tripal_ws_rest() {
 
   global $base_url;
   $ws_path = func_get_args();
-  $ws_get_args = $_GET;
-  unset($ws_get_args['q']);
+  $params = $_GET;
+  unset($params['q']);
 
   // The web services should never be cached.
   drupal_page_is_cacheable(FALSE);
@@ -37,7 +37,7 @@ function tripal_ws_rest() {
         tripal_ws_handle_doc_service($api_url, $response);
         break;
       case 'content':
-        tripal_ws_handle_content_service($api_url, $response, $ws_path);
+        tripal_ws_handle_content_service($api_url, $response, $ws_path, $params);
         break;
       case 'vocab':
         tripal_ws_handle_vocab_service($api_url, $response, $ws_path);
@@ -77,7 +77,7 @@ function tripal_ws_rest() {
  * @param $response
  * @param $ws_path
  */
-function tripal_ws_handle_content_service($api_url, &$response, $ws_path) {
+function tripal_ws_handle_content_service($api_url, &$response, $ws_path, $params) {
 
   // Get the content type.
   $ctype     = (count($ws_path) > 1) ? $ws_path[1] : '';
@@ -90,7 +90,7 @@ function tripal_ws_handle_content_service($api_url, &$response, $ws_path) {
   // If we don't have an entity ID then show a paged list of entities with
   // the given type.
   else if ($ctype and !$entity_id) {
-    tripal_ws_get_content_type($api_url, $response, $ws_path, $ctype);
+    tripal_ws_get_content_type($api_url, $response, $ws_path, $ctype, $params);
   }
   // If we have a content type and an entity ID then show the entity
   else {
@@ -106,20 +106,20 @@ function tripal_ws_handle_content_service($api_url, &$response, $ws_path) {
 function tripal_ws_handle_vocab_service($api_url, &$response, $ws_path) {
 
   // Get the vocab name.
-  $namespace = (count($ws_path) > 1) ? $ws_path[1] : '';
+  $vocabulary = (count($ws_path) > 1) ? $ws_path[1] : '';
   $accession = (count($ws_path) > 2) ? $ws_path[2] : '';
 
-  // If we have no $namespace type then list all of the available vocabs.
-  if (!$namespace) {
+  // If we have no $vocabulary type then list all of the available vocabs.
+  if (!$vocabulary) {
     tripal_ws_get_vocabs($api_url, $response);
   }
-  // If we don't have a $namespace then show a paged list of terms.
-  else if ($namespace and !$accession) {
-    tripal_ws_get_vocab($api_url, $response, $ws_path, $namespace);
+  // If we don't have a $vocabulary then show a paged list of terms.
+  else if ($vocabulary and !$accession) {
+    tripal_ws_get_vocab($api_url, $response, $ws_path, $vocabulary);
   }
   // If we have a content type and an entity ID then show the entity
-  else if ($namespace and $accession) {
-    tripal_ws_get_term($api_url, $response, $ws_path, $namespace, $accession);
+  else if ($vocabulary and $accession) {
+    tripal_ws_get_term($api_url, $response, $ws_path, $vocabulary, $accession);
   }
 }
 
@@ -151,9 +151,9 @@ function tripal_ws_get_vocabs($api_url, &$response) {
     $term =
     // Add the bundle as a content type.
     $response['member'][] = array(
-      '@id' => $api_url . '/vocab/' . urlencode($vocab->namespace),
+      '@id' => $api_url . '/vocab/' . urlencode($vocab->vocabulary),
       '@type' => 'vocabulary',
-      'namespace' => $vocab->namespace,
+      'vocabulary' => $vocab->vocabulary,
     );
     $i++;
   }
@@ -175,7 +175,7 @@ function tripal_ws_get_vocabs($api_url, &$response) {
  * @param $response
  * @param $ws_path
  */
-function tripal_ws_get_vocab($api_url, &$response, $ws_path, $namespace) {
+function tripal_ws_get_vocab($api_url, &$response, $ws_path, $vocabulary) {
 
   // First, add the vocabularies used into the @context section.
   $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
@@ -183,15 +183,15 @@ function tripal_ws_get_vocab($api_url, &$response, $ws_path, $namespace) {
   $response['@context']['schema'] = 'https://schema.org/';
 
   // Next add in the ID for tihs resource.
-  $response['@id'] = $api_url . '/vocab/' . $namespace;
+  $response['@id'] = $api_url . '/vocab/' . $vocabulary;
 
   // Get the vocabulary
-  $vocab = tripal_load_vocab_entity(array('namespace' => $namespace));
+  $vocab = tripal_load_vocab_entity(array('vocabulary' => $vocabulary));
 
   // Start the list.
   $response['@type'] = 'Collection';
   $response['totalItems'] = 0;
-  $response['label'] = $namespace . " vocabulary collection";
+  $response['label'] = vocabulary . " vocabulary collection";
   $response['comment'] = 'The following list of terms may not be the full ' .
     'list for the vocabulary.  The terms listed here are only those ' .
     'that have associated content on this site.';
@@ -208,9 +208,9 @@ function tripal_ws_get_vocab($api_url, &$response, $ws_path, $namespace) {
   while($term = $terms->fetchObject()) {
     $term = tripal_load_term_entity(array('term_id' => $term->id));
     $response['member'][] = array(
-      '@id' => $api_url . '/vocab/' . urlencode($namespace) . '/' .  urlencode($term->accession),
+      '@id' => $api_url . '/vocab/' . urlencode($vocabulary) . '/' .  urlencode($term->accession),
       '@type' => 'vocabulary_term',
-      'namespace' => $vocab->namespace,
+      'vocabulary' => $vocab->vocabulary,
       'accession' => $term->accession,
       'name' => $term->name,
       'definition' => $term->definition,
@@ -235,7 +235,7 @@ function tripal_ws_get_vocab($api_url, &$response, $ws_path, $namespace) {
  * @param $response
  * @param $ws_path
  */
-function tripal_ws_get_term($api_url, &$response, $ws_path, $namespace, $accession) {
+function tripal_ws_get_term($api_url, &$response, $ws_path, $vocabulary, $accession) {
 
   // First, add the vocabularies used into the @context section.
   $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
@@ -243,13 +243,13 @@ function tripal_ws_get_term($api_url, &$response, $ws_path, $namespace, $accessi
   $response['@context']['schema'] = 'https://schema.org/';
 
   // Get the term.
-  $term = tripal_load_term_entity(array('namespace' => $namespace, 'accession' => $accession));
+  $term = tripal_load_term_entity(array('vocabulary' => $vocabulary, 'accession' => $accession));
 
   // Next add in the ID and Type for this resources.
-  $response['@id'] = $api_url . '/vocab/' . urlencode($namespace) . '/' . urlencode($accession);
+  $response['@id'] = $api_url . '/vocab/' . urlencode($vocabulary) . '/' . urlencode($accession);
   $response['@type'] = 'vocabulary_term';
   $response['label'] = $term->name;
-  $response['namespace'] = $namespace;
+  $response['vocabulary'] = $vocabulary;
   $response['accession'] = $accession;
   $response['name'] = $term->name;
   $response['definition'] = $term->definition;
@@ -297,13 +297,13 @@ function tripal_ws_get_content_types($api_url, &$response) {
     $term = reset($entity);
     $vocab = $term->vocab;
 
-    if (!array_key_exists($vocab->namespace, $response['@context'])) {
+    if (!array_key_exists($vocab->vocabulary, $response['@context'])) {
       // If there is no URL prefix then use this API's vocabulary API
       if ($term->urlprefix) {
-        $response['@context'][$vocab->namespace] = $term->urlprefix;
+        $response['@context'][$vocab->vocabulary] = $term->urlprefix;
       }
       else {
-        $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
+        $response['@context'][$vocab->vocabulary] = $api_url . '/vocab/' . $vocab->vocabulary . '/';
       }
     }
     // Get the bundle description. If no description is provided then
@@ -315,7 +315,7 @@ function tripal_ws_get_content_types($api_url, &$response) {
     // Add the bundle as a content type.
     $response['member'][] = array(
       '@id' => $api_url . '/content/' . urlencode($bundle->label),
-      '@type' => $vocab->namespace . ':' . $term->accession,
+      '@type' => $vocab->vocabulary . ':' . $term->accession,
       'label' => $bundle->label,
       'description' => $description,
     );
@@ -337,7 +337,7 @@ function tripal_ws_get_content_types($api_url, &$response) {
  * @param $response
  * @param $ws_path
  */
-function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype) {
+function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype, $params) {
 
   // First, add the vocabularies used into the @context section.
   $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
@@ -353,13 +353,13 @@ function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype) {
   $term = reset($term);
   $vocab = $term->vocab;
 
-  if (!array_key_exists($vocab->namespace, $response['@context'])) {
+  if (!array_key_exists($vocab->vocabulary, $response['@context'])) {
     // If there is no URL prefix then use this API's vocabulary API
     if ($term->urlprefix) {
-      $response['@context'][$vocab->namespace] = $term->urlprefix;
+      $response['@context'][$vocab->vocabulary] = $term->urlprefix;
     }
     else {
-      $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
+      $response['@context'][$vocab->vocabulary] = $api_url . '/vocab/' . $vocab->vocabulary . '/';
     }
   }
 
@@ -368,12 +368,31 @@ function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype) {
   $response['totalItems'] = 0;
   $response['label'] = $bundle->label . " collection";
 
+
+
+  // Organize the fields by their web service names.
+  $fields = field_info_fields();
+  $field_ws_names = array();
+  foreach ($fields as $field_name => $details) {
+    if (array_key_exists('settings', $details) and
+         array_key_exists('semantic_web', $details['settings'])) {
+      $sw_name = $details['settings']['semantic_web']['name'];
+      $field_ws_names[$sw_name][] = $field_name;
+    }
+  }
+
   // Get the list of entities for this bundle.
   $query = new TripalFieldQuery();
   $query->fieldCondition('content_type', $term->id);
+  foreach($params as $key => $value) {
+    foreach ($field_ws_names[$key] as $field_name) {
+      $query->fieldCondition($field_name, $value);
+    }
+  }
   $results = $query->execute();
 
-  // Get the entities
+  // Get the entities from the above search.  We do a direct query of the
+  // table because the load_entity() function is too slow.
   $query = db_select('tripal_entity', 'TE');
   $query->fields('TE');
   $query->condition('id', array_keys($results['TripalEntity']));
@@ -384,7 +403,7 @@ function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype) {
   while($entity = $results->fetchObject()) {
     $response['member'][] = array(
       '@id' => $api_url . '/content/' . urlencode($ctype) . '/' .  $entity->id,
-      '@type' => $vocab->namespace . ':' . $term->accession,
+      '@type' => $vocab->vocabulary . ':' . $term->accession,
       'label' => $entity->title,
       'itemPage' => url('/bio_data/' . $entity->id, array('absolute' => TRUE)),
     );
@@ -436,13 +455,13 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
   $term = reset($term);
   $vocab = $term->vocab;
 
-  if (!array_key_exists($vocab->namespace, $response['@context'])) {
+  if (!array_key_exists($vocab->vocabulary, $response['@context'])) {
     // If there is no URL prefix then use this API's vocabulary API
     if (property_exists($term, 'urlprefix')) {
-      $response['@context'][$vocab->namespace] = $term->urlprefix;
+      $response['@context'][$vocab->vocabulary] = $term->urlprefix;
     }
     else {
-      $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
+      $response['@context'][$vocab->vocabulary] = $api_url . '/vocab/' . $vocab->vocabulary . '/';
     }
   }
 
@@ -454,7 +473,7 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
 
   // Next add in the ID and Type for this resources.
   $response['@id'] = $api_url . '/content/' . $ctype . '/' . $entity_id;
-  $response['@type'] = $vocab->namespace . ':' . $term->accession;
+  $response['@type'] = $vocab->vocabulary . ':' . $term->accession;
   $response['label'] = $entity->title;
   $response['itemPage'] = url('/bio_data/' . $entity->id, array('absolute' => TRUE));
 
@@ -514,14 +533,14 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
         $lvocab = tripal_load_vocab_entity(array('vocab_id' => $lterm->vocab_id));
         $value[] = array(
           '@id'   => $api_url . '/content/' . $lterm->name . '/' . $items[0]['entity_id'],
-          '@type' => $lvocab->namespace . ':' . $lterm->accession,
+          '@type' => $lvocab->vocabulary . ':' . $lterm->accession,
           'label' => $lentity->title,
           'type' => $lterm->name,
         );
 
-        if (property_exists($lvocab, 'namespace') and !array_key_exists($lvocab->namespace, $response['@context'])) {
-          $lterm_details = tripal_get_term_details($lvocab->namespace, $lterm->namespace);
-          $response['@context'][$lvocab->namespace] = $lterm_details->url;
+        if (property_exists($lvocab, 'vocabulary') and !array_key_exists($lvocab->vocabulary, $response['@context'])) {
+          $lterm_details = tripal_get_term_details($lvocab->vocabulary, $lterm->vocabulary);
+          $response['@context'][$lvocab->vocabulary] = $lterm_details->url;
         }
       }
       else {