-
Notifications
You must be signed in to change notification settings - Fork 0
/
testBed.py
193 lines (156 loc) · 4.98 KB
/
testBed.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
'''
Created on Jul 4, 2011
@author: tim
'''
import pytassium
import time
def SPARQLAndRespond(dataset, query):
response, data = dataset.select(query)
if response.status in range(200,300):
# data now contains a dictionary of results
import pprint
#pprint.pprint(data)
return data
else:
print "Oh no! %d %s " % (response.status, response.reason)
### API KEY ###
apiKey = '5dac588049e18e51fead5e788dc2449e38c2077a'
##==---------------------==##
##- Ordnance-Survey -##
##==---------------------==##
OSdataset = pytassium.Dataset('ordnance-survey-linked-data',apiKey)
AllBouroughsWithGIS = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
PREFIX geometry: <http://data.ordnancesurvey.co.uk/ontology/geometry/>
select * where {
?s rdf:type admingeo:Borough.
?s geometry:extent ?o
}
"""
#SPARQLAndRespond(OSdataset, AllBouroughsWithGIS)
##==---------------------==##
##- Education -##
##==---------------------==##
EducationDataset = pytassium.Dataset('education',apiKey)
LatymerSchoolQuery = '''
SELECT * WHERE {
<http://education.data.gov.uk/id/school/102055> ?p ?o.
}
'''
#SPARQLAndRespond(EducationDataset, LatymerSchoolQuery)
##==---------------------==##
##- Species in the UK -##
##==---------------------==##
GeoSpecies = pytassium.Dataset('geospecies', apiKey)
SpeciesInUKWithCommonName = """
PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
PREFIX uk: <http://sws.geonames.org/2635167/>
SELECT * WHERE{
?species geospecies:hasCommonName ?name;
geospecies:isExpectedIn uk:.
}
"""
speciesTest = """
PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
PREFIX uk: <http://sws.geonames.org/2635167/>
PREFIX bats: <http://lod.geospecies.org/orders/TuTld>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT ?family_name ?canonicalName ?speciesconcept ?geospeciespage
WHERE {
?x geospecies:hasFamilyName ?family_name;
geospecies:hasCanonicalName ?canonicalName;
dcterms:identifier ?speciesconcept;
geospecies:hasGeoSpeciesPage ?geospeciespage;
geospecies:inOrder bats:;
geospecies:isExpectedIn uk:.
}
ORDER BY ?family_name ?canonicalName
"""
#data = SPARQLAndRespond(GeoSpecies, SpeciesInUKWithCommonName)
#for result in data[1]:
# print result['name']
##==---------------------==##
##- DISCOGS -##
##==---------------------==##
Discogs = pytassium.Dataset('discogs', apiKey)
artistsJoinedByLabels = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mo: <http://purl.org/ontology/mo/>
SELECT DISTINCT ?artist2 ?name WHERE{
<http://data.kasabi.com/dataset/discogs/artist/cti> foaf:made ?release.
?release mo:publisher ?label.
?release2 mo:publisher ?label.
?artist2 foaf:made ?release2.
?artist2 foaf:name ?name.
}
"""
Colabs = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX dc: <http://purl.org/dc/terms/>
SELECT DISTINCT ?artist WHERE{
<http://data.kasabi.com/dataset/discogs/artist/cti> foaf:made ?release.
?artist foaf:made ?release.
}
"""
Compalations = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX dc: <http://purl.org/dc/terms/>
SELECT DISTINCT ?artist2 WHERE{
<http://data.kasabi.com/dataset/discogs/artist/jan-hammer> foaf:made ?release.
?release <http://xmlns.com/foaf/0.1/maker> ?artist2.
}
"""
# <http://data.kasabi.com/dataset/discogs/artist/various>
#data = SPARQLAndRespond(Discogs, artistsJoinedByLabels)
##==-------------------------==##
##== MUSICBRAINZ ==##
##==-------------------------==##
mb = pytassium.Dataset('musicbrainz', apiKey)
bbcMu = pytassium.Dataset('bbc-music', apiKey)
findMembers = """
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?mb WHERE{
?group mo:discogs <http://www.discogs.com/artist/Radiohead>.
?group foaf:member ?member.
?member mo:musicbrainz ?mb.
}
"""
discogs2lastfm = """
PREFIX mo: <http://purl.org/ontology/mo/>
SELECT * where{
?artist mo:musicbrainz <%s>.
?artist mo:wikipedia ?wiki
}
"""
data = SPARQLAndRespond(mb, findMembers)
wikiPages = []
for result in data[1]:
query = discogs2lastfm % result['mb'].decode()
data2 = SPARQLAndRespond(bbcMu, query)
for result in data2[1]:
wikiPages.append(result['wiki'])
##==-------------------------==##
##== DBPEDIA ==##
##==-------------------------==##
dbpedia = pytassium.Dataset('dbpedia-36', apiKey)
artistDetails = '''
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia-prop: <http://dbpedia.org/property/>
select * where{
?s foaf:page <%s>.
?s dbpedia-prop:origin ?origin.
?s dbpedia-prop:dateOfBirth ?dob.
?s dbpedia-owl:instrument ?instrument.
?s dbpedia-owl:genre ?genre.
}
'''
for page in wikiPages:
query = artistDetails % page
data3 = SPARQLAndRespond(dbpedia, query)
for result in data3[1]:
print result