-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
141 lines (115 loc) · 4.99 KB
/
views.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from flask import Blueprint, render_template
from SPARQLWrapper import SPARQLWrapper, JSON
import uuid
""" blueprint """
views = Blueprint(__name__, "views")
""" endpoint """
endpoint = "http://172.20.10.3:9999/blazegraph/sparql"
sparql = SPARQLWrapper(endpoint)
""" query """
""" raimondi """
raimondiWorksquery = """
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX efrbroo: <http://erlangen-crm.org/efrbroo/>
PREFIX prism: <http://prismstandard.org/namespaces/basic/2.0/>
PREFIX pro: <http://purl.org/spar/pro/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?text ?title ?pubdate ?author ?creation
WHERE {
?text a efrbroo:F24_Publication_Expression ;
ecrm:P102_has_title ?title_uri ;
prism:publicationDate ?pubdate .
?rit a pro:RoleInTime ;
pro:relatesToEntity ?text .
?author_uri pro:holdsRoleInTime ?rit ;
rdfs:label ?author . FILTER (?author="Giuseppe Raimondi"^^xsd:string)
?title_uri rdf:value ?title .
?creation efrbroo:R17_created ?text .
} order by asc(UCASE(str(?author))) limit 50
"""
raimondiInfluencingquery = """
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX efrbroo: <http://erlangen-crm.org/efrbroo/>
PREFIX prism: <http://prismstandard.org/namespaces/basic/2.0/>
PREFIX pro: <http://purl.org/spar/pro/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?text ?title ?pubdate ?author
WHERE {
?text a efrbroo:F24_Publication_Expression ;
ecrm:P102_has_title ?title_uri ;
prism:publicationDate ?pubdate .
?rit a pro:RoleInTime ;
pro:relatesToEntity ?text .
?author_uri pro:holdsRoleInTime ?rit ;
rdfs:label ?author . FILTER (!regex(?author, "Giuseppe Raimondi","i")) .
?title_uri rdf:value ?title .
} order by asc(UCASE(str(?author))) limit 50
"""
""" repim """
repimWorks = """
PREFIX dcterm: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX repim: <http://repim.unibo.it/sm/>
PREFIX crm: <http://erlangen-crm.org/current/>
PREFIX frbroo: <http://erlangen-crm.org/efrbroo/>
#?con = WorkConception ?work ?title ?pubdate ?author
select * {
?con <http://erlangen-crm.org/current/P94_has_created> ?work.
?work rdfs:label ?title.
?con <http://erlangen-crm.org/current/P14_carried_out_by>/rdfs:label ?author.
?con <http://erlangen-crm.org/current/P4_has_time-span>/<http://erlangen-crm.org/current/P78_is_identified_by>/rdfs:label ?date.
} order by asc(UCASE(str(?author))) limit 50
"""
""" homepage """
@views.route("/")
def index():
return render_template("index.html")
""" raimondi """
@views.route("/raimondi")
def raimondi():
""" works by raimondi """
""" convert data into JSON """
sparql = SPARQLWrapper(endpoint)
sparql.setTimeout(55)
sparql.setQuery(raimondiWorksquery)
sparql.setReturnFormat(JSON)
raimondiResults = sparql.query().convert()
""" original author works dict """
authorDict = {}
for result in raimondiResults["results"]["bindings"]:
uuidID = uuid.uuid4()
id = str(uuidID)
authorDict[result["creation"]["value"]] = {"id": id, "title": result["title"]["value"], "pubdate": result["pubdate"]["value"], "author": result["author"]["value"]}
""" influencing authors works """
""" convert data into JSON """
sparql.setQuery(raimondiInfluencingquery)
sparql.setReturnFormat(JSON)
influencersResults = sparql.query().convert()
""" influencing authors works dict """
influencersDict = {}
for result in influencersResults["results"]["bindings"]:
uuidID = uuid.uuid4()
id = str(uuidID)
influencersDict[result["text"]["value"]] = {"id": id, "title": result["title"]["value"], "pubdate": result["pubdate"]["value"], "author": result["author"]["value"]}
return render_template("raimondi.html", authorDict = authorDict, influencersDict = influencersDict)
""" repim """
@views.route("/repim")
def repim():
""" repim works """
""" convert data into JSON """
sparql = SPARQLWrapper(endpoint)
sparql.setTimeout(55)
sparql.setQuery(repimWorks)
sparql.setReturnFormat(JSON)
repimResults = sparql.query().convert()
""" repim works dict """
authorDict = {}
for result in repimResults["results"]["bindings"]:
uuidID = uuid.uuid4()
id = str(uuidID)
authorDict[result["work"]["value"]] = {"id": id, "title": result["title"]["value"], "pubdate": result["date"]["value"], "author": result["author"]["value"]}
return render_template("repim.html", authorDict = authorDict)