-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundtrackQuery.py
More file actions
37 lines (32 loc) · 1.05 KB
/
soundtrackQuery.py
File metadata and controls
37 lines (32 loc) · 1.05 KB
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
from rdflib import Graph
g = Graph()
filename = 'msbox.ttl'
g.parse(filename, format='turtle')
g.bind('dbo', 'http://dbpedia.org/ontology/')
g.bind('mo', 'http://purl.org/ontology/mo/')
g.bind('owl', 'http://www.w3.org/2002/07/owl#')
"""Pesquisa de soundtracks relacionadas aos filmes"""
ans = """SELECT ?x ?y ?z ?w
WHERE {
?d rdf:type ?x .
?d owl:sameAs ?w .
FILTER (?x = dbo:Movie)
}"""
ans2 = """SELECT ?y ?z ?w
WHERE {
?d owl:sameAs ?w .
?d mo:album ?y .
?y mo:track ?z .
}"""
result = g.query(ans)
for row in result:
print("From movie:", row.w)
print("The soundtracks are:")
'''
A pesquisa tem de ser feita dentro do for para obter as soundtracks do filme que
está sendo exibido na tela na iteração atual.
'''
result2 = g.query(ans2, initBindings={"w": row.w})
for row2 in result2:
print("*", row2.z)
print()