DOI to RDF to JSON-LD

It’s Friday afternoon, so why not write a DOI-to-JSON-LD resolver I thought?

Luckily, web services already exist to help me on this:

http://dx.doi.org/ – The global DOI service (that has a REST API yay!)

http://rdf-translator.appspot.com/ – An RDF translator (that has a REST API yay!)

So, putting these together with a bit of curl, you get:

#!/bin/bash
DOI=$1
OUT=$2

curl -D - -L -H "Accept: application/rdf+xml" "http://dx.doi.org/$1" -o $2.rdf.xml

curl --data-urlencode content@$2.rdf.xml http://rdf-translator.appspot.com/convert/detect/json-ld/content -o $2.json

The script takes 2 parameters – firstly the DOI itself, and secondly the output filename (no extensions, just the name!).

NB: thanks to @rmounce for the heads-up about DOI complexities. Put the DOI in double quotes, and bash will be happy.

So for example:

./doi-resolve-to-jsonld.sh "10.1126/science.1249721" choulet

Gives us 2 files:

choulet.rdf.xml
choulet.json

The first being the RDF XML output from the DOI resolver, and the second being the converted JSON-LD:

choulet.json

Enjoy! 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s