Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Official development copies of internal web services used by the wiki
authorpreecej <preecej@localhost>
Wed, 17 Aug 2011 19:03:08 +0000 (19:03 +0000)
committerpreecej <preecej@localhost>
Wed, 17 Aug 2011 19:03:08 +0000 (19:03 +0000)
svn path=/; revision=159

preecej/semantic_wiki/services/NCBI_eDocSummary.php [new file with mode: 0644]
preecej/semantic_wiki/services/TermSearch_JSON.php [new file with mode: 0644]

diff --git a/preecej/semantic_wiki/services/NCBI_eDocSummary.php b/preecej/semantic_wiki/services/NCBI_eDocSummary.php
new file mode 100644 (file)
index 0000000..7e38a66
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+$pub_id = $_GET["pub_id"];
+$url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi/?db=pubmed&id=" . $pub_id;
+$response = file_get_contents($url);
+
+$NCBI_doc = new SimpleXMLElement($response); // inst. NCBI eDocSummary as xml
+$xml_out = new SimpleXMLElement("<eSummaryResult/>"); // inst. new xml doc for output
+
+// build xml doc with NCBI data
+$DocSum = $xml_out->addChild("DocSum");
+$DocSum->addChild("Id",$NCBI_doc->DocSum->Id);
+
+foreach ($NCBI_doc->xpath("//Item") as $item) {
+    switch((string) $item["Name"]) { // Get attributes as element indices
+    case "PubDate":
+        $DocSum->addChild("PubDate",$item);
+        break;
+    case "Author":
+        $authorList[] = $item;
+        break;
+    case "LastAuthor":
+        $DocSum->addChild("LastAuthor",$item);
+        break;
+    case "Title":
+        $DocSum->addChild("Title",$item);
+        break;
+    case "Volume":
+        $DocSum->addChild("Volume",$item);
+        break;
+    case "Pages":
+        $DocSum->addChild("Pages",$item);
+        break;
+    case "FullJournalName":
+        $DocSum->addChild("FullJournalName",$item);
+        break;
+    }
+}
+
+$author_list = "";
+foreach ($authorList as $author) {
+    $author_list = $author_list . $author . ", ";
+}
+$DocSum->addChild("AuthorList",rtrim($author_list,", "));
+
+
+header('Content-Type: text/xml'); // output xml doctype in your response
+echo $xml_out->asXML(); 
+?>
+
diff --git a/preecej/semantic_wiki/services/TermSearch_JSON.php b/preecej/semantic_wiki/services/TermSearch_JSON.php
new file mode 100644 (file)
index 0000000..89c1033
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+// JSON web service for PO terms: autocomplete and search methods
+
+/* require the user as the parameter */
+if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
+
+        $arr_field_names = array('name','acc');
+    
+        /* read the params and/or set our own */
+        $type = isset($_GET['type']) ? $_GET['type'] : autocomplete; // autocomplete is the default
+        
+        // security measures; helps to avoid SQL injection attacks
+        $field = isset($_GET['field']) && in_array($_GET['field'],$arr_field_names)
+            ? $_GET['field']
+            : die('"field" is a required parameter and must match an available data field.');
+            
+        $number_of_terms = isset($_GET['max']) ? intval($_GET['max']) : 10; //10 is the default
+        if ($number_of_terms > 50) { $number_of_terms = 50; } 
+
+        $qval = $_GET['qval'];
+        
+        $qval = isset($_GET['qval']) && strlen($_GET['qval']) > 0 
+            ? strtolower($_GET['qval'])
+            : die('Please provide a searchable value');
+
+        $format = strtolower($_GET['format']) != 'json' 
+            ? strtolower($_GET['format']) 
+            : 'json'; //json is the default
+        
+        /* connect to the db */
+        $link = mysql_connect($_SERVER['mysql_host'], $_SERVER['mysql_user'], $_SERVER['mysql_pw']) or die('Cannot connect to the DB');
+        mysql_select_db($_SERVER['mysql_db'],$link) or die('Cannot select the DB');
+
+        switch ($type) {
+            case 'autocomplete':
+                /* grab the terms from the db */
+                $query = "SELECT t.$field FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.$field LIKE '%$qval%'"
+                    . " AND t.term_type in ('plant_anatomy','plant_growth_and_development_stage')"
+                    . " AND t.is_obsolete = 0"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY name LIMIT $number_of_terms";
+                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
+            
+                /* create one master array of the records */
+                $terms = array();
+                if(mysql_num_rows($result)) {
+                    while($term = mysql_fetch_assoc($result)) {
+                        $terms[] = array('title'=>$term[$field]);
+                    }
+                }
+
+                /* output in necessary format */
+                if($format == 'json') {
+                    header('Content-type: application/json');
+                    echo json_encode(array('sfautocomplete'=>$terms));
+                }
+                else {
+                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
+                }
+                break;
+
+            case 'term_detail':
+                /* grab the ontology data from the db */
+                $query = "SELECT DISTINCT t.acc as 'acc', t.term_type as 'type', d.term_definition as 'definition', d.term_comment as 'comment'"
+                    . " FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.name = '$qval'"
+                    . " AND t.term_type in ('plant_anatomy','plant_growth_and_development_stage')"
+                    . " AND t.is_obsolete = 0"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY t.name LIMIT 1";
+                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
+            
+                /* create one master array of the records */
+                $terms = array();
+                if(mysql_num_rows($result)) {
+                    while($term = mysql_fetch_assoc($result)) {
+                        $terms[] = array(
+                            'id'=>$term['acc'],
+                            'aspect'=>$term['type'] == "plant_anatomy" ? "Plant Anatomy" : "Plant Growth and Development Stage",
+                            'definition'=>$term['definition'],
+                            'comment'=>$term['comment']);
+                    }
+                }
+                /* output in necessary format */
+                if($format == 'json') {
+                    header('Content-type: application/json');
+                    echo json_encode(array('PO_result'=>$terms));
+                }
+                else {
+                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
+                }
+                break;
+            default:
+                die('Sorry, this web service method is not available.');
+        }
+        /* disconnect from the db */
+        @mysql_close($link);
+}
+else { die('Not authorized.'); }
+?>
+