-
Notifications
You must be signed in to change notification settings - Fork 2
Wikibase to Solr #2: item keys
Human Experience Systems LLC edited this page Apr 27, 2023
·
3 revisions
To understand the Wikibase to Solr script, it is useful to first understand the Wikibase JSON structure and how it is interpreted inside Ruby.
Here is a simple program which loads the export.json file into a Ruby variable using the JSON library, and then iterates over each item.
Here we use item.keys
to see what top-level keys are part of each item.
## import Ruby functions
require 'json'
require 'csv'
require 'date'
require 'time'
require 'optparse'
dir = File.dirname __FILE__
importJSONfile = File.expand_path 'export.json', dir
## Load the import JSON file into a Ruby array
data = JSON.load_file importJSONfile
data.each do |item|
p item.keys
end
The output will look like this:
["type", "id", "labels", "descriptions", "aliases", "claims", "sitelinks", "lastrevid"]
["type", "id", "labels", "descriptions", "aliases", "claims", "sitelinks", "lastrevid"]
["type", "id", "labels", "descriptions", "aliases", "claims", "sitelinks", "lastrevid"]
["type", "id", "labels", "descriptions", "aliases", "claims", "sitelinks", "lastrevid"]