Module: Wikimelon
- Extended by:
- Configuration
- Defined in:
- lib/wikimelon.rb,
lib/wikimelon/item.rb,
lib/wikimelon/error.rb,
lib/wikimelon/request.rb,
lib/wikimelon/version.rb,
lib/wikimelon/property.rb,
lib/wikimelon/resource.rb,
lib/wikimelon/throttle.rb,
lib/wikimelon/reference.rb,
lib/wikimelon/statement.rb,
lib/wikimelon/search_result.rb
Defined Under Namespace
Modules: Throttle Classes: BadGateway, BadRequest, Error, GatewayTimeout, InternalServerError, Item, NotFound, Property, Reference, Request, Resource, SearchResult, ServiceUnavailable, Statement
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.entities(ids, verbose: false) ⇒ Hash
Fetch multiple Wikidata entities in a single request via wbgetentities.
-
.entity(entity_id, revision_id: nil, verbose: false) ⇒ Array, Boolean
Get Wikidata entity data.
-
.exists?(entity_id, verbose: false) ⇒ Boolean
Check whether a Wikidata entity exists at the exact ID requested.
-
.query(query, verbose: false) ⇒ Array, Boolean
Run a Wikidata SPARQL query.
-
.search(query, type: 'item', language: nil, limit: 10, verbose: false) ⇒ Object
Fuzzy-search Wikidata for an item, property, or other entity type via wbsearchentities.
Methods included from Configuration
Class Method Details
.entities(ids, verbose: false) ⇒ Hash
Fetch multiple Wikidata entities in a single request via wbgetentities. Up to 50 IDs per call (the API hard limit). Use Item.find_many or Property.find_many for the wrapped-object form.
75 76 77 78 79 80 81 |
# File 'lib/wikimelon.rb', line 75 def self.entities(ids, verbose: false) Request.new( url: "#{api_url}/w/api.php", params: { action: 'wbgetentities', ids: ids.join('|'), format: 'json' }, verbose: verbose ).perform end |
.entity(entity_id, revision_id: nil, verbose: false) ⇒ Array, Boolean
Get Wikidata entity data
44 45 46 47 48 49 50 51 |
# File 'lib/wikimelon.rb', line 44 def self.entity(entity_id, revision_id: nil, verbose: false) url = "#{api_url}/wiki/Special:EntityData/#{entity_id}.json" url = "#{url}?revision=#{revision_id}" unless revision_id.nil? Request.new( url: url, verbose: verbose ).perform end |
.exists?(entity_id, verbose: false) ⇒ Boolean
Check whether a Wikidata entity exists at the exact ID requested. Returns false for missing IDs and for IDs that have been merged or redirected (the API returns the target entity, whose id differs from the requested string).
62 63 64 65 66 67 |
# File 'lib/wikimelon.rb', line 62 def self.exists?(entity_id, verbose: false) res = entity(entity_id, verbose: verbose) res.dig('entities', entity_id, 'id') == entity_id rescue Wikimelon::NotFound false end |
.query(query, verbose: false) ⇒ Array, Boolean
Run a Wikidata SPARQL query
27 28 29 30 31 32 33 |
# File 'lib/wikimelon.rb', line 27 def self.query(query, verbose: false) Request.new( url: sparql_url, query: query, verbose: verbose ).perform end |
.search(query, type: 'item', language: nil, limit: 10, verbose: false) ⇒ Object
Fuzzy-search Wikidata for an item, property, or other entity type via wbsearchentities. Returns the raw response hash; use Item.search / Property.search for the wrapped form.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/wikimelon.rb', line 91 def self.search(query, type: 'item', language: nil, limit: 10, verbose: false) Request.new( url: "#{api_url}/w/api.php", params: { action: 'wbsearchentities', search: query, language: language || default_language, type: type, limit: limit, format: 'json' }, verbose: verbose ).perform end |