Skip to content

Instantly share code, notes, and snippets.

@adzkar
Last active February 13, 2021 11:28
Show Gist options
  • Save adzkar/bf4907f6dc6a033e4782da13c88aa8d9 to your computer and use it in GitHub Desktop.
Save adzkar/bf4907f6dc6a033e4782da13c88aa8d9 to your computer and use it in GitHub Desktop.
from SPARQLWrapper import SPARQLWrapper, JSON, DIGEST, POST
import json
with open('contoh.json') as f:
specs = json.load(f)
x = ""
for d in specs['aktivitas di lapangan']:
x += f"{d}"
print(x)
query = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX myowl: <http://www.risetgroup.org/ontologies/recommendersystem/smartphone#>
SELECT *
WHERE {
""" + x + """
}
"""
print(query)
sparql = SPARQLWrapper("http://localhost:3030/phone/sparql")
sparql.setHTTPAuth(DIGEST)
sparql.setCredentials("admin", "admin")
sparql.setMethod(POST)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["s"]["value"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment