def getLuogo(): sparql = SPARQLWrapper("http://localhost:3030/data/query") #il mio endpoint sparql.setQuery(""" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX ao: <http://vitali.web.cs.unibo.it/AnnOtaria/> PREFIX oa: <http://www.w3.org/ns/oa#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT (COALESCE(?label,?object) AS ?risultato) WHERE{ ?annotation a oa:Annotation; ao:type ?type; oa:hasBody ?body. FILTER REGEX(?type, "denotesPlace", "i"). ?body a rdf:Statement; rdf:object ?object. OPTIONAL{?body rdfs:label ?label} } ORDER BY (?risultato) """) sparql.setReturnFormat(JSON) results = sparql.query().convert() results = results['results']['bindings'] results = json.dumps(results) return results
def info(autore): sparql = SPARQLWrapper("http://localhost:3030/data/query") sparql.setQuery(""" PREFIX oa: <http://www.w3.org/ns/oa#> PREFIX ao: <http://vitali.web.cs.unibo.it/AnnOtaria/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX aon: <http://vitali.web.cs.unibo.it/AnnOtaria/annotation/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX schema: <http://schema.org/> SELECT ?author (COALESCE(?name, "Nome non disponibile") AS ?annotator) (COALESCE(?email, "Email non disponibile") AS ?mail) WHERE{ OPTIONAL{ ?author foaf:name ?name; schema:email ?email. FILTER regex(str(?author), \"""" + autore + """\", "i") } } LIMIT 1 """) sparql.setReturnFormat(JSON) results = sparql.query().convert() results = results['results']['bindings'] results = json.dumps(results) return results
def getAnnotation(url): sparql = SPARQLWrapper("http://localhost:3030/data/query") sparql.setQuery(""" PREFIX oa: <http://www.w3.org/ns/oa#> PREFIX ao: <http://vitali.web.cs.unibo.it/AnnOtaria/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX aon: <http://vitali.web.cs.unibo.it/AnnOtaria/annotation/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX schema: <http://schema.org/> SELECT DISTINCT ?type ?timestamp ?author ?target ?object (COALESCE(?label1, "Label non disponibile") AS ?label) (COALESCE(?name, "Name non disponibile") AS ?annotator) (COALESCE(?email, "Email non disponibile") AS ?mail) WHERE{ ?ann a oa:Annotation; ao:type ?type; oa:annotatedAt ?timestamp; oa:annotatedBy ?author; oa:hasTarget ?target. FILTER regex(str(?target), \"""" + url + """\", "i"). ?ann oa:hasBody ?body. ?body a rdf:Statement; rdf:object ?object. OPTIONAL {?body rdfs:label ?label1}. } ORDER BY DESC(?timestamp) """) sparql.setReturnFormat(JSON) results = sparql.query().convert() results = results['results']['bindings'] results = json.dumps(results) return results
def getDpPedia(tipo): sparql = SPARQLWrapper("http://it.dbpedia.org/sparql/") sparql.setQuery(""" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?uri ?label WHERE { ?uri rdfs:label ?label . FILTER REGEX(?label, \"""" + tipo + """\", \"i") } ORDER BY ?label LIMIT 20""") sparql.setReturnFormat(JSON) results = sparql.query().convert() results = results['results']['bindings'] results = json.dumps(results) return results
def getAutore(): sparql = SPARQLWrapper("http://localhost:3030/data/query") sparql.setQuery(""" PREFIX oa: <http://www.w3.org/ns/oa#> SELECT DISTINCT ?person WHERE{ ?ann a oa:Annotation; oa:annotatedBy ?person. } ORDER BY DESC(?person) """) sparql.setReturnFormat(JSON) results = sparql.query().convert() results = results['results']['bindings'] results = json.dumps(results) return results