Browse Source

moving control of semantic web settings out of field classes

Stephen Ficklin 8 years ago
parent
commit
5104bf6ce0

+ 1 - 17
tripal/api/tripal.entities.api.inc

@@ -476,22 +476,6 @@ function hook_add_bundle_fields($entity_type, $bundle, $term) {
   $schema = chado_get_schema($syn_table);
   $pkey = $schema['primary key'][0];
 
-
-  // Tripal wants to map fields to a controlled vocabulary terms
-  // (e.g SO:0000704 for a 'gene').  This is not required, but is highly
-  // recommended to support mashups of data via web services.
-  $semantic_web = array(
-    // The type is the term from a vocabulary that desribes this field..
-    'name' => '',
-    // The accession in the vocabulary for this term.
-    'accession' => '',
-    // 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' => '',
-  );
-
   // The Tripal Chado module needs to know what Chado table and field
   // this field maps to, as well as the base table that it maps to
   // if this field will map to a record in a linking table.
@@ -502,7 +486,7 @@ function hook_add_bundle_fields($entity_type, $bundle, $term) {
     'chado_column' => $pkey,
     // The base table that this field is connected to.
     'base_table' => $base_table,
-    'semantic_web' => $semantic_web,
+    'semantic_web' => '',
   );
 
   // Finally set the field values.

+ 13 - 38
tripal/includes/TripalField.inc

@@ -244,45 +244,20 @@ class TripalField {
     $settings = $field['settings'];
     $element = array();
 
-    $element['semantic_web'] = array(
-      '#type' => 'fieldset',
-      '#title' => 'Semantic Web',
-      '#description' => t('Each field must be associated with a term
-          from a controlled vocabulary.  This allows computer programs to understand
-          the data provided on this site.  Please be cautions changing these
-          values.  Defaults are set by Tripal and sites that use the same
-          terms can exchange information.'),
-      '#collapsed' => TRUE,
-      '#collapsible' => TRUE,
-      '#tree' => TRUE,
-    );
+//     $element['semantic_web'] = array(
+//       '#type' => 'textfield',
+//       '#title' => 'Semantic Web',
+//       '#description' => t('Each field must be associated with a term
+//           from a controlled vocabulary.  This allows computer programs to understand
+//           the data provided on this site.  Please be cautions changing these
+//           values.  Defaults are set by Tripal and sites that use the same
+//           terms can exchange information.'),
+//       '#collapsed' => TRUE,
+//       '#collapsible' => TRUE,
+//       '#tree' => TRUE,
+//     );
+
 
-    $element['semantic_web']['name'] = array(
-      '#type' => 'textfield',
-      '#title' => 'Term Name',
-      '#description' => t('The name of the term (e.g. gene, mRNA, organism, etc.).'),
-      '#default_value' => $settings['semantic_web']['name'],
-    );
-    $element['semantic_web']['accession'] = array(
-      '#type' => 'textfield',
-      '#title' => 'Term ID',
-      '#description' => t('The unique term ID (accession) in the vocabulary (e.g. ' .
-          'for the term "gene" in the Sequence Ontology, the accession is "0000704").'),
-      '#default_value' => $settings['semantic_web']['accession'],
-    );
-    $element['semantic_web']['vocabulary'] = array(
-      '#type' => 'textfield',
-      '#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(
-      '#type' => 'textfield',
-      '#title' => 'Vocabulary URL',
-      '#description' => t('The web URL of the vocabulary..'),
-      '#default_value' => $settings['semantic_web']['nsurl'],
-    );
     return $element;
   }
 

+ 1 - 11
tripal/tripal.module

@@ -536,17 +536,7 @@ function tripal_add_bundle_fields($entity_type, $bundle, $term) {
     'is_required' => 0,
     'storage' => 'tripal_no_storage',
     'field_settings' => array(
-      'semantic_web' => array(
-        // The type is the term from a vocabulary that desribes this field..
-        'name' => '',
-        // The accession of the term in the vocabulary.
-        'accession' => '',
-        // 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' => '',
-      ),
+      'semantic_web' => '',
     ),
   );
 

+ 1 - 6
tripal_chado/includes/fields/chado_base__dbxref_id.inc

@@ -55,12 +55,7 @@ class chado_base__dbxref_id extends TripalField {
       'field_settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'dbxref_id',
-        'semantic_web' => array(
-          'name' => 'Accession',
-          'accession' => '2091',
-          'ns' => 'data',
-          'nsurl' => ' http://edamontology.org/',
-        ),
+        'semantic_web' => 'data:2091',
       ),
     );
 

+ 1 - 6
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -68,12 +68,7 @@ class chado_base__organism_id extends TripalField {
       'field_settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'organism_id',
-        'semantic_web' => array(
-          'name' => 'organism',
-          'accession' => 'organism',
-          'ns' => 'local',
-          'nsurl' => '',
-        ),
+        'semantic_web' => 'local:organism',
       ),
     );
 

+ 1 - 6
tripal_chado/includes/fields/chado_feature__md5checksum.inc

@@ -48,12 +48,7 @@ class chado_feature__md5checksum  extends TripalField {
         'field_settings' => array(
           'chado_table' => 'feature',
           'chado_column' => 'md5checksum',
-          'semantic_web' => array(
-            'name' => 'md5_checksum',
-            'accession' => 'md5_checksum',
-            'ns' => 'local',
-            'nsurl' => '',
-          ),
+          'semantic_web' => 'local:md5_checksum',
         ),
       );
     }

+ 1 - 6
tripal_chado/includes/fields/chado_feature__residues.inc

@@ -65,12 +65,7 @@ class chado_feature__residues extends TripalField {
       'field_settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'residues',
-        'semantic_web' => array(
-          'name' => 'sequence_feature',
-          'accession' => '0000110',
-          'ns' => 'SO',
-          'nsurl' => 'http://www.sequenceontology.org',
-        ),
+        'semantic_web' => 'SO:0000110',
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_feature__seqlen.inc

@@ -46,12 +46,7 @@ class chado_feature__seqlen extends TripalField {
         'field_settings' => array(
           'chado_table' => $table_name,
           'chado_column' => 'seqlen',
-          'semantic_web' => array(
-            'name' => 'Sequence length',
-            'accession' => '1249',
-            'ns' => 'data',
-            'nsurl' => 'http://edamontology.org/',
-          ),
+          'semantic_web' => 'data:1249',
         ),
       );
     }

+ 1 - 6
tripal_chado/includes/fields/chado_gene__transcripts.inc

@@ -56,12 +56,7 @@ class chado_gene__transcripts extends TripalField {
         'chado_table' => $rel_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'transcript',
-          'accession' => '0000673',
-          'ns' => 'SO',
-          'nsurl' => 'http://www.sequenceontology.org',
-        ),
+        'semantic_web' => 'SO:0000673',
       ),
     );
 

+ 1 - 6
tripal_chado/includes/fields/chado_linker__contact.inc

@@ -77,12 +77,7 @@ class chado_linker__contact extends TripalField {
         'chado_table' => $contact_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'contact',
-          'accession' => 'contact',
-          'ns' => 'local',
-          'nsurl' => '',
-        ),
+        'semantic_web' => 'local:contact'
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_linker__dbxref.inc

@@ -68,12 +68,7 @@ class chado_linker__dbxref extends TripalField {
           'chado_table' => $dbxref_table,
           'chado_column' => $pkey,
           'base_table' => $table_name,
-          'semantic_web' => array(
-            'name' => 'database cross reference',
-            'accession' => '0000554',
-            'ns' => 'SBO',
-            'nsurl' => 'http://www.ebi.ac.uk/sbo/main/',
-          ),
+          'semantic_web' => 'SBO:0000554',
         ),
       );
 

+ 1 - 6
tripal_chado/includes/fields/chado_linker__expression.inc

@@ -65,12 +65,7 @@ class chado_linker__expression extends TripalField {
         'chado_table' => $expression_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => '',
-          'accession' => '',
-          'ns' => '',
-          'nsurl' => '',
-        ),
+        'semantic_web' => 'local:expression',
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_linker__featureloc.inc

