Created
July 30, 2012 14:04
-
-
Save rubinsztajn/3207088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import rdflib | |
from rdflib.graph import Graph | |
from rdflib import plugin | |
out = csv.writer(open('databib.csv', 'w')) | |
out.writerow(['Name','Page','License','Deposit']) | |
plugin.register( | |
'sparql', rdflib.query.Processor, | |
'rdfextras.sparql.processor', 'Processor') | |
plugin.register( | |
'sparql', rdflib.query.Result, | |
'rdfextras.sparql.query', 'SPARQLQueryResult') | |
ns = { | |
"foaf":"http://xmlns.com/foaf/0.1/", | |
"dcterms":"http://purl.org/dc/terms/", | |
"databib":"http://databib.org/ns#" | |
} | |
g = Graph() | |
g.parse('resource.rdf') | |
qres = g.query( | |
"""SELECT ?url ?title ?page ?lic ?deposit | |
WHERE { | |
?url dcterms:title ?title . | |
?url foaf:homepage ?page . | |
?url databib:reusePolicy ?lic . | |
?url databib:depositPolicy ?deposit . | |
}""", | |
initNs=ns) | |
for row in qres.result: | |
url, title, page, lic, deposit = row | |
xls_url = '=HYPERLINK(\"' + url + '\", \"' + title + '\")' | |
out.writerow([xls_url, page, lic, deposit]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment