Skip to content

Commit

Permalink
Add code
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmpage committed Jun 23, 2016
1 parent 53f6bda commit 2e51894
Show file tree
Hide file tree
Showing 8 changed files with 1,122 additions and 7 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ You can participate in several ways.
4. Propose queries you’d like the database to answer
5. Create those queries in the database itself.

## Overview

The hack glues together several tools:

1. https://hypothes.is to make annotations
2. https://ifttt.com to send the annotations to a central store
3. http://cloudant.com to analyse the annotations


## Using hypothes.is to annotate papers

![logo](https://github.com/rdmpage/recon16-annotation/raw/master/images/7iUlfzBp.jpg)

If you’ve not used hypothes.is before you will need to create a free account at https://hypothes.is. If you use Chrome you can get the hypothes.is extension, if you use another web browser you can still annotate content using the proxy https://via.hypothes.is

There are various ways to annotate documents. Here are some possibilities:

If a paper mentioned a latitude and longitude pair, select that text, click “annotate” and add the tag “geo”
In the list of literature cited, select a reference, click “annotate” and in the annotation paste in the DOI of the reference and add the tag “cites”
If the paper contains a scientific name, select it, click annotate, and add the tag “name”
1. If a paper mentioned a latitude and longitude pair, select that text, click “annotate” and add the tag “geo”
2. In the list of literature cited, select a reference, click “annotate” and in the annotation paste in the DOI of the reference and add the tag “cites”
3. If the paper contains a scientific name, select it, click annotate, and add the tag “name”

There is lots of scope for thinking about what to annotate, and how to use tags and URLs to make the annotations easy to read by machines.

Expand All @@ -47,15 +57,15 @@ IFTTT will now ask for “that”, in the box saying “Choose Action Channel”

![Example](https://github.com/rdmpage/recon16-annotation/raw/master/images/Screenshot 2016-06-23 14.22.59.png)

Set the method to “POST”, content type to “application/json”, and body to “EntryUrl”. For the URL paste in: xxxx
Set the method to “POST”, content type to “application/json”, and body to “EntryUrl”. For the URL paste in: http://bionames.org/~rpage/recon16-annotation/webhook.php .

The IFTTT recipe will automatically send your annotations to the central database.
This URL is for a service that reads the annotations received via IFTTT, tries to interpret them where possible (e.g., extract latitude and longitude from geographical coordinates) then sends the annotations to the central store.

## Central database

The central database for this project is CouchDB, in this case hosted by https://couldant.com (other hosting options are available, such as http://www.iriscouch.com although these may lack some of the features this hack relies on).
The central database for this project is CouchDB, in this case hosted by https://cloudant.com (other hosting options are available, such as http://www.iriscouch.com although these may lack some of the features this hack relies on).

An account on Cloudant has been created especially for this project with the user name “recon16”. We can create some “views” to index the data, including a geospatial index to search by geography (Cloudant has an built-in map to display this data on a map).
An account on Cloudant has been created especially for this project with the user name “recon16” https://recon16.cloudant.com/dashboard.html . We can create some “views” to index the data, including a geospatial index to search by geography (Cloudant has an built-in map to display this data on a map).



Expand Down
50 changes: 50 additions & 0 deletions config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

// $Id: //

/**
* @file config.php
*
* Global configuration variables (may be added to by other modules).
*
*/

global $config;

// Date timezone
date_default_timezone_set('UTC');


// CouchDB--------------------------------------------------------------------------------
// local
$config['couchdb_options'] = array(
'database' => 'annotation',
'host' => 'localhost',
'port' => 5984,
'prefix' => 'http://'
);


// Cloudant
$config['couchdb_options'] = array(
'database' => 'annotation',
'host' => 'recon16:[email protected]',
'port' => 5984,
'prefix' => 'http://'
);


// HTTP proxy
if ($config['proxy_name'] != '')
{
if ($config['couchdb_options']['host'] != 'localhost')
{
$config['couchdb_options']['proxy'] = $config['proxy_name'] . ':' . $config['proxy_port'];
}
}

$config['stale'] = true;



?>
125 changes: 125 additions & 0 deletions couchsimple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

require_once (dirname(__FILE__) . '/config.inc.php');

$couch = new CouchSimple($config['couchdb_options']);

//--------------------------------------------------------------------------------------------------
class CouchSimple
{
//----------------------------------------------------------------------------------------------
function CouchSimple($options)
{
foreach($options AS $key => $value) {
$this->$key = $value;
}
}

//----------------------------------------------------------------------------------------------
function send($method, $url, $post_data = NULL)
{
$ch = curl_init();

$url = $this->prefix . $this->host . ':' . $this->port . $url;

//echo $url . "\n";

//echo $url;

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);

// Set HTTP headers
$headers = array();
$headers[] = 'Content-type: application/json'; // we are sending JSON

// Override Expect: 100-continue header (may cause problems with HTTP proxies
// http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/
$headers[] = 'Expect:';
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);

if (isset($this->proxy))
{
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
}
switch ($method) {
case 'POST':
curl_setopt($ch, CURLOPT_POST, TRUE);
if (!empty($post_data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
break;
case 'PUT':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
if (!empty($post_data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
}
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//echo $response;

if (curl_errno ($ch) != 0 )
{
echo "CURL error: ", curl_errno ($ch), " ", curl_error($ch);
}

return $response;
}

// Add, update, or delete object. This method is handy if you are unsure of whether object
// already exists. If it does, we get the revision number and then update the record using PUT
function add_update_or_delete_document($obj, $id, $operation = 'add')
{
if ($operation == 'add')
{
// add (PUT as we have identifier)
$resp = $this->send("PUT", "/" . $this->database . "/" . urlencode($id), json_encode($obj));
$r = json_decode($resp);

if (isset($r->error))
{
if ($r->error == 'conflict')
{
// Document exists, try update instead
$operation = 'update';
}
}
}

switch ($operation)
{
case 'delete':
case 'update':
$resp = $this->send("GET", "/" . $this->database . "/" . urlencode($id));
$r = json_decode($resp);
$rev = $r->_rev;

if ($operation == 'delete')
{
$resp = $this->send("DELETE", "/" . $this->database . "/" . urlencode($id) . '?rev=' . $rev);
}
else
{
$obj->_rev = $rev;
$resp = $this->send("PUT", "/" . $this->database . "/" . urlencode($id), json_encode($obj));
}
var_dump($resp);

default:
break;
}
var_dump($resp);
}
}



?>
Loading

0 comments on commit 2e51894

Please sign in to comment.