Skip to content

Instantly share code, notes, and snippets.

@salgo60
Created February 23, 2019 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salgo60/3b9608dacc6c1a479d1b36e85930f713 to your computer and use it in GitHub Desktop.
Save salgo60/3b9608dacc6c1a479d1b36e85930f713 to your computer and use it in GitHub Desktop.
Swepub Python
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)
@salgo60
Copy link
Author

salgo60 commented Feb 23, 2019

Output results
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment