From cd6ea52f070c6dc23e55f6ed2ab4614b81776865 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 14 Feb 2026 15:41:11 +0100 Subject: [PATCH] Inspect locations --- .gitignore | 2 ++ Gemfile | 4 +++ Gemfile.lock | 24 +++++++++++++ src/map_locations.rb | 81 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 src/map_locations.rb diff --git a/.gitignore b/.gitignore index d6aa672..2d11a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ build-iPhoneSimulator/ # Used by RuboCop. Remote config files pulled in from inherit_from directive. # .rubocop-https?--* +# Editors +*~ \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..688dac4 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'sequel' +gem 'mysql2' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f29c834 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,24 @@ +GEM + remote: https://rubygems.org/ + specs: + bigdecimal (4.0.1) + mysql2 (0.5.7) + bigdecimal + sequel (5.101.0) + bigdecimal + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + mysql2 + sequel + +CHECKSUMS + bigdecimal (4.0.1) sha256=8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7 + mysql2 (0.5.7) sha256=ba09ede515a0ae8a7192040a1b778c0fb0f025fa5877e9be895cd325fa5e9d7b + sequel (5.101.0) sha256=d2ae3fd997a7c4572e8357918e777869faf90dc19310fcd6332747122aed2b29 + +BUNDLED WITH + 4.0.3 diff --git a/src/map_locations.rb b/src/map_locations.rb new file mode 100755 index 0000000..9a71b32 --- /dev/null +++ b/src/map_locations.rb @@ -0,0 +1,81 @@ +#!/usr/bin/env ruby + +require 'sequel' + +DB = Sequel.mysql2(host: 'localhost', user: 'migrants', database: 'migrants', password: '1234') + +def toName(name) + name.gsub(' ', '_') +end + +# Define the regions + +REGIONS = { + 'Africa' => { + wikidata: 'wd:Q15' + }, + 'Asia' => { + wikidata: 'wd:Q48' + }, + 'Australia' => { + wikidata: 'wd:Q3960' + }, + 'East Asia' => { + wikidata: 'wd:Q27231', + part_of: 'Asia' + }, + 'Europe' => { + wikidata: 'wd:Q46' + }, + 'Middle East' => { + wikidata: 'wd:Q7204' + }, + 'North Africa' => { + wikidata: 'wd:Q27381', + part_of: 'Africa' + }, + 'North America' => { + wikidata: 'wd:Q49' + }, + 'Oceania' => { + wikidata: 'wd:Q538' + }, + 'South America' => { + wikidata: 'wd:Q18' + } +} + +# Print the regions + +REGIONS.each do |reg_name, reg_attr| + reg_attr[:id] = "region:#{toName(reg_name)}" + puts "#{reg_attr[:id]} a mig:Region ; skos:prefLabel \"#{reg_name}\"@en ." +end + +LOCATIONS = [] +COUNTRIES = {} + +# [[:IDLocation, {primary_key: true, auto_increment: false, generated: false, allow_null: false, comment: nil, default: nil, db_type: "varchar(20)", type: :string, extra: "", ruby_default: nil, max_length: 20}], +# [:Continent, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "varchar(50)", type: :string, extra: "", ruby_default: nil, max_length: 50}], +# [:Country, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "varchar(50)", type: :string, extra: "", ruby_default: nil, max_length: 50}], +# [:State, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "varchar(50)", type: :string, extra: "", ruby_default: nil, max_length: 50}], +# [:City, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "varchar(50)", type: :string, extra: "", ruby_default: nil, max_length: 50}], +# [:latitude, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "float", type: :float, extra: "", ruby_default: nil}], +# [:longitude, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "float", type: :float, extra: "", ruby_default: nil}], +# [:wikipedia, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "text", type: :string, extra: "", ruby_default: nil}], +# [:wikidata, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "text", type: :string, extra: "", ruby_default: nil}], +# [:GeoNamesID, {primary_key: false, generated: false, allow_null: true, comment: nil, default: nil, db_type: "varchar(100)", type: :string, extra: "", ruby_default: nil, max_length: 100}]] + + +DB[:location].limit(10).each do |location| + LOCATIONS << { + id: "location:#{location[:IDLocation]}" + } +end + +# Print locations + +LOCATIONS.each do |location| + p location + puts "#{location[:id]} a mig:Location ." +end