Skip to content

Instantly share code, notes, and snippets.

@axiomsofchoice
Created April 20, 2011 16:50
Show Gist options
  • Save axiomsofchoice/931878 to your computer and use it in GitHub Desktop.
Save axiomsofchoice/931878 to your computer and use it in GitHub Desktop.
Use content negotiation with a certain DOI to obtain linked data about that resource.
"""Use content negotiation with a certain DOI to obtain linked data about that resource.
See also:
http://myemail.constantcontact.com/CrossRef-and-International-DOI-Foundation-Collaborate-on-Linked-Data-Friendly-DOIs.html?soid=1102390657767&aid=eTYx65PAErU
http://www.crossref.org/CrossTech/2011/04/content_negotiation_for_crossr.html
"""
import urllib
exampleDOI = 'http://dx.doi.org/10.1126/science.1157784'
op = urllib.FancyURLopener()
op.addheader('Accept', 'application/rdf+xml')
f = op.open(exampleDOI)
s = f.read()
#print s
from rdflib import Graph
from rdflib import Namespace
import StringIO
g = Graph()
g.parse(StringIO.StringIO(s), format="xml")
for s, p, o in g:
if str(s)==exampleDOI and str(p)=="http://purl.org/dc/terms/title":
print "%s has title \"%s\"" % (s,o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment