dbpedia_film 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dbpedia_film.gemspec +27 -0
- data/lib/dbpedia_film.rb +107 -0
- data/lib/dbpedia_film/version.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b67e23b60dcfa0d96dacb4b0cb64bc73d79a108c
|
4
|
+
data.tar.gz: d99dc5558c7a52be618df90ed9c4b5d766ce8165
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11cce59d603d57101b32a8c8c568bfa9ce447cff85e29375b812315f079dfa7fbdd7e51d7c19c975996cc18de8fc811811662a5b1ccfdc066587e719841945fa
|
7
|
+
data.tar.gz: d2f2ff693380b02d499d290c6312b71697f0b348b092ccd772326810402d4ffc96f9ea2aae04eecc7f066a5b37847399b4f8e32f92bb8052aadfea2a37574d88
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# DbpediaFilm
|
2
|
+
|
3
|
+
|
4
|
+
This gem uses is used to get metadata from DBPedia about film using the title. It's
|
5
|
+
not exact, and sometimes DBPedia can have slow response times. If you are using this
|
6
|
+
information on the web, you will want to cache the responses.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'dbpedia_film'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install dbpedia_film
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
DbpediaFilm::Metadata::by_title("Alien")
|
29
|
+
```
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
{:director=>"Scott, Ridley", :director_image=>"http://commons.wikimedia.org/wiki/Special:FilePath/Ridley_Scott_by_Gage_Skidmore.jpg", :producer=>"&pizza", :screenplay=>"Dan O'Bannon", :starring=>[], :composer=>"Jerry Goldsmith", :cinematographer=>"Derek Vanlint", :editing=>"&pizza", :studio=>"&pizza", :thumbnail=>"", :dist=>"", :gross=>0.0, :budget=>9.0, :date=>""}
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# Tests
|
38
|
+
To run the tests:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
rake test
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dbpedia_film"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dbpedia_film/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dbpedia_film"
|
8
|
+
spec.version = DbpediaFilm::VERSION
|
9
|
+
spec.authors = ["Jamie Little"]
|
10
|
+
spec.email = ["jamielittle@outlook.com"]
|
11
|
+
spec.license = "Apache-2.0"
|
12
|
+
spec.summary = "A gem for getting film metadata from DBPedia"
|
13
|
+
spec.homepage = "https://github.com/little9/dbpedia_film/"
|
14
|
+
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "sparql"
|
26
|
+
|
27
|
+
end
|
data/lib/dbpedia_film.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require "dbpedia_film/version"
|
2
|
+
require "sparql"
|
3
|
+
module DbpediaFilm
|
4
|
+
class Metadata
|
5
|
+
|
6
|
+
def self.by_title(title)
|
7
|
+
|
8
|
+
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
|
9
|
+
query = sparql.query("
|
10
|
+
|
11
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
12
|
+
PREFIX dbprop: <http://dbpedia.org/property/>
|
13
|
+
PREFIX dbowl: <http://dbpedia.org/ontology/>
|
14
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
15
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
16
|
+
|
17
|
+
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 {
|
18
|
+
?type rdf:type dbowl:Film .
|
19
|
+
?title dbprop:name ?name
|
20
|
+
FILTER regex(?name, \"^#{title}$\", 'i' ) .
|
21
|
+
?title foaf:name ?title_display .
|
22
|
+
?title dbprop:director ?director .
|
23
|
+
OPTIONAL { ?director foaf:name ?director_display . }
|
24
|
+
OPTIONAL { ?director foaf:depiction ?director_image . }
|
25
|
+
OPTIONAL { ?title dbprop:cinematography ?cinematography . }
|
26
|
+
OPTIONAL { ?cinematography foaf:name ?cinematography_display . }
|
27
|
+
OPTIONAL { ?title dbprop:editing ?editing . }
|
28
|
+
OPTIONAL { ?editing foaf:name ?editing_display . }
|
29
|
+
OPTIONAL { ?title dbprop:distributor ?distributor . }
|
30
|
+
OPTIONAL { ?title dbowl:thumbnail ?thumbnail . }
|
31
|
+
OPTIONAL { ?title dbprop:released ?date . }
|
32
|
+
|
33
|
+
OPTIONAL { ?distributor foaf:name ?dist_display . }
|
34
|
+
OPTIONAL { ?title dbprop:starring ?starring . }
|
35
|
+
OPTIONAL { ?starring foaf:name ?starring_display . }
|
36
|
+
OPTIONAL { ?starring foaf:depiction ?starring_image . }
|
37
|
+
OPTIONAL { ?title dbprop:producer ?producer . }
|
38
|
+
OPTIONAL { ?producer foaf:name ?producer_display . }
|
39
|
+
OPTIONAL { ?title dbprop:music ?composer . }
|
40
|
+
OPTIONAL { ?composer foaf:name ?composer_display . }
|
41
|
+
OPTIONAL { ?title dbprop:studio ?studio . }
|
42
|
+
OPTIONAL { ?studio foaf:name ?studio_display . }
|
43
|
+
OPTIONAL { ?title dbprop:screenplay ?screenplay . }
|
44
|
+
OPTIONAL { ?screenplay rdfs:label ?screenplay_display . }
|
45
|
+
|
46
|
+
OPTIONAL { ?title dbprop:gross ?gross . }
|
47
|
+
OPTIONAL { ?title dbowl:budget ?budget . }
|
48
|
+
} LIMIT 1
|
49
|
+
|
50
|
+
|
51
|
+
")
|
52
|
+
|
53
|
+
query.each_solution do |solution|
|
54
|
+
|
55
|
+
director = solution.to_hash[:director_display].to_s
|
56
|
+
director_image = solution.to_hash[:director_image].to_s
|
57
|
+
producer = solution.to_hash[:producer_display].to_s
|
58
|
+
starring = []
|
59
|
+
screenplay = solution.to_hash[:screenplay_display].to_s
|
60
|
+
composer = solution.to_hash[:composer_display].to_s
|
61
|
+
cinematographer = solution.to_hash[:cinematography_display].to_s
|
62
|
+
editing = solution.to_hash[:editing_display].to_s
|
63
|
+
studio = solution.to_hash[:studio_display].to_s
|
64
|
+
thumbnail = solution.to_hash[:thumbnail].to_s
|
65
|
+
dist = solution.to_hash[:dist_display].to_s
|
66
|
+
gross = solution.to_hash[:gross].to_s.to_f
|
67
|
+
budget = solution.to_hash[:budget].to_s.to_f
|
68
|
+
date = solution.to_hash[:date].to_s
|
69
|
+
# release date
|
70
|
+
# running time
|
71
|
+
|
72
|
+
query2 = sparql.query("
|
73
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
74
|
+
PREFIX dbprop: <http://dbpedia.org/property/>
|
75
|
+
PREFIX dbowl: <http://dbpedia.org/ontology/>
|
76
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
77
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
78
|
+
|
79
|
+
SELECT distinct ?title ?starring_display WHERE {
|
80
|
+
?type rdf:type dbowl:Film .
|
81
|
+
?title dbprop:name ?name
|
82
|
+
FILTER regex(?name, \"^#{title}$\", 'i' ) .
|
83
|
+
?title foaf:name ?title_display .
|
84
|
+
?title dbprop:director ?director .
|
85
|
+
?title dbowl:starring ?starring .
|
86
|
+
?starring foaf:name ?starring_display .
|
87
|
+
} LIMIT 10")
|
88
|
+
|
89
|
+
query2.each_solution do |solution2|
|
90
|
+
starring.push(solution2.to_hash[:starring_display])
|
91
|
+
end
|
92
|
+
|
93
|
+
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}
|
94
|
+
|
95
|
+
|
96
|
+
return meta
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbpedia_film
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Little
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sparql
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jamielittle@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- dbpedia_film.gemspec
|
84
|
+
- lib/dbpedia_film.rb
|
85
|
+
- lib/dbpedia_film/version.rb
|
86
|
+
homepage: https://github.com/little9/dbpedia_film/
|
87
|
+
licenses:
|
88
|
+
- Apache-2.0
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.5.1
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: A gem for getting film metadata from DBPedia
|
110
|
+
test_files: []
|