Skip to content

Instantly share code, notes, and snippets.

@colwilson
Created January 22, 2012 22:55
Show Gist options
  • Save colwilson/1659213 to your computer and use it in GitHub Desktop.
Save colwilson/1659213 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
from sparql import DBpediaEndpoint
def main ():
s = DBpediaEndpoint( {
"resource": "http://dbpedia.org/resource/",
"yago": "http://dbpedia.org/class/yago/"
} )
query = """
SELECT * WHERE {
?subject rdf:type yago:Locations .
?subject dbpedia-owl:abstract ?abstract .
?subject foaf:page ?url .
?subject foaf:name ?name .
FILTER regex(?name, "London") .
FILTER(langMatches(lang(?abstract), "EN")) .
} LIMIT 1
"""
results = s.query(query)
url = results[0]["url"]["value"]
print url
abstract = results[0]["abstract"]["value"]
print abstract
if __name__ == '__main__':
try:
main()
sys.exit(0)
except KeyboardInterrupt, e: # Ctrl-C
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment