Browse Source

Made fixes to the TPUB and TContact db and cv entries and added a sw_url to the vocab details

Stephen Ficklin 7 years ago
parent
commit
b39dfbb6ae

+ 6 - 5
tripal/api/tripal.terms.api.inc

@@ -270,15 +270,16 @@ function tripal_get_term_details($vocabulary, $accession) {
  *
  * @return
  *   An array with at least the following keys:
- *     - name : The full name of the vocabulary.
- *     - short_name : The short name abbreviation for the vocabulary.
- *     - description : A brief description of the vocabulary.
- *     - url : (optional) A URL for the online resources for the vocabulary.
- *     - urlprefix : (optional) A URL to which the short_name and term
+ *     - name: The full name of the vocabulary.
+ *     - short_name: The short name abbreviation for the vocabulary.
+ *     - description: A brief description of the vocabulary.
+ *     - url:  A URL for the online resources for the vocabulary.
+ *     - urlprefix: A URL to which the short_name and term
  *       accession can be appended to form a complete URL for a term.  If the
  *       prefix does not support appending then the exact location for the
  *       position of the short_name and the term accession will be
  *       specified with the {db} and {accession} tags respectively.
+ *     - sw_url: The URL for mapping terms via the semantic web.
  */
 function tripal_get_vocabulary_details($vocabulary) {
   // TODO: we need some sort of administrative interface that lets the user

+ 7 - 17
tripal/includes/TripalTerm.inc

@@ -15,23 +15,13 @@ class TripalTerm extends Entity {
     $this->definition = NULL;
     $this->url = NULL;
 
-    // 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.
-    $stores = module_invoke_all('vocab_storage_info');
-    if (is_array($stores) and count($stores) > 0) {
-      $keys = array_keys($stores);
-      $module = $stores[$keys[0]]['module'];
-      $function = $module . '_vocab_get_term';
-      if (function_exists($function)) {
-        $term_details = $function($vocab->vocabulary, $this->accession);
-        if ($term_details) {
-//          $this->details = $term_details;
-          if ($term_details and $term_details['definition']) {
-            $this->definition = $term_details['definition'];
-            $this->url = $term_details['url'];
-          }
-        }
+    $term_details = tripal_get_term_details($vocab->vocabulary, $this->accession);
+    if ($term_details) {
+      if ($term_details and $term_details['definition']) {
+        $this->definition = $term_details['definition'];
+      }
+      if ($term_details and $term_details['url']) {
+        $this->url = $term_details['url'];
       }
     }
   }

+ 9 - 2
tripal_chado/includes/tripal_chado.semweb.inc

@@ -1513,6 +1513,13 @@ function tripal_chado_populate_vocab_SWO() {
  * Adds the contact table mapping.
  */
 function tripal_chado_populate_vocab_TCONTACT() {
+  tripal_insert_db(array(
+    'name' => 'TContact',
+    'description' => 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
+    'url' => 'cv/lookup/TContact',
+    'urlprefix' => 'cv/lookup/TContact/{accession}',
+  ));
+  tripal_insert_cv('tripal_contact', 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
 }
 
 /**
@@ -1523,8 +1530,8 @@ function tripal_chado_populate_vocab_TPUB() {
   tripal_insert_db(array(
     'name' => 'TPUB',
     'description' => 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
-    'url' => 'http://localhost/cv/lookup/TPUB',
-    'urlprefix' => 'http://localhost/cv/lookup/TPUB/{accession}',
+    'url' => 'cv/lookup/TPUB',
+    'urlprefix' => 'cv/lookup/TPUB/{accession}',
   ));
   tripal_insert_cv('tripal_pub', 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
 

+ 20 - 2
tripal_chado/includes/tripal_chado.vocab_storage.inc

@@ -40,9 +40,16 @@ function tripal_chado_vocab_get_vocabulary($vocabulary) {
   ";
   $result = chado_query($sql, array(':name' => $vocabulary));
   $result = $result->fetchAssoc();
+
   if (!$result['name']) {
     $result['name'] = $result['short_name'];
   }
+  $sw_url = $result['urlprefix'];
+  $sw_url = preg_replace('/\{db\}/', $result['short_name'], $sw_url);
+  $sw_url = preg_replace('/\{accession\}/', '', $sw_url);
+  $sw_url = url($sw_url, array('absolute' => TRUE));
+  $result['sw_url'] = $sw_url;
+  unset($result['short_name']);
   return $result;
 }
 
@@ -73,13 +80,24 @@ function tripal_chado_vocab_get_term($vocabulary, $accession) {
     return FALSE;
   }
   $cvterm = chado_expand_var($cvterm, 'field', 'cvterm.definition');
+
+  $url = $cvterm->dbxref_id->db_id->url;
+  $urlprefix = $cvterm->dbxref_id->db_id->urlprefix;
+
+  // Generate the URL that can be used for semantic web applications.
+  $sw_url = $urlprefix;
+  $sw_url = preg_replace('/{db}/', $cvterm->dbxref_id->db_id->name, $sw_url);
+  $sw_url = preg_replace('/{accession}/', '', $sw_url);
+  $sw_url = url($sw_url, array('absolute' => TRUE));
+
   $term = array(
     'vocabulary' => array(
       'name' => $cvterm->cv_id->name,
       'short_name' => $cvterm->dbxref_id->db_id->name,
       'description' =>  $cvterm->dbxref_id->db_id->description,
-      'url' => $cvterm->dbxref_id->db_id->url,
-      'urlprefix' => $cvterm->dbxref_id->db_id->urlprefix
+      'url' => $url,
+      'urlprefix' => $urlprefix,
+      'sw_url' => $sw_url,
     ),
     'accession'  => $cvterm->dbxref_id->accession,
     'name'       => $cvterm->name,

+ 26 - 2
tripal_chado/tripal_chado.install

@@ -1399,8 +1399,8 @@ function tripal_chado_update_7321() {
     tripal_insert_db(array(
       'name' => 'TPUB',
       'description' => 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
-      'url' => 'http://localhost/cv/lookup/TPUB',
-      'urlprefix' => 'http://localhost/cv/lookup/TPUB/{accession}',
+      'url' => '/cv/lookup/TPUB',
+      'urlprefix' => '/cv/lookup/TPUB/{accession}',
     ));
     tripal_insert_cv('tripal_pub', 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
 
@@ -1435,4 +1435,28 @@ function tripal_chado_update_7321() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
+}
+/**
+ * Fixing the TPUB and TContact vocabulary URLs
+ */
+function tripal_chado_update_7322() {
+  try {
+    tripal_insert_db(array(
+      'name' => 'TPUB',
+      'description' => 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
+      'url' => 'cv/lookup/TPUB',
+      'urlprefix' => 'cv/lookup/TPUB/{accession}',
+    ));
+    tripal_insert_db(array(
+      'name' => 'TContact',
+      'description' => 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
+      'url' => 'cv/lookup/TContact',
+      'urlprefix' => 'cv/lookup/TContact/{accession}',
+    ));
+    tripal_insert_cv('tripal_contact', 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }

+ 1 - 1
tripal_ws/includes/TripalWebService.inc

@@ -627,7 +627,7 @@ class TripalWebService {
     // page.  But unfortunately, the URL prefix can't be guaranteed to be
     // a true prefix. Not all databases place by the rules.  For this reason,
     // we can never use JSON-LD compact IRIs. :-(
-    $iri = $vocab['url'];
+    $iri = $vocab['sw_url'];
     $resource->addContextItem($key, $iri);
   }
 

+ 16 - 14
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -28,10 +28,17 @@ class TripalEntityService_v0_1 extends TripalWebService {
    */
   public function __construct($base_path) {
     parent::__construct($base_path);
+  }
 
+  /**
+   * @see TripalWebService::getDocumentation()
+   */
+  public function getDocumentation() {
     // Add the classes that this resource supports.
     $this->addDocBundleClasses();
     $this->addDocContentCollectionClass();
+
+    return parent::getDocumentation();
   }
 
   /**
@@ -873,9 +880,10 @@ class TripalEntityService_v0_1 extends TripalWebService {
    */
   private function doAllTypesList() {
     $service_path = $this->getServicePath();
+    $service_vocab = new TripalVocabService_v0_1($this->base_path);
     $this->resource = new TripalWebServiceCollection($service_path, $this->params);
-    $this->resource->addContextItem('vocab', 'http://localhost/web-services/vocab/v0.1/');
-    $this->resource->addContextItem('ContentCollection', 'http://localhost/web-services/vocab/v0.1#ContentCollection');
+    $this->resource->addContextItem('vocab', $service_vocab->getServicePath());
+    $this->resource->addContextItem('ContentCollection', $service_vocab->getServicePath() . '#ContentCollection');
     $this->resource->setType('ContentCollection');
 
     $label = tripal_get_term_details('rdfs', 'label');
@@ -937,28 +945,25 @@ class TripalEntityService_v0_1 extends TripalWebService {
       'title' => 'Content Collection',
     );
     $vocab = tripal_get_vocabulary_details('hydra');
-    $url = preg_replace('/{accession}/', 'member', $vocab['urlprefix']);
     $propeties = array();
     $propeties[] = array(
-      'type' => $url,
+      'type' => $vocab['sw_url'],
       'title' => 'member',
       'description' => "The list of available content types.",
       "required" => null,
       "readonly" => FALSE,
       "writeonly" => FALSE,
     );
-    $url = preg_replace('/{accession}/', 'totalItems', $vocab['urlprefix']);
     $propeties[] = array(
-      "type" => $url,
+      "type" => $vocab['sw_url'],
       "title" => "totalItems",
       "description" => "The total number of content types.",
       "required" => null,
       "readonly" => FALSE,
       "writeonly" => FALSE
     );
-    $url = preg_replace('/{accession}/', 'label', $vocab['urlprefix']);
     $propeties[] = array(
-      "type" => $url,
+      "type" => $vocab['sw_url'],
       "title" => "label",
       "description" => "The type content.",
       "required" => null,
@@ -1111,28 +1116,25 @@ class TripalEntityService_v0_1 extends TripalWebService {
       'description' => 'A collection (or list) of ' . $bundle->label . ' resources.',
     );
     $vocab = tripal_get_vocabulary_details('hydra');
-    $url = preg_replace('/{accession}/', 'member', $vocab['urlprefix']);
     $propeties = array();
     $propeties[] = array(
-      'type' => $url,
+      'type' => $vocab['sw_url'],
       'title' => 'member',
       'description' => "The list of available " . $bundle->label . '(s).',
       "required" => null,
       "readonly" => FALSE,
       "writeonly" => FALSE,
     );
-    $url = preg_replace('/{accession}/', 'totalItems', $vocab['urlprefix']);
     $propeties[] = array(
-      "type" => $url,
+      "type" => $vocab['sw_url'],
       "title" => "totalItems",
       "description" => "The total number of resources.",
       "required" => null,
       "readonly" => FALSE,
       "writeonly" => FALSE
     );
-    $url = preg_replace('/{accession}/', 'label', $vocab['urlprefix']);
     $propeties[] = array(
-      "type" => $url,
+      "type" => $vocab['sw_url'],
       "title" => "label",
       "description" => "A label or name for the resource.",
       "required" => null,

+ 6 - 20
tripal_ws/includes/TripalWebServiceResource.inc

@@ -45,41 +45,27 @@ class TripalWebServiceResource {
     // web services should use these.
     $vocab = tripal_get_vocabulary_details('rdf');
 
-    $this->addContextItem('rdf', $this->cleanVocabURL($vocab));
+    $this->addContextItem('rdf', $vocab['sw_url']);
 
     $vocab = tripal_get_vocabulary_details('rdfs');
-    $this->addContextItem('rdfs', $this->cleanVocabURL($vocab));
+    $this->addContextItem('rdfs', $vocab['sw_url']);
 
     $vocab = tripal_get_vocabulary_details('hydra');
-    $url = $this->cleanVocabURL($vocab);
-    // $remove the '#' from the end of the URL as the HydraConsole automatically
-    // wants to add it.
-    //$url = preg_replace('/#/', '', $url);
-    $this->addContextItem('hydra', $url);
+    $this->addContextItem('hydra', $vocab['sw_url']);
 
     $vocab = tripal_get_vocabulary_details('dc');
-    $this->addContextItem('dc', $this->cleanVocabURL($vocab));
+    $this->addContextItem('dc', $vocab['sw_url']);
 
     $vocab = tripal_get_vocabulary_details('schema');
-    $this->addContextItem('schema', $this->cleanVocabURL($vocab));
+    $this->addContextItem('schema', $vocab['sw_url']);
 
     $vocab = tripal_get_vocabulary_details('local');
-    $this->addContextItem('local', url($vocab['urlprefix'], array('absolute' => TRUE)). '/');
+    $this->addContextItem('local', url($vocab['sw_url'], array('absolute' => TRUE)));
 
 
     $this->data['@id'] = $service_path;
     $this->data['@type'] = '';
   }
-  /**
-   * A helper function to remove the {db} and {accession} from the URL prefix.
-   */
-  private function cleanVocabURL($vocab) {
-    $url = $vocab['urlprefix'];
-    $url = preg_replace('/{db}:{accession}/', '', $url);
-    $url = preg_replace('/{db}/', '', $url);
-    $url = preg_replace('/{accession}/', '', $url);
-    return $url;
-  }
 
   /**
    * Adds a term to the '@context' section for this resource.

+ 2 - 3
tripal_ws/tripal_ws.module

@@ -26,9 +26,8 @@ function tripal_ws_init() {
   // Following the WC3 Hydra documentation, we want to add  LINK to the header
   // of the site that indicates where the API documentation can be found.
   // This allows a hydra-enabled client to discover the API and use it.
-  $url = preg_replace('/{accession}/', 'apiDocumenation', $vocab['urlprefix']);
   $attributes = array(
-    'rel' => $url,
+    'rel' => $vocab['sw_url'] . 'apiDocumentation',
     'href' => $api_url . '/ws-doc/',
   );
   drupal_add_html_head_link($attributes, $header = FALSE);
@@ -121,7 +120,7 @@ function tripal_ws_get_services() {
   tripal_load_include_web_service_class('TripalVocabService_v0_1');
   $service = new TripalVocabService_v0_1($service_path);
   $vocab = tripal_get_vocabulary_details('hydra');
-  drupal_add_http_header('Link', '<' . $service->getServicePath() . '>; rel="' . $vocab['url'] . '#apiDocumentation"');
+  drupal_add_http_header('Link', '<' . $service->getServicePath() . '>; rel="' . $vocab['sw_url'] . 'apiDocumentation"');
   drupal_add_http_header('Cache-Control', "no-cache");
 
   try {