@@ -55,12 +55,7 @@ class chado_linker__featureloc extends TripalField {
         'chado_table' => 'featureloc',
         'chado_column' => $pkey,
         'base_table' => 'feature',
-        'semantic_web' => array(
-          'name' => 'position_of',
-          'accession' => 'position_of',
-          'ns' => 'SO',
-          'nsurl' => 'http://www.sequenceontology.org/',
-        ),
+        'semantic_web' => 'SO:position_of',
       ),
     );
 

+ 1 - 6
tripal_chado/includes/fields/chado_linker__genotype.inc

@@ -76,13 +76,8 @@ class chado_linker__genotype extends TripalField {
       'field_settings' => array(
         'chado_table' => $genotype_table,
         'chado_column' => $pkey,
+        'semantic_web' => 'SO:0001027',
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'genotype',
-          'accession' => 'genotype',
-          'ns' => 'local',
-          'nsurl' => '',
-        ),
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_linker__phenotype.inc

@@ -77,12 +77,7 @@ class chado_linker__phenotype extends TripalField {
         'chado_table' => $phenotype_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'phenotype',
-          'accession' => 'phenotype',
-          'ns' => 'local',
-          'nsurl' => '',
-        ),
+        'semantic_web' => 'SBO:0000358',
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_linker__pub.inc

@@ -55,12 +55,7 @@ class chado_linker_pub extends TripalField {
         'chado_table' => $pub_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'publication',
-          'accession' => 'publication',
-          'ns' => 'schema',
-          'nsurl' => 'https://schema.org/',
-        ),
+        'semantic_web' => 'schema:publication',
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -55,12 +55,7 @@ class chado_linker__relationship extends TripalField {
         'chado_table' => $rel_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'relationship',
-          'accession' => '0000374',
-          'ns' => 'SBO',
-          'nsurl' => '',
-        ),
+        'semantic_web' => 'SBO:0000374',
       ),
     );
 

+ 1 - 6
tripal_chado/includes/fields/chado_linker__synonym.inc

@@ -55,12 +55,7 @@ class chado_linker__synonym extends TripalField {
         'chado_table' => $syn_table,
         'chado_column' => $pkey,
         'base_table' => $table_name,
-        'semantic_web' => array(
-          'name' => 'alternateName',
-          'accession' => 'alternateName',
-          'ns' => 'schema',
-          'nsurl' => 'https://schema.org/',
-        ),
+        'semantic_web' => 'schema:alternateName',
       ),
     );
     return $field_info;

+ 1 - 6
tripal_chado/includes/fields/chado_organism__type_id.inc

@@ -51,12 +51,7 @@ class chado_organism__type_id extends TripalField {
         'field_settings' => array(
           'chado_table' => 'organism',
           'chado_column' => 'type_id',
-          'semantic_web' => array(
-            'name' => 'infraspecific_type',
-            'accession' => 'infraspecific_type',
-            'ns' => 'local',
-            'nsurl' => '',
-          ),
+          'semantic_web' => 'local:infraspecific_type',
         ),
       );
     }

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

@@ -351,17 +351,7 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
       'chado_table' => $table_name,
       // The column in the Chado table that this field maps to.
       'chado_column' => $column_name,
-      'semantic_web' => array(
-        // The type is the term from a vocabulary that desribes this field..
-        'name' => '',
-        // The accession ID for this term in the vocaulary.
-        'accession' => '',
-        // The namepsace for the vocabulary (e.g. 'foaf').
-        'ns' => '',
-        // The URL for the namespace.  It must be that the type can be
-        // appended to the URL.
-        'nsurl' => '',
-      ),
+      'semantic_web' => '',
     ),
   );
 
@@ -426,38 +416,10 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
 
   // Set some default semantic web information
   if ($column_name == 'uniquename') {
-    $field['field_settings']['semantic_web']['name'] = 'name';
-    $field['field_settings']['semantic_web']['accession'] = 'name';
-    $field['field_settings']['semantic_web']['ns'] = 'foaf';
-    $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
     $field['widget_type'] = 'text_textfield';
     $field['field_settings']['text_processing'] = 0;
   }
-  if ($column_name == 'name') {
-    // If this table also has a unqiuename field then use the 'name' field
-    // as an alternate name.
-    if (array_key_exists('uniquename', $schema['fields'])) {
-      $field['field_settings']['semantic_web']['name'] = 'alternateName';
-      $field['field_settings']['semantic_web']['accession'] = 'alternateName';
-      $field['field_settings']['semantic_web']['ns'] = 'schema';
-      $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
-    }
-    else {
-      $field['field_settings']['semantic_web']['name'] = 'name';
-      $field['field_settings']['semantic_web']['accession'] = 'name';
-      $field['field_settings']['semantic_web']['ns'] = 'foaf';
-      $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
-    }
-  }
-  if ($column_name == 'description' or $column_name == 'definition' or
-      $column_name == 'comment') {
-    $field['field_settings']['semantic_web']['name'] = 'description';
-    $field['field_settings']['semantic_web']['accession'] = 'description';
-    $field['field_settings']['semantic_web']['ns'] = 'hydra';
-    $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
-  }
-
-  if ($field['label'] == 'Timeaccessioned') {
+  elseif ($field['label'] == 'Timeaccessioned') {
     $field['label'] = 'Time Accessioned';
     $field['description'] = 'Please enter the time that this record was first added to the database.';
   }
@@ -468,40 +430,8 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
   //
   // ORGANISM TABLE
   //
-  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'] = '';
-    }
+  elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
+    $field['label'] = 'Description';
   }
   //
   // PUB TABLE
@@ -510,20 +440,12 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
     $field['field_type'] = 'text';
     $field['widget_type'] = 'text_textfield';
     $field['field_settings']['text_processing'] = 0;
-    $field['field_settings']['semantic_web']['name'] = 'Comment';
-    $field['field_settings']['semantic_web']['accession'] = 'Comment';
-    $field['field_settings']['semantic_web']['ns'] = 'schema';
-    $field['field_settings']['semantic_web']['nsurl'] = 'https://www.schema.org/';
   }
 
   //
   // ANALYSIS TABLE
   //
   elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
-    $field['field_settings']['semantic_web']['name'] = 'SoftwareApplication';
-    $field['field_settings']['semantic_web']['accession'] = 'SoftwareApplication';
-    $field['field_settings']['semantic_web']['ns'] = 'schema';
-    $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
     $field['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
     $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
   }
@@ -556,6 +478,7 @@ function tripal_chado_get_bundle_fields_base__fields_defaults($table_name, $sche
   elseif ($field['field_settings']['chado_table'] == 'project' and $field['field_settings']['chado_column'] == 'description') {
     $field['label'] = 'Short Description';
   }
+
   return $field;
 }
 
@@ -773,6 +696,37 @@ function tripal_chado_get_bundle_fields($entity_type, $bundle, $term) {
     $fields[$field_name] = $field_info;
   }
 
+  // Add in the semantic web details
+  foreach ($fields as $field_name => $field) {
+    if (!array_key_exists('chado_table', $field['field_settings'])) {
+      continue;
+    }
+    $chado_column = $field['field_settings']['chado_column'];
+    $chado_table = $field['field_settings']['chado_table'];
+
+    // Get the semantic web mapping for this field. First look for a
+    // table specific mapping.
+    $smweb = db_select('chado_semweb', 'CS')
+      ->fields('CS')
+      ->condition('chado_column', $chado_column)
+      ->condition('chado_table', $chado_table)
+      ->execute()
+      ->fetchObject();
+    // We don't have a table/column specific mapping, so let's look for a
+    // generic column mapping.
+    if (!$smweb) {
+      $smweb = db_select('chado_semweb', 'CS')
+      ->fields('CS')
+      ->condition('chado_column', $chado_column)
+      ->execute()
+      ->fetchObject();
+    }
+    if ($smweb) {
+      $cvterm = tripal_get_cvterm(array('cvterm_id' => $smweb->cvterm_id));
+      $fields[$field_name]['field_settings']['semantic_web'] = $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession;
+    }
+  }
+
   return $fields;
 }
 

+ 33 - 0
tripal_chado/includes/tripal_chado.setup.inc

@@ -1908,6 +1908,15 @@ function tripal_chado_populate_chado_semweb_table() {
   ));
   tripal_insert_cv('IAO','Information Artifact Ontology');
 
+
+  tripal_insert_db(array(
+    'name' => 'SBO',
+    'description' => 'Systems Biology. Terms commonly used in Systems Biology, and in particular in computational modeling.',
+    'url' => 'http://www.ebi.ac.uk/sbo/main/',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/SBO_',
+  ));
+  tripal_insert_cv('sbo','Systems Biology');
+
   //
   // GENERIC TERMS
   //
@@ -1969,6 +1978,21 @@ function tripal_chado_populate_chado_semweb_table() {
   ));
   tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $time_executed);
 
+
+  $dbxref = tripal_insert_cvterm(array(
+    'id' => 'SBO:0000554',
+    'name' => 'database cross reference',
+    'cv_name' => 'sbo',
+    'definition' => 'An annotation which directs one to information contained within a database.',
+  ));
+
+  $relationship = tripal_insert_cvterm(array(
+    'id' => 'SBO:0000374',
+    'name' => 'relationship',
+    'cv_name' => 'sbo',
+    'definition' => 'connectedness between entities and/or interactions representing their relatedness or influence. [ src_code:NR ]',
+  ));
+
   //
   // ANALYSIS TABLE
   //
@@ -2029,6 +2053,15 @@ function tripal_chado_populate_chado_semweb_table() {
   ));
   tripal_associate_chado_semweb_term('organism', 'infraspecific_name', $term);
 
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:infraspecific_type',
+    'name' => 'infraspecific_type',
+    'definition' => 'The connector type for the infraspecific name',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term('organism', 'type_id', $term);
+
   $term = tripal_insert_cvterm(array(
     'id' => 'NCBITaxon:common_name',
     'name' => 'common name',

+ 14 - 12
tripal_ws/includes/tripal_ws.rest.inc

@@ -444,6 +444,9 @@ function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype, $par
  */
 function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_id) {
 
+  $context_vocabs = array();
+  $context_terms = array();
+
   // First, add the vocabularies used into the @context section.
   $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
   $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
@@ -455,6 +458,7 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
   $term = reset($term);
   $vocab = $term->vocab;
 
+  // Add the vocabulary for this content type to the @context section.
   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')) {
@@ -503,16 +507,12 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
     // term from the vocabulary that the field is assigned. But in the
     // case that the field is not assigned a term, we must use the field name.
     $key = $field['field_name'];
-    if (array_key_exists('semantic_web', $settings)) {
-      if (array_key_exists('name', $settings['semantic_web']) and
-          $settings['semantic_web']['name']) {
-        $key = $settings['semantic_web']['name'];
-        $nsurl = $settings['semantic_web']['nsurl'];
-        $ns = $settings['semantic_web']['ns'];
-        $accession = $settings['semantic_web']['accession'];
-        $response['@context'][$ns] = $nsurl;
-        $response['@context'][$key] = $ns . ':' . $accession;
-      }
+    if (array_key_exists('semantic_web', $settings) and $settings['semantic_web']) {
+      list($vocabulary, $accession) = explode(':', $settings['semantic_web']);
+      $term = tripal_get_term_details($vocabulary, $accession);
+      $key = $term['name'];
+      $context_vocabs[$vocabulary] = $term['url'];
+      $context_terms[$key] = $settings['semantic_web'];
     }
 
     // Skip hidden fields.
@@ -557,8 +557,10 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
   }
 
   // Lastly, add in the terms used into the @context section.
-  $response['@context']['label'] = 'rdfs:label';
-  $response['@context']['itemPage'] = 'schema:itemPage';
+  $context_terms['label'] = 'rdfs:label';
+  $context_terms['itemPage'] = 'schema:itemPage';
+
+  $response['@context'] = array_merge($context_vocabs, $context_terms);
 
   $response['operation'][] = array(
     '@type' => 'hydra:DeleteResourceOperation',