瀏覽代碼

Fixing entity fields and web services

Stephen Ficklin 8 年之前
父節點
當前提交
6742365f61

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

@@ -268,7 +268,7 @@ function tripal_entity_access($entity) {
 }
 
 function tripal_form_tripal_entity_form_alter(&$form, &$form_state, $form_id) {
-  //dpm($form);
+
 }
 
 /**

+ 10 - 4
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -77,7 +77,13 @@ class sbo__database_cross_reference extends ChadoField {
 
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
-      'value' => array(),
+      'value' => array(
+        // Database name
+        'data:1056' => '',
+        // Accession
+        'data:2091' => '',
+        'schema:url' => '',
+      ),
       'chado-' . $field_table . '__' . $pkey => '',
       'chado-' . $field_table . '__' . $fkey_lcolumn => '',
       'chado-' . $field_table . '__dbxref_id' => '',
@@ -98,9 +104,9 @@ class sbo__database_cross_reference extends ChadoField {
         $URL = tripal_get_dbxref_url($dbxref);
         $entity->{$field_name}['und'][$i] = array(
           'value' => array(
-            'vocabulary' => $dbxref->db_id->name,
-            'accession' => $dbxref->accession,
-            'URL' => $URL,
+            'data:1056' => $dbxref->db_id->name,
+            'data:2091' => $dbxref->accession,
+            'schema:url' => $URL,
           ),
           'chado-' . $field_table . '__' . $pkey => $linker->$pkey,
           'chado-' . $field_table . '__' . $fkey_lcolumn => $linker->$fkey_lcolumn->$fkey_lcolumn,

+ 2 - 2
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc

@@ -26,9 +26,9 @@ class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
       if (!$item['value']) {
         continue;
       }
-      $content = $item['value']['vocabulary'] . ':' . $item['value']['accession'];
+      $content = $item['value']['data:1056'] . ':' . $item['value']['data:2091'];
       if ($item['value']['URL']) {
-        $content = l($content, $item['value']['URL'], array('attributes' => array('target' => '_blank')));
+        $content = l($content, $item['value']['schema:url'], array('attributes' => array('target' => '_blank')));
       }
       $element[$delta] = array(
         '#type' => 'markup',

+ 75 - 73
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -100,7 +100,25 @@ class sbo__relationship extends ChadoField {
 
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
-      'value' => array(),
+      'value' => array(
+      /* The following shows what may be present in the value array
+        // Clause
+        'SIO:000493' => '',
+        'local:relationship_subject' => array(
+          // Identifier
+          'data:0842' => '',
+          'schema:name' => '',
+          'rdfs:type' => ''
+        ),
+        'local:relationship_object' => array(
+          // Identifier
+          'data:0842' => '',
+          'schema:name' => '',
+          'rdfs:type' => '',
+        ),
+        'local:relationship_type' => '',
+      */
+      ),
       'chado-' . $field_table . '__' . $pkey => '',
       'chado-' . $field_table . '__subject_id' => '',
       'chado-' . $field_table . '__object_id' => '',
@@ -177,54 +195,47 @@ class sbo__relationship extends ChadoField {
         $object_name = $relationship->object_id->name;
         $object_type = $relationship->object_id->type_id->name;
         $entity->{$field_name}['und'][$i]['value'] = array(
-          'type' => $relationship->type_id->name,
-          'subject' => array(
-            'type' => $subject_type,
-            'name' => $subject_name,
+          'local:relationship_subject' => array(
+            'rdfs:type' => $subject_type,
+            'schema:name' => $subject_name,
           ),
-          'type' => $relationship->type_id->name,
-          'object' => array(
-            'type' => $object_type,
-            'name' => $object_name,
+          'local:relationship_type' => $relationship->type_id->name,
+          'local:relationship_object' => array(
+            'rdfs:type' => $object_type,
+            'schema:name' => $object_name,
             'entity' => 'TripalEntity:' . $entity->id,
           )
         );
         if (property_exists($relationship->subject_id, 'uniquename')) {
-          $entity->{$field_name}['und'][$i]['value']['subject']['identifier'] =  $relationship->subject_id->uniquename;;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['data:0842'] =  $relationship->subject_id->uniquename;;
         }
         if (property_exists($relationship->object_id, 'uniquename')) {
-          $entity->{$field_name}['und'][$i]['value']['object']['identifier'] = $relationship->object_id->uniquename;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['data:0842'] = $relationship->object_id->uniquename;
         }
         if (property_exists($relationship->subject_id, 'entity_id')) {
           $entity_id = $relationship->subject_id->entity_id;
-          $entity->{$field_name}['und'][$i]['value']['subject']['entity'] = 'TripalEntity:' . $entity_id;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['entity'] = 'TripalEntity:' . $entity_id;
         }
         $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
-        $entity->{$field_name}['und'][$i]['value']['phrase'] = 'The ' . $subject_type . ', ' .
-            $subject_name . ', ' . $verb . ' '  . $rel_type_clean . ' this '  .
-            $object_type . '.';
-
-            $entity->{$field_name}['und'][$i]['semantic_web'] = array(
-              'type' => $rel_acc,
-              'subject' => $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
-              'object' => $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->object_id->type_id->dbxref_id->accession,
-            );
-
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__subject_id'] = $relationship->subject_id->$subject_pkey;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__object_id'] = $relationship->object_id->$object_pkey;
-
-            $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
-            $entity->{$field_name}['und'][$i]['subject_name'] = $relationship->subject_id->name . ' [id: ' . $relationship->subject_id->$fkey_rcolumn . ']';
-            $entity->{$field_name}['und'][$i]['object_name'] = $relationship->object_id->name  . ' [id: ' . $relationship->object_id->$fkey_rcolumn . ']';
-            if (array_key_exists('value', $schema['fields'])) {
-              $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
-            }
-            if (array_key_exists('rank', $schema['fields'])) {
-              $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
-            }
-            $i++;
+        $entity->{$field_name}['und'][$i]['value']['SIO:000493'] = 'The ' . $subject_type . ', ' .
+        $subject_name . ', ' . $verb . ' '  . $rel_type_clean . ' this '  .
+        $object_type . '.';
+
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__subject_id'] = $relationship->subject_id->$subject_pkey;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__object_id'] = $relationship->object_id->$object_pkey;
+
+        $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
+        $entity->{$field_name}['und'][$i]['subject_name'] = $relationship->subject_id->name . ' [id: ' . $relationship->subject_id->$fkey_rcolumn . ']';
+        $entity->{$field_name}['und'][$i]['object_name'] = $relationship->object_id->name  . ' [id: ' . $relationship->object_id->$fkey_rcolumn . ']';
+        if (array_key_exists('value', $schema['fields'])) {
+          $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
+        }
+        if (array_key_exists('rank', $schema['fields'])) {
+          $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
+        }
+        $i++;
       }
     }
 
@@ -238,57 +249,48 @@ class sbo__relationship extends ChadoField {
         $object_name = $relationship->object_id->name;
         $object_type = $relationship->object_id->type_id->name;
         $entity->{$field_name}['und'][$i]['value'] = array(
-          '@type' => $relationship->type_id->name,
-          'subject' => array(
-            'type' => $subject_type,
-            'name' => $subject_name,
+          'local:relationship_subject' => array(
+            'rdfs:type' => $subject_type,
+            'schema:name' => $subject_name,
             'entity' => 'TripalEntity:' . $entity->id,
           ),
-          'type' => $relationship->type_id->name,
-          'object' => array(
-            'type' =>  $object_type,
-            'name' => $object_name,
+          'local:relationship_type' => $relationship->type_id->name,
+          'local:relationship_object' => array(
+            'rdfs:type' =>  $object_type,
+            'schema:name' => $object_name,
           )
         );
         if (property_exists($relationship->subject_id, 'uniquename')) {
-          $entity->{$field_name}['und'][$i]['value']['subject']['identifier'] = $relationship->subject_id->uniquename;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['data:0842'] = $relationship->subject_id->uniquename;
         }
         if (property_exists($relationship->object_id, 'uniquename')) {
-          $entity->{$field_name}['und'][$i]['value']['object']['identifier'] = $relationship->object_id->uniquename;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['data:0842'] = $relationship->object_id->uniquename;
         }
         if (property_exists($relationship->object_id, 'entity_id')) {
           $entity_id = $relationship->object_id->entity_id;
-          $entity->{$field_name}['und'][$i]['value']['object']['entity'] = 'TripalEntity:' . $entity_id;
+          $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['entity'] = 'TripalEntity:' . $entity_id;
         }
         $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
-        $entity->{$field_name}['und'][$i]['value']['phrase'] = 'This  ' .
-            $subject_type . ' ' . $verb . ' '  . $rel_type_clean . ' the '  .
-            $object_type . ', ' . $object_name . '.';
-
-
-            $entity->{$field_name}['und'][$i]['semantic_web'] = array(
-              'type' => $rel_acc,
-              'subject' => $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
-              'object' => $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->object_id->type_id->dbxref_id->accession,
-            );
-
+        $entity->{$field_name}['und'][$i]['value']['SIO:000493'] = 'This  ' .
+        $subject_type . ' ' . $verb . ' '  . $rel_type_clean . ' the '  .
+        $object_type . ', ' . $object_name . '.';
 
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__subject_id'] = $relationship->subject_id->$subject_pkey;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
-            $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__object_id'] = $relationship->object_id->$object_pkey;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__subject_id'] = $relationship->subject_id->$subject_pkey;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__object_id'] = $relationship->object_id->$object_pkey;
 
-            $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
-            $entity->{$field_name}['und'][$i]['subject_name'] = $relationship->subject_id->name  . ' [id: ' . $relationship->subject_id->$fkey_rcolumn . ']';
-            $entity->{$field_name}['und'][$i]['object_name'] = $relationship->object_id->name  . ' [id: ' . $relationship->object_id->$fkey_rcolumn . ']';
+        $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
+        $entity->{$field_name}['und'][$i]['subject_name'] = $relationship->subject_id->name  . ' [id: ' . $relationship->subject_id->$fkey_rcolumn . ']';
+        $entity->{$field_name}['und'][$i]['object_name'] = $relationship->object_id->name  . ' [id: ' . $relationship->object_id->$fkey_rcolumn . ']';
 
-            if (array_key_exists('value', $schema['fields'])) {
-              $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
-            }
-            if (array_key_exists('rank', $schema['fields'])) {
-              $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
-            }
-            $i++;
+        if (array_key_exists('value', $schema['fields'])) {
+          $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
+        }
+        if (array_key_exists('rank', $schema['fields'])) {
+          $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
+        }
+        $i++;
       }
     }
   }

+ 5 - 5
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -31,11 +31,11 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       if (!$item['value']) {
         continue;
       }
-      $subject_name = $item['value']['subject']['name'];
-      $subject_type = $item['value']['subject']['type'];
-      $object_name = $item['value']['object']['name'];
-      $object_type = $item['value']['object']['type'];
-      $phrase = $item['value']['phrase'];
+      $subject_name = $item['value']['local:relationship_subject']['schema:name'];
+      $subject_type = $item['value']['local:relationship_subject']['rdfs:type'];
+      $object_name = $item['value']['local:relationship_object']['schema:name'];
+      $object_type = $item['value']['local:relationship_object']['rdfs:type'];
+      $phrase = $item['value']['SIO:000493'];
 
       // Handle some special cases.
       // For mRNA objects we don't want to show the CDS, exons, 5' UTR, etc.

+ 1 - 1
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -84,7 +84,7 @@ class schema__alternate_name extends ChadoField {
       'chado-' . $field_table . '__' . $fkey_lcolumn => '',
       'chado-' . $field_table . '__' . 'synonym_id' => '',
       'chado-' . $field_table . '__' . 'pub_id' => '',
-      'chado-' . $field_table . '__' . 'is_current' => TRUE,
+      'chado-' . $field_table . '__' . 'is_current' => '',
       'chado-' . $field_table . '__' . 'is_internal' => '',
       'name' => '',
       'type_id' => '',

+ 10 - 8
tripal_chado/includes/TripalFields/so__transcript/so__transcript.inc

@@ -70,10 +70,12 @@ class so__transcript extends ChadoField {
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => array(
-        'type' => '',
-        'name' => '',
-        'identifier' => '',
-        'location' => '',
+        'rdfs:type' => '',
+        'schema:name' => '',
+        // Identifier
+        'data:0842' => '',
+        // sequence location
+        'SO:0000735' => '',
       ),
     );
 
@@ -105,10 +107,10 @@ class so__transcript extends ChadoField {
         $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
       }
       $entity->{$field_name}['und'][$i]['value'] = array(
-        'type' => $transcript->type,
-        'name' => $transcript->name,
-        'identifier' => $transcript->uniquename,
-        'location' => $loc,
+        'rdfs:type' => $transcript->type,
+        'schema:name' => $transcript->name,
+        'data:0842' => $transcript->uniquename,
+        'SO:0000735' => $loc,
       );
       $entity_id = tripal_get_chado_entity_id($field_table, $record->feature_id);
       if ($entity_id) {

+ 4 - 4
tripal_chado/includes/TripalFields/so__transcript/so__transcript_formatter.inc

@@ -34,10 +34,10 @@ class so__transcript_formatter extends ChadoFieldFormatter {
       $transcript = $item['value'];
 
       // Get the field values
-      $feature_name = $transcript['name'];
-      $feature_uname = $transcript['identifier'];
-      $loc = $transcript['location'];
-      $type = $transcript['type'];
+      $feature_name = $transcript['schema:name'];
+      $feature_uname = $transcript['data:0842'];
+      $loc = $transcript['SO:0000735'];
+      $type = $transcript['rdfs:type'];
 
       // Add a link i there is an entity.
       if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {

+ 111 - 1
tripal_chado/includes/tripal_chado.semweb.inc

@@ -20,6 +20,7 @@ function tripal_chado_populate_chado_semweb_table() {
 
   // Now set defaults!
   tripal_chado_populate_vocab_EDAM();
+  tripal_chado_populate_vocab_ERO();
   tripal_chado_populate_vocab_FOAF();
   tripal_chado_populate_vocab_IAO();
   tripal_chado_populate_vocab_LOCAL();
@@ -29,6 +30,8 @@ function tripal_chado_populate_chado_semweb_table() {
   tripal_chado_populate_vocab_RDFS();
   tripal_chado_populate_vocab_SBO();
   tripal_chado_populate_vocab_SCHEMA();
+  tripal_chado_populate_vocab_SIO();
+  tripal_chado_populate_vocab_SO();
   tripal_chado_populate_vocab_SWO();
   tripal_chado_populate_vocab_TAXRANK();
   tripal_chado_populate_vocab_TPUB();
@@ -127,6 +130,34 @@ function tripal_chado_populate_vocab_SCHEMA() {
     'definition' => 'A publication event associated with the item.',
   ));
   tripal_associate_chado_semweb_term(NULL, 'pub_id', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'schema:url',
+    'name' => 'url',
+    'cv_name' => 'schema',
+    'definition' => 'URL of the item.',
+  ));
+  tripal_associate_chado_semweb_term('db', 'URL', $term);
+}
+
+/**
+ * Adds the SemanticScience database and terms.
+ */
+function tripal_chado_populate_vocab_SIO() {
+  tripal_insert_db(array(
+    'name' => 'SIO',
+    'description' => 'Semanticscience Integrated Ontology.',
+    'url' => 'http://sio.semanticscience.org/',
+    'urlprefix' => 'http://semanticscience.org/resource/{db}_{accession}',
+  ));
+  tripal_insert_cv('SIO',' The Semanticscience Integrated Ontology (SIO) provides a simple, integrated ontology of types and relations for rich description of objects, processes and their attributes.');
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SIO:000493',
+    'name' => 'clause',
+    'cv_name' => 'SIO',
+    'definition' => 'A clause consists of a subject and a predicate.',
+  ));
 }
 /**
  * Adds the EDAM database and terms.
@@ -145,6 +176,8 @@ function tripal_chado_populate_vocab_EDAM() {
     'url' => 'http://edamontology.org/page',
     'urlprefix' => 'http://edamontology.org/{db}_{accession}',
   ));
+  tripal_insert_cv('data','Bioinformatics operations, data types, formats, identifiers and topics.');
+
 
   $term = tripal_insert_cvterm(array(
     'id' => 'data:1249',
@@ -218,13 +251,40 @@ function tripal_chado_populate_vocab_EDAM() {
   ));
   tripal_associate_chado_semweb_term('featuremap', 'featuremap_id', $term);
 
-
   $term = tripal_insert_cvterm(array(
     'id' => 'data:2012',
     'name' => 'Sequence coordinates',
     'cv_name' => 'EDAM',
     'definition' => 'A position in a map (for example a genetic map), either a single position (point) or a region / interval.',
   ));
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:1056',
+    'name' => 'Databse name',
+    'cv_name' => 'EDAM',
+    'definition' => 'The name of a biological or bioinformatics database.',
+  ));
+  tripal_associate_chado_semweb_term('db', 'name', $term);
+}
+
+/**
+ * Adds the Eagle-i Resource Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_ERO() {
+  tripal_insert_db(array(
+    'name' => 'ERO',
+    'description' => 'The Eagle-I Research Resource Ontology',
+    'url' => 'http://purl.bioontology.org/ontology/ERO',
+    'urlprefix' => 'http://purl.bioontology.org/ontology/ERO/{db}:{accession}',
+  ));
+  tripal_insert_cv('ero','The Eagle-I Research Resource Ontology models research resources such instruments. protocols, reagents, animal models and biospecimens. It has been developed in the context of the eagle-i project (http://eagle-i.net/).');
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'ERO:0001716',
+    'name' => 'database',
+    'cv_name' => 'ero',
+    'definition' => 'A database is an organized collection of data, today typically in digital form.',
+  ));
 }
 
 /**
@@ -392,6 +452,43 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
   tripal_associate_chado_semweb_term(NULL, 'is_obsolete', $term);
 
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:relationship_subject',
+    'name' => 'clause subject',
+    'definition' => 'The subject of a relationship clause.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'subject_id', $term);
+  tripal_associate_chado_semweb_term(NULL, 'subject_reagent_id', $term);
+  tripal_associate_chado_semweb_term(NULL, 'subject_project_id', $term);
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:relationship_object',
+    'name' => 'clause predicate',
+    'definition' => 'The object of a relationship clause.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'object_id', $term);
+  tripal_associate_chado_semweb_term(NULL, 'object_reagent_id', $term);
+  tripal_associate_chado_semweb_term(NULL, 'object_project_id', $term);
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:relationship_type',
+    'name' => 'relationship type',
+    'definition' => 'The relationship type.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term('acquisition_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('biomaterial_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('cell_line_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('contact_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('element_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('elementresult_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('feature_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('nd_reagent_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('phylonode_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('project_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('pub_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('quantification_relationship', 'type_id', $term);
+  tripal_associate_chado_semweb_term('stock_relationship', 'type_id', $term);
 }
 /**
  * Adds the Systems Biology Ontology database and terms.
@@ -427,6 +524,19 @@ function tripal_chado_populate_vocab_SBO() {
   ));
 }
 
+/**
+ * Adds the Sequence Ontology
+ */
+function tripal_chado_populate_vocab_SO() {
+  tripal_insert_db(array(
+    'name' => 'SO',
+    'description' => 'Sequence Ontology',
+    'url' => 'http://www.sequenceontology.org',
+    'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
+  ));
+  tripal_insert_cv('sequence','The Sequence Ontology.');
+}
+
 /**
  * Adds the Software Ontology database and terms.
  */

+ 48 - 19
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -567,7 +567,17 @@ function tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_u
     if ($term) {
       $key = $term['name'];
       $key_adj = strtolower(preg_replace('/ /', '_', $key));
-      $response['@context'][$key_adj] = $term['url'];
+      // The term schema:url also points to a recource so we need
+      // to make sure we set the type to be '@id'.
+      if ($vocabulary == 'schema' and $accession == 'url') {
+        $response['@context'][$key_adj] = array(
+          '@id' => $term['url'],
+          '@type' => '@id',
+        );
+      }
+      else {
+        $response['@context'][$key_adj] = $term['url'];
+      }
     }
     else {
       continue;
@@ -582,7 +592,17 @@ function tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_u
         '@id' => $response['@context'][$key_adj],
         '@type' => '@id'
       );
-      $response[$key_adj] = url($api_url . '/content/' . $ctype . '/' . $entity->id . '/' . urlencode($key), array('absolute' => TRUE));
+      // Add a URL only if there are values. If there are no values then
+      // don't add a URL which would make the end-user think they can get
+      // that information.
+      $items = field_get_items('TripalEntity', $entity, $field_name);
+      if ($items and count($items) > 0 and $items[0]['value']) {
+        $response[$key_adj] = url($api_url . '/content/' . $ctype . '/' . $entity->id . '/' . urlencode($key), array('absolute' => TRUE));
+      }
+      else {
+        $response[$key_adj] = NULL;
+      }
+
       continue;
     }
 
