File: example-ask.py

package info (click to toggle)
sparql-wrapper-python 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,228 kB
  • sloc: python: 14,201; makefile: 30
file content (35 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# -*- coding: utf-8 -*-

from SPARQLWrapper import SPARQLWrapper, JSON, XML, CSV, TSV

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
    ASK WHERE { 
        <http://dbpedia.org/resource/Asturias> rdfs:label "Asturias"@es
    }    
""")

# JSON example
print('\n\n*** JSON Example')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
print(results)

# XML example
print('\n\n*** XML Example')
sparql.setReturnFormat(XML)
results = sparql.query().convert()
print(results.toxml())

# CSV example
print('\n\n*** CSV Example')
sparql.setReturnFormat(CSV)
results = sparql.query().convert()
print(results)

# TSV example
print('\n\n*** TSV Example')
sparql.setReturnFormat(TSV)
results = sparql.query().convert()
print(results)