diff --git a/Sparql.py b/Sparql.py new file mode 100644 index 0000000000000000000000000000000000000000..f562f3d91c2ec9f95ab7dc4ee883ddc88db4ff54 --- /dev/null +++ b/Sparql.py @@ -0,0 +1,89 @@ +from SPARQLWrapper import SPARQLWrapper, JSON +from flask import jsonify +sparql = SPARQLWrapper("http://dbpedia.org/sparql") + + +#Bekommt den Namen des Kuenstlers +#Gibt einen Tupel (Name, Geschlecht, Geburtsdatum, Todesdatum, Beschreibung) zurueck +def sendSparqlQuery(name): + if "(" in name: + name = name.split(" (")[0] + print("Name :" + name+": ") + results = send(name) + print("Empfange") + test = results['results']['bindings'] + print(len(test)) + if(len(test) >= 1): + tests = test + for test in tests: + name = test['name']['value'] + gender = test['gender']['value'] + birth = test['birth']['value'] + death = test['death']['value'] + description = test['description']['value'] + return (name, gender, birth, death, description) + else: + return ("No Information", "No Information", "No Information", "No Information", "No Information") + + + + + +def send(name): + print("Bearbeite") + print(""" + PREFIX owl: <http://www.w3.org/2002/07/owl#> + PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> + PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + PREFIX foaf: <http://xmlns.com/foaf/0.1/> + PREFIX dc: <http://purl.org/dc/elements/1.1/> + PREFIX : <http://dbpedia.org/resource/> + PREFIX dbpedia2: <http://dbpedia.org/property/> + PREFIX dbpedia: <http://dbpedia.org/> + PREFIX skos: <http://www.w3.org/2004/02/skos/core#> + PREFIX dbo: <http://dbpedia.org/ontology/># + + + select ?person ?name ?birth ?description where { + ?person a dbo:Person ; + foaf:name ?name ; + dbo:birthDate ?birth ; + dbo:abstract ?description + filter langMatches(lang(?description),'en') + + FILTER regex(str(?name), """+ "\"" + name+ "\"" +""") + } + order by ?person + """) + sparql.setQuery(""" + PREFIX owl: <http://www.w3.org/2002/07/owl#> + PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> + PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + PREFIX foaf: <http://xmlns.com/foaf/0.1/> + PREFIX dc: <http://purl.org/dc/elements/1.1/> + PREFIX : <http://dbpedia.org/resource/> + PREFIX dbpedia2: <http://dbpedia.org/property/> + PREFIX dbpedia: <http://dbpedia.org/> + PREFIX skos: <http://www.w3.org/2004/02/skos/core#> + PREFIX dbo: <http://dbpedia.org/ontology/># + + + select ?person ?name ?gender ?birth ?death ?description where { + ?person a dbo:Person ; + foaf:name ?name ; + foaf:gender ?gender; + dbo:birthDate ?birth ; + dbo:deathDate ?death; + dbo:abstract ?description + filter langMatches(lang(?description),'en') + + FILTER regex(str(?name), """+ "\"" + name+ "\"" +""") + } + order by ?person + """) + sparql.setReturnFormat(JSON) + return sparql.query().convert() + + diff --git a/__pycache__/Sparql.cpython-35.pyc b/__pycache__/Sparql.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9d2bbfed60a3c177c4aaf76737bb2fadd4ed36ed Binary files /dev/null and b/__pycache__/Sparql.cpython-35.pyc differ diff --git a/api.py b/api.py index a784e240123334b0716a720a2b891458728a9d26..46f9525e70993a37eb8204bf39e77be1cc7f375b 100644 --- a/api.py +++ b/api.py @@ -1,6 +1,7 @@ from flask import Flask, request, jsonify, make_response, g, render_template from flask_cors import CORS import BaseXClient +from Sparql import sendSparqlQuery import threading import xml.etree.ElementTree as ET import xml.dom.minidom as dom