@@ -626,14 +646,11 @@ function tripal_ws_services_v0_1_get_content_find_field($field_arg, $ctype, $ent
   foreach ($instances as $instance) {
     $field_name = $instance['field_name'];
     $field = field_info_field($field_name);
-    $field_settings = $field['settings'];
-    if (array_key_exists('semantic_web', $field_settings) and
-        $field_settings['semantic_web']) {
-      list($vocabulary, $accession) = explode(':', $field_settings['semantic_web']);
-      $temp_term = tripal_get_term_details($vocabulary, $accession);
-      if ($temp_term['name'] == $field_arg) {
-        return array($entity, $bundle, $field, $instance, $temp_term);
-      }
+    $vocabulary = $instance['settings']['term_vocabulary'];
+    $accession = $instance['settings']['term_accession'];
+    $temp_term = tripal_get_term_details($vocabulary, $accession);
+    if ($temp_term['name'] == $field_arg) {
+      return array($entity, $bundle, $field, $instance, $temp_term);
     }
   }
 }
@@ -668,14 +685,15 @@ function tripal_ws_services_v0_1_get_content($api_url, &$response, $ws_path, $ct
 
     // Next add in the ID and Type for this resources.
     $key = $term['name'];
-    $response['@context'][$key] = $term['url'];
+    $key_adj = strtolower(preg_replace('/ /', '_', $term['name']));
+    $response['@context'][$key_adj] = $term['url'];
     $response['@id'] = url($api_url . '/content/' . $ctype . '/' . $entity->id . '/' . urlencode($key), array('absolute' => TRUE));
 
     // Attach the field and then add it's values to the response.
-    field_attach_load($entity->type, array($entity->id => $entity), FIELD_LOAD_CURRENT,
-        array('field_id' => $field['id']));
+    field_attach_load($entity->type, array($entity->id => $entity),
+      FIELD_LOAD_CURRENT, array('field_id' => $field['id']));
 
-    tripal_ws_services_v0_1_get_content_add_field($key, $entity, $field, $instance, $api_url, $response, TRUE);
+    tripal_ws_services_v0_1_get_content_add_field($key_adj, $entity, $field, $instance, $api_url, $response, TRUE);
 
     return;
   }
@@ -759,8 +777,8 @@ function tripal_ws_services_v0_1_get_content_add_field($key, $entity, $field, $i
   $values = array();
   for ($i = 0; $i < count($items); $i++) {
 
-    // See if the keys in the values array have been mapped to semantic
-    // web terms.
+    // If the value is an array rather than a scalar then map the sub elements
+    // to controlled vocabulary terms.
     if (is_array($items[$i]['value'])) {
       $temp = array();
       foreach ($items[$i]['value'] as $k => $v) {
@@ -769,14 +787,25 @@ function tripal_ws_services_v0_1_get_content_add_field($key, $entity, $field, $i
           $vocabulary = $matches[1];
           $accession = $matches[2];
           $term = tripal_get_term_details($vocabulary, $accession);
-          $temp[$term['name']] = $v;
-          $response['@context'][$term['name']] = $term['url'];
+          $key_adj = strtolower(preg_replace('/ /', '_', $term['name']));
+          $temp[$key_adj] = $v != "" ? $v : NULL;
+          // The term schema:url also points to a recource so we need
+          // to make sure we set the type to be '@id'.
+          if ($vocabulary == 'schema' and $accession == 'url') {
+            $response['@context'][$key_adj] = array(
+              '@id' => $term['url'],
+              '@type' => '@id',
+            );
+          }
+          else {
+            $response['@context'][$key_adj] = $term['url'];
+          }
         }
       }
       $values[] = $temp;
     }
     else {
-      $values[] = $items[$i]['value'];
+      $values[] = $items[$i]['value'] != "" ? $items[$i]['value'] : NULL;
     }
 
     // Recurse through the values array and set the entity elemetns