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 6fdf337006f4fdc049881a5a4cea0b10db65ae58..b6d15d56f8f54ad8dd4e34e297ce19bfacf08439 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 @@ -15,7 +16,7 @@ def main(): #globvar = session.query("db:open(\"Holzschnitt\")") session.execute("open Holzschnitte1") merke = [] - + for i in range(1,10): url = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/resource/resourceLink/text()) return $x" ).execute() actor = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/descriptiveMetadata/eventWrap/actor/name/text()) return $x" ).execute() diff --git a/saveLink.py b/saveLink.py index 12c642853eb869a35d5ff94ca1ac7f2ddf8b6736..fdd5605535948a8509654c061775fc66646b9522 100644 --- a/saveLink.py +++ b/saveLink.py @@ -20,7 +20,7 @@ file_object = open("saveImages.sh", "w") for link in links: file_object.write("wget " + link + "\n") - + print("wget " + link) print(len(links)) \ No newline at end of file diff --git a/sparql query b/sparql query new file mode 100644 index 0000000000000000000000000000000000000000..c02ee44499aef69b8d407c512b91c47db011aa05 --- /dev/null +++ b/sparql query @@ -0,0 +1,24 @@ +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(?name),'en') + filter langMatches(lang(?description),'en') +} +order by ?person +offset 100 +limit 50