-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovieByTrackQuery.py
43 lines (37 loc) · 1.19 KB
/
movieByTrackQuery.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
from rdflib import Graph, Literal
g = Graph()
filename = 'msbox.ttl'
g.parse(filename, format='turtle')
track = input("Please input the track name: ")
track = Literal(track)
"""Pesquisa de tracks dos filmes"""
ans = """SELECT ?x ?y
WHERE {
?d mo:track ?x .
?d foaf:name ?y .
}"""
ans2 = """SELECT ?x ?y ?z ?w ?t ?n
WHERE {
?d rdf:type ?x .
?d mo:album ?y .
?y mo:track ?t .
?d owl:sameAs ?z .
?d dbo:musicComposer ?w .
?w owl:sameAs ?n .
FILTER (?x = dbo:Movie)
}"""
result = g.query(ans, initBindings={"x": track})
print()
for row in result:
print("Track:", row.x)
print("Album:", row.y)
print()
'''
A pesquisa tem de ser feita dentro do for para obter os dados do filme que
estão relacionados a track escolhida pelo usuário.
'''
result2 = g.query(ans2, initBindings={"t": track})
for row2 in result2:
print("Present in movie:", row2.z)
print("Composer:", row2.n)
print()