wikidatum 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/CHANGELOG.md +13 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +46 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/wikidatum/client.rb +22 -0
- data/lib/wikidatum/item.rb +96 -0
- data/lib/wikidatum/qualifier.rb +4 -0
- data/lib/wikidatum/reference.rb +4 -0
- data/lib/wikidatum/sitelink.rb +25 -0
- data/lib/wikidatum/snak.rb +4 -0
- data/lib/wikidatum/statement.rb +4 -0
- data/lib/wikidatum/term.rb +21 -0
- data/lib/wikidatum/version.rb +5 -0
- data/lib/wikidatum.rb +14 -0
- data/wikidatum.gemspec +38 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5aa9e8eb9fccc24e9c423dcba185ef7550ad465426f90c57128968e06e99d51
|
4
|
+
data.tar.gz: 19fc905557859d97d1e604155d08d56d416eb332d6f285246c5354bdc1f024a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ee9f49ee6689d953f308a9e2f4deaad71226080f70bf6fe3d7f375ac86bbd887e3494d50eed06b96308e6965165c86596fc7dae6abbdf2367e5f4302e49d73a
|
7
|
+
data.tar.gz: 4147886d03d2f17e2743d0b9309a22e278cbe2e0febb95acc77dbdebeb30319058b1cb33f2b142d0f1f0c84858fa3d59b40039492ff393b89fa19f04e516f54b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
6
|
+
|
7
|
+
## Unreleased
|
8
|
+
|
9
|
+
## 0.1.0 - 2022-06-20
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Initial release, nothing is really usable yet.
|
13
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wikidatum (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
minitest (5.16.0)
|
11
|
+
parallel (1.22.1)
|
12
|
+
parser (3.1.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.1.1)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.5.0)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rubocop (1.30.1)
|
19
|
+
parallel (~> 1.10)
|
20
|
+
parser (>= 3.1.0.0)
|
21
|
+
rainbow (>= 2.2.2, < 4.0)
|
22
|
+
regexp_parser (>= 1.8, < 3.0)
|
23
|
+
rexml (>= 3.2.5, < 4.0)
|
24
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
25
|
+
ruby-progressbar (~> 1.7)
|
26
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
27
|
+
rubocop-ast (1.18.0)
|
28
|
+
parser (>= 3.1.1.0)
|
29
|
+
ruby-progressbar (1.11.0)
|
30
|
+
unicode-display_width (2.1.0)
|
31
|
+
webrick (1.7.0)
|
32
|
+
yard (0.9.28)
|
33
|
+
webrick (~> 1.7.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
x86_64-darwin-21
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
minitest (~> 5.16)
|
40
|
+
rake (~> 13.0)
|
41
|
+
rubocop (~> 1.30)
|
42
|
+
wikidatum!
|
43
|
+
yard (~> 0.9)
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
2.3.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Connor Shea
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Wikidatum
|
2
|
+
|
3
|
+
This gem will support making requests with the [new Wikidata/Wikibase REST API](https://doc.wikimedia.org/Wikibase/master/js/rest-api/).
|
4
|
+
|
5
|
+
**Currently it is in very early development and is not ready for actual usage**.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'wikidatum'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install wikidatum
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/connorshea/wikidatum.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "wikidatum"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Wikidatum::Client
|
4
|
+
# @return [String] The root URL of the Wikibase instance we want to interact
|
5
|
+
# with. If not provided, will default to Wikidata.
|
6
|
+
attr_reader :wikibase_url
|
7
|
+
|
8
|
+
# @return [Boolean] Whether this client instance should identify itself
|
9
|
+
# as a bot when making requests.
|
10
|
+
attr_reader :bot
|
11
|
+
|
12
|
+
# @param wikibase_url [String] The root URL of the Wikibase instance we want
|
13
|
+
# to interact with. If not provided, will
|
14
|
+
# default to Wikidata.
|
15
|
+
# @param bot [Boolean] Whether requests sent by this client instance should
|
16
|
+
# be registered as bot requests.
|
17
|
+
# @return [Wikidatum::Client]
|
18
|
+
def initialize(wikibase_url: 'https://www.wikidata.org', bot: true)
|
19
|
+
@wikibase_url = wikibase_url
|
20
|
+
@bot = bot
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Wikidatum::Item
|
4
|
+
# @!visibility private
|
5
|
+
#
|
6
|
+
# @param labels [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing labels for this item.
|
7
|
+
# @param descriptions [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing descriptions for this item.
|
8
|
+
# @param aliases [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing aliases for this item.
|
9
|
+
# @param statements [Array<Wikidatum::Statement>] Statements for this item.
|
10
|
+
# @param sitelinks [Array<Wikidatum::Sitelink>] Sitelinks for this item.
|
11
|
+
# @return [Wikidatum::Item]
|
12
|
+
def initialize(labels:, descriptions:, aliases:, statements:, sitelinks:)
|
13
|
+
@labels = labels
|
14
|
+
@descriptions = descriptions
|
15
|
+
@aliases = aliases
|
16
|
+
@statements = statements
|
17
|
+
@sitelinks = sitelinks
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param property [String] Wikidata property, in the format of 'P123'. If unspecified, will return all statements for the item.
|
21
|
+
# @return [Array<Wikidatum::Statement>]
|
22
|
+
def statements(property: nil)
|
23
|
+
return @statements if property.nil?
|
24
|
+
|
25
|
+
# TODO
|
26
|
+
@statements
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param lang [String, Symbol]
|
30
|
+
# @return [Wikidatum::Term, nil]
|
31
|
+
def label(lang:)
|
32
|
+
@labels.find { |label| label.lang == lang.to_s }
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param langs [Array<String, Symbol>]
|
36
|
+
# @return [Array<Wikidatum::Term>]
|
37
|
+
def labels(langs: [])
|
38
|
+
return @labels if langs.empty?
|
39
|
+
|
40
|
+
langs.map!(&:to_s)
|
41
|
+
@labels.filter { |label| langs.include?(label.lang) }
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param lang [String, Symbol]
|
45
|
+
# @return [Wikidatum::Term, nil]
|
46
|
+
def description(lang:)
|
47
|
+
@descriptions.find { |desc| desc.lang == lang.to_s }
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param langs [Array<String, Symbol>]
|
51
|
+
# @return [Array<Wikidatum::Term>]
|
52
|
+
def descriptions(langs: [])
|
53
|
+
return @descriptions if langs.empty?
|
54
|
+
|
55
|
+
langs.map!(&:to_s)
|
56
|
+
@descriptions.filter { |desc| langs.include?(desc.lang) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# @param langs [Array<Symbol, String>] If unspecified, will return all aliases for all languages.
|
60
|
+
# @return [Array<Wikidatum::Term>]
|
61
|
+
def aliases(langs: [])
|
62
|
+
return @aliases if langs.empty?
|
63
|
+
|
64
|
+
langs.map!(&:to_s)
|
65
|
+
@aliases.filter { |al| langs.include?(al.lang) }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get a specific sitelink based on its shortcode.
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# item.sitelink(site: 'enwiki')
|
72
|
+
# @example Using a symbol key
|
73
|
+
# item.sitelink(site: :enwiki)
|
74
|
+
#
|
75
|
+
# @param site [String, Symbol] The shortcode for the sitelink you want to access, e.g. 'enwiki' or 'commons'. Can be a string or a symbol.
|
76
|
+
# @return [Wikidatum::Sitelink, nil]
|
77
|
+
def sitelink(site:)
|
78
|
+
@sitelinks.find { |sitelink| sitelink.site == site.to_s }
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get the sitelinks on the item.
|
82
|
+
#
|
83
|
+
# @example Getting all sitelinks for the item.
|
84
|
+
# item.sitelinks
|
85
|
+
# @example Getting only a few specific sitelinks.
|
86
|
+
# item.sitelink(sites: ['enwiki', 'eswiki', 'commons'])
|
87
|
+
#
|
88
|
+
# @param sites [Array<String, Symbol>] An array of sitelink shortcodes to return (e.g. ['enwiki', 'eswiki']), if not provided then all sitelinks will be returned.
|
89
|
+
# @return [Array<Wikidatum::Sitelink>]
|
90
|
+
def sitelinks(sites: [])
|
91
|
+
return @sitelinks if sites.empty?
|
92
|
+
|
93
|
+
sites.map!(&:to_s)
|
94
|
+
@sitelinks.filter { |sitelink| sites.include?(sitelink.site) }
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Wikidatum::Sitelinks represent associated sitelinks on a Wikidata item.
|
4
|
+
class Wikidatum::Sitelink
|
5
|
+
# @return [String]
|
6
|
+
attr_reader :site
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
attr_reader :title
|
10
|
+
|
11
|
+
# @return [Array<String>]
|
12
|
+
attr_reader :badges
|
13
|
+
|
14
|
+
# @!visibility private
|
15
|
+
#
|
16
|
+
# @param site [String, Symbol] The shortcode for the given site (e.g. 'enwiki', 'commons', etc.), can be either a string or a symbol.
|
17
|
+
# @param title [String] The title of the page in the associated Wikimedia site.
|
18
|
+
# @param badges [Array<String>] An array of badge names, optional.
|
19
|
+
# @return [Wikidatum::Sitelink]
|
20
|
+
def initialize(site:, title:, badges: [])
|
21
|
+
@site = site.to_s
|
22
|
+
@title = title
|
23
|
+
@badges = badges
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Wikidatum::Term represents "Terms", which are pairs of language codes and
|
4
|
+
# values. They're used for things like item labels, descriptions, and aliases.
|
5
|
+
class Wikidatum::Term
|
6
|
+
# @return [String]
|
7
|
+
attr_reader :lang
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :value
|
11
|
+
|
12
|
+
# @!visibility private
|
13
|
+
#
|
14
|
+
# @param lang [String, Symbol] A language code ('en', 'zh-mo', etc), can be a symbol or a string.
|
15
|
+
# @param value [String] The value of the term.
|
16
|
+
# @return [Wikidatum::Term]
|
17
|
+
def initialize(lang:, value:)
|
18
|
+
@lang = lang.to_s
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
end
|
data/lib/wikidatum.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'wikidatum/client'
|
4
|
+
require_relative 'wikidatum/item'
|
5
|
+
require_relative 'wikidatum/qualifier'
|
6
|
+
require_relative 'wikidatum/reference'
|
7
|
+
require_relative 'wikidatum/snak'
|
8
|
+
require_relative 'wikidatum/statement'
|
9
|
+
require_relative 'wikidatum/term'
|
10
|
+
require_relative 'wikidatum/version'
|
11
|
+
|
12
|
+
module Wikidatum
|
13
|
+
class Error < StandardError; end
|
14
|
+
end
|
data/wikidatum.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/wikidatum/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "wikidatum"
|
7
|
+
spec.version = Wikidatum::VERSION
|
8
|
+
spec.authors = ["Connor Shea"]
|
9
|
+
spec.email = ["connor.james.shea+rubygems@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby gem for the new Wikidata REST API."
|
12
|
+
spec.description = "Interact with the Wikidata/Wikibase REST API from Ruby."
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.7.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = "https://github.com/connorshea/wikidatum"
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/connorshea/wikidatum"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/connorshea/wikidatum/blob/main/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|))})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wikidatum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Connor Shea
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Interact with the Wikidata/Wikibase REST API from Ruby.
|
14
|
+
email:
|
15
|
+
- connor.james.shea+rubygems@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/wikidatum.rb
|
29
|
+
- lib/wikidatum/client.rb
|
30
|
+
- lib/wikidatum/item.rb
|
31
|
+
- lib/wikidatum/qualifier.rb
|
32
|
+
- lib/wikidatum/reference.rb
|
33
|
+
- lib/wikidatum/sitelink.rb
|
34
|
+
- lib/wikidatum/snak.rb
|
35
|
+
- lib/wikidatum/statement.rb
|
36
|
+
- lib/wikidatum/term.rb
|
37
|
+
- lib/wikidatum/version.rb
|
38
|
+
- wikidatum.gemspec
|
39
|
+
homepage:
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
allowed_push_host: https://rubygems.org
|
44
|
+
homepage_uri: https://github.com/connorshea/wikidatum
|
45
|
+
source_code_uri: https://github.com/connorshea/wikidatum
|
46
|
+
changelog_uri: https://github.com/connorshea/wikidatum/blob/main/CHANGELOG.md
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.7.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.3.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Ruby gem for the new Wikidata REST API.
|
66
|
+
test_files: []
|