wikidatum 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +28 -1
- data/README.md +38 -3
- data/Rakefile +1 -1
- data/lib/wikidatum/client.rb +356 -8
- data/lib/wikidatum/data_value_type/base.rb +61 -0
- data/lib/wikidatum/data_value_type/globe_coordinate.rb +92 -0
- data/lib/wikidatum/data_value_type/monolingual_text.rb +74 -0
- data/lib/wikidatum/data_value_type/no_value.rb +29 -0
- data/lib/wikidatum/data_value_type/quantity.rb +92 -0
- data/lib/wikidatum/data_value_type/some_value.rb +29 -0
- data/lib/wikidatum/data_value_type/time.rb +187 -0
- data/lib/wikidatum/data_value_type/wikibase_entity_id.rb +83 -0
- data/lib/wikidatum/data_value_type/wikibase_string.rb +61 -0
- data/lib/wikidatum/data_value_type.rb +11 -0
- data/lib/wikidatum/item.rb +118 -12
- data/lib/wikidatum/qualifier.rb +5 -2
- data/lib/wikidatum/reference.rb +43 -0
- data/lib/wikidatum/sitelink.rb +15 -1
- data/lib/wikidatum/snak.rb +75 -0
- data/lib/wikidatum/statement.rb +73 -0
- data/lib/wikidatum/term.rb +13 -0
- data/lib/wikidatum/version.rb +1 -1
- data/lib/wikidatum.rb +48 -0
- data/wikidatum.gemspec +2 -2
- metadata +29 -4
data/lib/wikidatum/item.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Wikidatum::Item
|
4
|
+
# @return [String] the ID of the Wikibase item, in the format "Q123".
|
5
|
+
attr_reader :id
|
6
|
+
|
4
7
|
# @!visibility private
|
5
8
|
#
|
9
|
+
# @param id [String] The ID of the Wikibase item, in the format "Q123".
|
6
10
|
# @param labels [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing labels for this item.
|
7
11
|
# @param descriptions [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing descriptions for this item.
|
8
12
|
# @param aliases [Array<Wikidatum::Term>] An array of {Wikidatum::Term}s representing aliases for this item.
|
9
13
|
# @param statements [Array<Wikidatum::Statement>] Statements for this item.
|
10
14
|
# @param sitelinks [Array<Wikidatum::Sitelink>] Sitelinks for this item.
|
11
15
|
# @return [Wikidatum::Item]
|
12
|
-
def initialize(labels:, descriptions:, aliases:, statements:, sitelinks:)
|
16
|
+
def initialize(id:, labels:, descriptions:, aliases:, statements:, sitelinks:)
|
17
|
+
@id = id
|
13
18
|
@labels = labels
|
14
19
|
@descriptions = descriptions
|
15
20
|
@aliases = aliases
|
@@ -17,21 +22,28 @@ class Wikidatum::Item
|
|
17
22
|
@sitelinks = sitelinks
|
18
23
|
end
|
19
24
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# Get the label for an item in a given language.
|
26
|
+
#
|
27
|
+
# @example Get the label of the item for a given language.
|
28
|
+
# item.label(lang: 'es')
|
29
|
+
# @example Also accepts symbols.
|
30
|
+
# item.label(lang: :en)
|
31
|
+
# @example You can also use the {Wikidatum::LanguageCodes} constants to write code that's easier to read.
|
32
|
+
# item.label(lang: Wikidatum::LanguageCodes::English)
|
33
|
+
#
|
29
34
|
# @param lang [String, Symbol]
|
30
35
|
# @return [Wikidatum::Term, nil]
|
31
36
|
def label(lang:)
|
32
37
|
@labels.find { |label| label.lang == lang.to_s }
|
33
38
|
end
|
34
39
|
|
40
|
+
# Get labels for an item.
|
41
|
+
#
|
42
|
+
# @example Get all labels on the item.
|
43
|
+
# item.labels
|
44
|
+
# @example Get the labels for a few specific languages.
|
45
|
+
# item.labels(langs: ['en', 'es', 'fr'])
|
46
|
+
#
|
35
47
|
# @param langs [Array<String, Symbol>]
|
36
48
|
# @return [Array<Wikidatum::Term>]
|
37
49
|
def labels(langs: [])
|
@@ -41,12 +53,28 @@ class Wikidatum::Item
|
|
41
53
|
@labels.filter { |label| langs.include?(label.lang) }
|
42
54
|
end
|
43
55
|
|
56
|
+
# Get the description for an item in a given language.
|
57
|
+
#
|
58
|
+
# @example Get the description in a given language.
|
59
|
+
# item.description(lang: 'fr')
|
60
|
+
# @example Also accepts symbols.
|
61
|
+
# item.description(lang: :en)
|
62
|
+
# @example You can also use the {Wikidatum::LanguageCodes} constants to write code that's easier to read.
|
63
|
+
# item.description(lang: Wikidatum::LanguageCodes::English)
|
64
|
+
#
|
44
65
|
# @param lang [String, Symbol]
|
45
66
|
# @return [Wikidatum::Term, nil]
|
46
67
|
def description(lang:)
|
47
68
|
@descriptions.find { |desc| desc.lang == lang.to_s }
|
48
69
|
end
|
49
70
|
|
71
|
+
# Get descriptions for an item.
|
72
|
+
#
|
73
|
+
# @example Get all descriptions on the item.
|
74
|
+
# item.descriptions
|
75
|
+
# @example Get the descriptions for a few specific languages.
|
76
|
+
# item.descriptions(langs: ['en', 'es', 'fr'])
|
77
|
+
#
|
50
78
|
# @param langs [Array<String, Symbol>]
|
51
79
|
# @return [Array<Wikidatum::Term>]
|
52
80
|
def descriptions(langs: [])
|
@@ -56,6 +84,15 @@ class Wikidatum::Item
|
|
56
84
|
@descriptions.filter { |desc| langs.include?(desc.lang) }
|
57
85
|
end
|
58
86
|
|
87
|
+
# Get aliases for the item.
|
88
|
+
#
|
89
|
+
# @example Get aliases for all languages.
|
90
|
+
# item.aliases
|
91
|
+
# @example Get the aliases for one or more specific languages.
|
92
|
+
# item.aliases(langs: ['en', 'es'])
|
93
|
+
# @example Also accepts symbols.
|
94
|
+
# item.aliases(langs: [:en, :es])
|
95
|
+
#
|
59
96
|
# @param langs [Array<Symbol, String>] If unspecified, will return all aliases for all languages.
|
60
97
|
# @return [Array<Wikidatum::Term>]
|
61
98
|
def aliases(langs: [])
|
@@ -65,6 +102,21 @@ class Wikidatum::Item
|
|
65
102
|
@aliases.filter { |al| langs.include?(al.lang) }
|
66
103
|
end
|
67
104
|
|
105
|
+
# Get statements on the item.
|
106
|
+
#
|
107
|
+
# @example Get all statements.
|
108
|
+
# item.statements
|
109
|
+
# @example Get statements for one or more specific properties.
|
110
|
+
# item.statements(properties: ['P123', 'P124'])
|
111
|
+
#
|
112
|
+
# @param properties [Array<String>] One or more Wikidata properties, in the format of `['P123']`. If unspecified, will return all statements for the item.
|
113
|
+
# @return [Array<Wikidatum::Statement>]
|
114
|
+
def statements(properties: [])
|
115
|
+
return @statements if properties.empty?
|
116
|
+
|
117
|
+
@statements.filter { |statement| properties.include?(statement.property_id) }
|
118
|
+
end
|
119
|
+
|
68
120
|
# Get a specific sitelink based on its shortcode.
|
69
121
|
#
|
70
122
|
# @example
|
@@ -83,9 +135,11 @@ class Wikidatum::Item
|
|
83
135
|
# @example Getting all sitelinks for the item.
|
84
136
|
# item.sitelinks
|
85
137
|
# @example Getting only a few specific sitelinks.
|
86
|
-
# item.
|
138
|
+
# item.sitelinks(sites: ['enwiki', 'eswiki', 'commons'])
|
139
|
+
# @example Also accepts symbols.
|
140
|
+
# item.sitelinks(sites: [:enwiki, :eswiki])
|
87
141
|
#
|
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.
|
142
|
+
# @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
143
|
# @return [Array<Wikidatum::Sitelink>]
|
90
144
|
def sitelinks(sites: [])
|
91
145
|
return @sitelinks if sites.empty?
|
@@ -93,4 +147,56 @@ class Wikidatum::Item
|
|
93
147
|
sites.map!(&:to_s)
|
94
148
|
@sitelinks.filter { |sitelink| sites.include?(sitelink.site) }
|
95
149
|
end
|
150
|
+
|
151
|
+
# Convert the item, including all of its labels, descriptions, aliases,
|
152
|
+
# statements, and sitelinks, to a Ruby hash.
|
153
|
+
#
|
154
|
+
# This can be useful for debugging purposes.
|
155
|
+
#
|
156
|
+
# @example View the contents of an item according to the Wikidatum gem by outputting prettified JSON.
|
157
|
+
# require 'json'
|
158
|
+
#
|
159
|
+
# puts JSON.pretty_generate(item.to_h)
|
160
|
+
#
|
161
|
+
# @return [Hash]
|
162
|
+
def to_h
|
163
|
+
{
|
164
|
+
id: @id,
|
165
|
+
labels: @labels.map(&:to_h),
|
166
|
+
descriptions: @descriptions.map(&:to_h),
|
167
|
+
aliases: @aliases.map(&:to_h),
|
168
|
+
statements: @statements.map(&:to_h),
|
169
|
+
sitelinks: @sitelinks.map(&:to_h)
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
# @!visibility private
|
174
|
+
#
|
175
|
+
# This takes in the JSON blob (as a hash) that is output for an item record
|
176
|
+
# in the API and turns it into an actual instance of an Item.
|
177
|
+
#
|
178
|
+
# @param item_json [Hash]
|
179
|
+
# @return [Wikidatum::Item]
|
180
|
+
def self.marshal_load(item_json)
|
181
|
+
labels = item_json['labels'].to_a.map { |lang, label| Wikidatum::Term.new(lang: lang, value: label) }
|
182
|
+
descriptions = item_json['descriptions'].to_a.map { |lang, desc| Wikidatum::Term.new(lang: lang, value: desc) }
|
183
|
+
aliases = item_json['aliases'].to_a.flat_map do |lang, als|
|
184
|
+
als.map { |al| Wikidatum::Term.new(lang: lang, value: al) }
|
185
|
+
end
|
186
|
+
statements = item_json['statements'].to_a.flat_map do |_property_id, st_arr|
|
187
|
+
st_arr.map { |statement| Wikidatum::Statement.marshal_load(statement) }
|
188
|
+
end
|
189
|
+
sitelinks = item_json['sitelinks'].to_a.map do |_name, sitelink|
|
190
|
+
Wikidatum::Sitelink.new(site: sitelink['site'], title: sitelink['title'], badges: sitelink['badges'])
|
191
|
+
end
|
192
|
+
|
193
|
+
Wikidatum::Item.new(
|
194
|
+
id: item_json['id'],
|
195
|
+
labels: labels,
|
196
|
+
descriptions: descriptions,
|
197
|
+
aliases: aliases,
|
198
|
+
statements: statements,
|
199
|
+
sitelinks: sitelinks
|
200
|
+
)
|
201
|
+
end
|
96
202
|
end
|
data/lib/wikidatum/qualifier.rb
CHANGED
data/lib/wikidatum/reference.rb
CHANGED
@@ -1,4 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Wikidatum::Reference
|
4
|
+
# @return [String] Hash of the reference (a cryptographic hash, not a Ruby hash).
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
# @return [Array<Wikidatum::Snak>]
|
8
|
+
attr_reader :snaks
|
9
|
+
|
10
|
+
# @!visibility private
|
11
|
+
# @param hash [String] Hash of the reference (a cryptographic hash, not a Ruby hash).
|
12
|
+
# @param snaks [Array<Wikidatum::Snak>]
|
13
|
+
def initialize(hash:, snaks:)
|
14
|
+
@hash = hash
|
15
|
+
@snaks = snaks
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Hash]
|
19
|
+
def to_h
|
20
|
+
{
|
21
|
+
hash: @hash,
|
22
|
+
snaks: @snaks.map(&:to_h)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String]
|
27
|
+
def inspect
|
28
|
+
"<Wikidatum::Reference hash=#{@hash.inspect} snaks=#{@snaks.inspect}>"
|
29
|
+
end
|
30
|
+
|
31
|
+
# @!visibility private
|
32
|
+
#
|
33
|
+
# This takes in the JSON blob (as a hash) that is output for a given
|
34
|
+
# reference in the API and turns it into an actual instance of a
|
35
|
+
# Reference.
|
36
|
+
#
|
37
|
+
# @param ref_json [Hash]
|
38
|
+
# @return [Wikidatum::Reference]
|
39
|
+
def self.marshal_load(ref_json)
|
40
|
+
snaks = ref_json['snaks'].values.flatten.map { |snak| Wikidatum::Snak.marshal_load(snak) }
|
41
|
+
|
42
|
+
Wikidatum::Reference.new(
|
43
|
+
hash: ref_json['hash'],
|
44
|
+
snaks: snaks
|
45
|
+
)
|
46
|
+
end
|
4
47
|
end
|
data/lib/wikidatum/sitelink.rb
CHANGED
@@ -15,11 +15,25 @@ class Wikidatum::Sitelink
|
|
15
15
|
#
|
16
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
17
|
# @param title [String] The title of the page in the associated Wikimedia site.
|
18
|
-
# @param badges [Array<String>] An array of
|
18
|
+
# @param badges [Array<String>] An array of badges, given as item IDs (e.g. `['Q123', 'Q124']`) optional.
|
19
19
|
# @return [Wikidatum::Sitelink]
|
20
20
|
def initialize(site:, title:, badges: [])
|
21
21
|
@site = site.to_s
|
22
22
|
@title = title
|
23
23
|
@badges = badges
|
24
24
|
end
|
25
|
+
|
26
|
+
# @return [Hash]
|
27
|
+
def to_h
|
28
|
+
{
|
29
|
+
site: @site,
|
30
|
+
title: @title,
|
31
|
+
badges: @badges
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def inspect
|
37
|
+
"<Wikidatum::Sitelink site=#{@site.inspect} title=#{@title.inspect} badges=#{@badges.inspect}>"
|
38
|
+
end
|
25
39
|
end
|
data/lib/wikidatum/snak.rb
CHANGED
@@ -1,4 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Wikidatum::Snak
|
4
|
+
# @return [String] Hash of a snak (a cryptographic hash, not a Ruby hash).
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :snaktype
|
9
|
+
|
10
|
+
# @return [String] ID of the property for this Snak, in the format 'P123'.
|
11
|
+
attr_reader :property
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :datatype
|
15
|
+
|
16
|
+
# For more information on the possible types that can be returned by
|
17
|
+
# datavalues, see the official documentation:
|
18
|
+
# https://doc.wikimedia.org/Wikibase/master/php/md_docs_topics_json.html#json_datavalues
|
19
|
+
#
|
20
|
+
# @return [Wikidatum::DataValueType::Base] the value of the statement, can take various forms
|
21
|
+
attr_reader :datavalue
|
22
|
+
|
23
|
+
# @!visibility private
|
24
|
+
# @param hash [String] Hash of a snak (a cryptographic hash, not a Ruby hash).
|
25
|
+
# @param snaktype [String]
|
26
|
+
# @param property [String] ID of the property for this Snak, in the format 'P123'.
|
27
|
+
# @param datatype [String]
|
28
|
+
# @param datavalue [DataValueType::GlobeCoordinate, DataValueType::MonolingualText, DataValueType::Quantity, DataValueType::WikibaseString, DataValueType::Time, DataValueType::WikibaseEntityId]
|
29
|
+
def initialize(hash:, snaktype:, property:, datatype:, datavalue:)
|
30
|
+
@hash = hash
|
31
|
+
@snaktype = snaktype
|
32
|
+
@property = property
|
33
|
+
@datatype = datatype
|
34
|
+
@datavalue = datavalue
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Hash]
|
38
|
+
def to_h
|
39
|
+
{
|
40
|
+
hash: @hash,
|
41
|
+
snaktype: @snaktype,
|
42
|
+
property: @property,
|
43
|
+
datatype: @datatype,
|
44
|
+
datavalue: @datavalue.to_h
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String]
|
49
|
+
def inspect
|
50
|
+
"<Wikidatum::Snak hash=#{@hash.inspect} snaktype=#{@snaktype.inspect} property=#{@property.inspect} datatype=#{@datatype.inspect} datavalue=#{@datavalue.inspect}>"
|
51
|
+
end
|
52
|
+
|
53
|
+
# @!visibility private
|
54
|
+
#
|
55
|
+
# This takes in the JSON blob (as a hash) that is output for a given
|
56
|
+
# snak in the API and turns it into an actual instance of a Snak.
|
57
|
+
#
|
58
|
+
# @param snak_json [Hash]
|
59
|
+
# @return [Wikidatum::Snak]
|
60
|
+
def self.marshal_load(snak_json)
|
61
|
+
# snaktype can be 'novalue' (no value) or 'somevalue' (unknown), so we handle those as somewhat special cases
|
62
|
+
case snak_json['snaktype']
|
63
|
+
when 'novalue'
|
64
|
+
datavalue = Wikidatum::DataValueType::Base.marshal_load('novalue', nil)
|
65
|
+
when 'somevalue'
|
66
|
+
datavalue = Wikidatum::DataValueType::Base.marshal_load('somevalue', nil)
|
67
|
+
when 'value'
|
68
|
+
datavalue = Wikidatum::DataValueType::Base.marshal_load(snak_json['datavalue']['type'], snak_json['datavalue']['value'])
|
69
|
+
end
|
70
|
+
|
71
|
+
Wikidatum::Snak.new(
|
72
|
+
hash: snak_json['hash'],
|
73
|
+
snaktype: snak_json['snaktype'],
|
74
|
+
property: snak_json['property'],
|
75
|
+
datatype: snak_json['datatype'],
|
76
|
+
datavalue: datavalue
|
77
|
+
)
|
78
|
+
end
|
4
79
|
end
|
data/lib/wikidatum/statement.rb
CHANGED
@@ -1,4 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Wikidatum::Statement
|
4
|
+
# @return [String]
|
5
|
+
attr_reader :id
|
6
|
+
|
7
|
+
# @return [String] property ID, in the format of 'P123'.
|
8
|
+
attr_accessor :property_id
|
9
|
+
|
10
|
+
# @return [Wikidatum::Snak]
|
11
|
+
attr_accessor :mainsnak
|
12
|
+
|
13
|
+
# @return [Array<Wikidatum::Qualifier>]
|
14
|
+
attr_accessor :qualifiers
|
15
|
+
|
16
|
+
# @return [Array<Wikidatum::Reference>]
|
17
|
+
attr_accessor :references
|
18
|
+
|
19
|
+
# @return [String] the rank of the given statement.
|
20
|
+
# Can have the values "preferred", "normal", or "deprecated". Defaults to "normal".
|
21
|
+
attr_accessor :rank
|
22
|
+
|
23
|
+
# @param id [String]
|
24
|
+
# @param property_id [String] The 'P123' ID of the property that this statement represents.
|
25
|
+
# @param mainsnak [Wikidatum::Snak]
|
26
|
+
# @param qualifiers [Array<Wikidatum::Qualifier>]
|
27
|
+
# @param references [Array<Wikidatum::Reference>]
|
28
|
+
# @param rank [String] The rank of the given statement.
|
29
|
+
# Can have the values "preferred", "normal", or "deprecated". Defaults to "normal".
|
30
|
+
def initialize(id:, property_id:, mainsnak:, qualifiers:, references:, rank: 'normal')
|
31
|
+
@id = id
|
32
|
+
@property_id = property_id
|
33
|
+
@mainsnak = mainsnak
|
34
|
+
@qualifiers = qualifiers
|
35
|
+
@references = references
|
36
|
+
@rank = rank
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Hash]
|
40
|
+
def to_h
|
41
|
+
{
|
42
|
+
id: @id,
|
43
|
+
property_id: @property_id,
|
44
|
+
mainsnak: @mainsnak.to_h,
|
45
|
+
qualifiers: @qualifiers.map(&:to_h),
|
46
|
+
references: @references.map(&:to_h),
|
47
|
+
rank: @rank
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
# @!visibility private
|
52
|
+
#
|
53
|
+
# This takes in the JSON blob (as a hash) that is output for a given
|
54
|
+
# statement in the API and turns it into an actual instance of a Statement.
|
55
|
+
#
|
56
|
+
# @param statement_json [Hash]
|
57
|
+
# @return [Wikidatum::Statement]
|
58
|
+
def self.marshal_load(statement_json)
|
59
|
+
mainsnak = Wikidatum::Snak.marshal_load(statement_json['mainsnak'])
|
60
|
+
|
61
|
+
qualifiers = statement_json['qualifiers'].to_a.flat_map do |_qualifier_prop_id, qualifier|
|
62
|
+
qualifier.map { |q| Wikidatum::Qualifier.marshal_load(q) }
|
63
|
+
end
|
64
|
+
references = statement_json['references'].flat_map do |reference|
|
65
|
+
Wikidatum::Reference.marshal_load(reference)
|
66
|
+
end
|
67
|
+
|
68
|
+
Wikidatum::Statement.new(
|
69
|
+
id: statement_json['id'],
|
70
|
+
property_id: mainsnak.property,
|
71
|
+
mainsnak: mainsnak,
|
72
|
+
qualifiers: qualifiers,
|
73
|
+
references: references,
|
74
|
+
rank: statement_json['rank']
|
75
|
+
)
|
76
|
+
end
|
4
77
|
end
|
data/lib/wikidatum/term.rb
CHANGED
@@ -18,4 +18,17 @@ class Wikidatum::Term
|
|
18
18
|
@lang = lang.to_s
|
19
19
|
@value = value
|
20
20
|
end
|
21
|
+
|
22
|
+
# @return [Hash]
|
23
|
+
def to_h
|
24
|
+
{
|
25
|
+
lang: @lang,
|
26
|
+
value: @value
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def inspect
|
32
|
+
"<Wikidatum::Term lang=#{@lang.inspect} value=#{@value.inspect}>"
|
33
|
+
end
|
21
34
|
end
|
data/lib/wikidatum/version.rb
CHANGED
data/lib/wikidatum.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'wikidatum/client'
|
4
|
+
require_relative 'wikidatum/data_value_type'
|
4
5
|
require_relative 'wikidatum/item'
|
5
6
|
require_relative 'wikidatum/qualifier'
|
6
7
|
require_relative 'wikidatum/reference'
|
8
|
+
require_relative 'wikidatum/sitelink'
|
7
9
|
require_relative 'wikidatum/snak'
|
8
10
|
require_relative 'wikidatum/statement'
|
9
11
|
require_relative 'wikidatum/term'
|
@@ -11,4 +13,50 @@ require_relative 'wikidatum/version'
|
|
11
13
|
|
12
14
|
module Wikidatum
|
13
15
|
class Error < StandardError; end
|
16
|
+
|
17
|
+
# rubocop:disable Naming/ConstantName
|
18
|
+
|
19
|
+
# These language codes are not enforced, you can pass whatever language code
|
20
|
+
# you want, even if it's not represented in this list. The purpose of this
|
21
|
+
# is to provide helper constants to allow writing more readable code.
|
22
|
+
#
|
23
|
+
# This will only cover some of the most common language codes, not all of
|
24
|
+
# them.
|
25
|
+
module LanguageCodes
|
26
|
+
Arabic = 'ar'
|
27
|
+
BrazilianPortuguese = 'pt-br'
|
28
|
+
Chinese = 'zh'
|
29
|
+
Dutch = 'nl'
|
30
|
+
English = 'en'
|
31
|
+
EnglishUK = 'en-gb'
|
32
|
+
French = 'fr'
|
33
|
+
German = 'de'
|
34
|
+
Hebrew = 'he'
|
35
|
+
Hindi = 'hi'
|
36
|
+
Italian = 'it'
|
37
|
+
Polish = 'pl'
|
38
|
+
Portuguese = 'pt'
|
39
|
+
Russian = 'ru'
|
40
|
+
SimplifiedChinese = 'zh-hans'
|
41
|
+
Spanish = 'es'
|
42
|
+
TraditionalChinese = 'zh-hant'
|
43
|
+
Turkish = 'tr'
|
44
|
+
Ukrainian = 'uk'
|
45
|
+
# rubocop:enable Naming/ConstantName
|
46
|
+
end
|
47
|
+
|
48
|
+
module DataValueType
|
49
|
+
# rubocop:disable Lint/SymbolConversion
|
50
|
+
DATA_VALUE_TYPES = {
|
51
|
+
'globecoordinate': 'Wikidatum::DataValueType::GlobeCoordinate',
|
52
|
+
'monolingualtext': 'Wikidatum::DataValueType::MonolingualText',
|
53
|
+
'novalue': 'Wikidatum::DataValueType::NoValue',
|
54
|
+
'quantity': 'Wikidatum::DataValueType::Quantity',
|
55
|
+
'somevalue': 'Wikidatum::DataValueType::SomeValue',
|
56
|
+
'string': 'Wikidatum::DataValueType::WikibaseString',
|
57
|
+
'time': 'Wikidatum::DataValueType::Time',
|
58
|
+
'wikibase-entityid': 'Wikidatum::DataValueType::WikibaseEntityId'
|
59
|
+
}.freeze
|
60
|
+
# rubocop:enable Lint/SymbolConversion
|
61
|
+
end
|
14
62
|
end
|
data/wikidatum.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.metadata["homepage_uri"] = "https://github.com/connorshea/wikidatum"
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/connorshea/wikidatum"
|
20
20
|
spec.metadata["changelog_uri"] = "https://github.com/connorshea/wikidatum/blob/main/CHANGELOG.md"
|
21
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
21
22
|
|
22
23
|
# Specify which files should be added to the gem when it is released.
|
23
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -30,8 +31,7 @@ Gem::Specification.new do |spec|
|
|
30
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
32
|
spec.require_paths = ["lib"]
|
32
33
|
|
33
|
-
|
34
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
spec.add_dependency "faraday", "~> 2.4"
|
35
35
|
|
36
36
|
# For more information and examples about making a new gem, check out our
|
37
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikidatum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Shea
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
13
27
|
description: Interact with the Wikidata/Wikibase REST API from Ruby.
|
14
28
|
email:
|
15
29
|
- connor.james.shea+rubygems@gmail.com
|
@@ -27,6 +41,16 @@ files:
|
|
27
41
|
- bin/setup
|
28
42
|
- lib/wikidatum.rb
|
29
43
|
- lib/wikidatum/client.rb
|
44
|
+
- lib/wikidatum/data_value_type.rb
|
45
|
+
- lib/wikidatum/data_value_type/base.rb
|
46
|
+
- lib/wikidatum/data_value_type/globe_coordinate.rb
|
47
|
+
- lib/wikidatum/data_value_type/monolingual_text.rb
|
48
|
+
- lib/wikidatum/data_value_type/no_value.rb
|
49
|
+
- lib/wikidatum/data_value_type/quantity.rb
|
50
|
+
- lib/wikidatum/data_value_type/some_value.rb
|
51
|
+
- lib/wikidatum/data_value_type/time.rb
|
52
|
+
- lib/wikidatum/data_value_type/wikibase_entity_id.rb
|
53
|
+
- lib/wikidatum/data_value_type/wikibase_string.rb
|
30
54
|
- lib/wikidatum/item.rb
|
31
55
|
- lib/wikidatum/qualifier.rb
|
32
56
|
- lib/wikidatum/reference.rb
|
@@ -44,6 +68,7 @@ metadata:
|
|
44
68
|
homepage_uri: https://github.com/connorshea/wikidatum
|
45
69
|
source_code_uri: https://github.com/connorshea/wikidatum
|
46
70
|
changelog_uri: https://github.com/connorshea/wikidatum/blob/main/CHANGELOG.md
|
71
|
+
rubygems_mfa_required: 'true'
|
47
72
|
post_install_message:
|
48
73
|
rdoc_options: []
|
49
74
|
require_paths:
|
@@ -59,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
84
|
- !ruby/object:Gem::Version
|
60
85
|
version: '0'
|
61
86
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.2.33
|
63
88
|
signing_key:
|
64
89
|
specification_version: 4
|
65
90
|
summary: Ruby gem for the new Wikidata REST API.
|