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
|
# File 'lib/dbpedia_film.rb', line 6
def self.by_title(title)
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
query = sparql.query("
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbprop: <http://dbpedia.org/property/>
PREFIX dbowl: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?title ?director_display ?starring_image ?director_image ?composer_display ?thumbnail ?cinematography_display ?starring_display ?studio_display ?editing_display ?dist_display ?producer_display ?screenplay_display ?gross ?budget ?date WHERE {
?type rdf:type dbowl:Film .
?title dbprop:name ?name
FILTER regex(?name, \"^#{title}$\", 'i' ) .
?title foaf:name ?title_display .
?title dbprop:director ?director .
OPTIONAL { ?director foaf:name ?director_display . }
OPTIONAL { ?director foaf:depiction ?director_image . }
OPTIONAL { ?title dbprop:cinematography ?cinematography . }
OPTIONAL { ?cinematography foaf:name ?cinematography_display . }
OPTIONAL { ?title dbprop:editing ?editing . }
OPTIONAL { ?editing foaf:name ?editing_display . }
OPTIONAL { ?title dbprop:distributor ?distributor . }
OPTIONAL { ?title dbowl:thumbnail ?thumbnail . }
OPTIONAL { ?title dbprop:released ?date . }
OPTIONAL { ?distributor foaf:name ?dist_display . }
OPTIONAL { ?title dbprop:starring ?starring . }
OPTIONAL { ?starring foaf:name ?starring_display . }
OPTIONAL { ?starring foaf:depiction ?starring_image . }
OPTIONAL { ?title dbprop:producer ?producer . }
OPTIONAL { ?producer foaf:name ?producer_display . }
OPTIONAL { ?title dbprop:music ?composer . }
OPTIONAL { ?composer foaf:name ?composer_display . }
OPTIONAL { ?title dbprop:studio ?studio . }
OPTIONAL { ?studio foaf:name ?studio_display . }
OPTIONAL { ?title dbprop:screenplay ?screenplay . }
OPTIONAL { ?screenplay rdfs:label ?screenplay_display . }
OPTIONAL { ?title dbprop:gross ?gross . }
OPTIONAL { ?title dbowl:budget ?budget . }
} LIMIT 1
")
query.each_solution do |solution|
director = solution.to_hash[:director_display].to_s
director_image = solution.to_hash[:director_image].to_s
producer = solution.to_hash[:producer_display].to_s
starring = []
screenplay = solution.to_hash[:screenplay_display].to_s
composer = solution.to_hash[:composer_display].to_s
cinematographer = solution.to_hash[:cinematography_display].to_s
editing = solution.to_hash[:editing_display].to_s
studio = solution.to_hash[:studio_display].to_s
thumbnail = solution.to_hash[:thumbnail].to_s
dist = solution.to_hash[:dist_display].to_s
gross = solution.to_hash[:gross].to_s.to_f
budget = solution.to_hash[:budget].to_s.to_f
date = solution.to_hash[:date].to_s
query2 = sparql.query("
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbprop: <http://dbpedia.org/property/>
PREFIX dbowl: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT distinct ?title ?starring_display WHERE {
?type rdf:type dbowl:Film .
?title dbprop:name ?name
FILTER regex(?name, \"^#{title}$\", 'i' ) .
?title foaf:name ?title_display .
?title dbprop:director ?director .
?title dbowl:starring ?starring .
?starring foaf:name ?starring_display .
} LIMIT 10")
query2.each_solution do |solution2|
starring.push(solution2.to_hash[:starring_display])
end
meta = {:director => director, :director_image => director_image, :producer => producer, :screenplay => screenplay, :starring => starring, :composer => composer, :cinematographer => cinematographer, :editing => editing, :studio => studio, :thumbnail => thumbnail, :dist => dist, :gross => gross, :budget => budget, :date => date}
return meta
end
end
|