Created
February 23, 2019 10:19
-
-
Save salgo60/3b9608dacc6c1a479d1b36e85930f713 to your computer and use it in GitHub Desktop.
Swepub Python
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
from SPARQLWrapper import SPARQLWrapper, JSON | |
sparql = SPARQLWrapper("http://virhp07.libris.kb.se/sparql/") | |
sparql.setQuery(""" | |
PREFIX bmc: <http://swepub.kb.se/bibliometric/model#> | |
PREFIX swpa_m: <http://swepub.kb.se/SwePubAnalysis/model#> | |
PREFIX mods_m: <http://swepub.kb.se/mods/model#> | |
PREFIX outt_m: <http://swepub.kb.se/SwePubAnalysis/OutputTypes/model#> | |
PREFIX xlink: <http://www.w3.org/1999/xlink#> | |
SELECT DISTINCT xsd:string(?_orgName) | |
COUNT(DISTINCT ?_workID) as ?c | |
?_pubYear | |
WHERE | |
{ | |
?CreativeWork bmc:localID ?_workID . | |
?Publication bmc:localID ?_publicationID . | |
?Organization rdfs:label ?_orgName . | |
FILTER(lang(?_orgName) = 'sv' ) | |
?CreativeWork bmc:reportedBy ?Record . | |
?CreativeWork a bmc:CreativeWork . | |
?CreativeWork bmc:publishedAs ?Publication . | |
?CreativeWork bmc:publicationYearEarliest ?_pubYear . | |
?CreativeWork bmc:hasCreatorShip ?CreatorShip . | |
?CreatorShip bmc:hasAffiliation ?CreatorAffiliation . | |
?CreatorAffiliation bmc:hasOrganization ?Organization . | |
?CreatorShip bmc:hasCreator ?Creator . | |
} | |
ORDER BY xsd:string(?_orgName) ?_pubYear | |
""") | |
sparql.setReturnFormat(JSON) | |
results = sparql.query().convert() | |
for result in results["results"]["bindings"]: | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output results