From eba9136962689e89a2355b4a3f122e727266f1b5 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Sun, 22 Feb 2026 11:11:11 +0100 Subject: [PATCH] List defined regions. --- data/defined_regions.ttl | 46 ++++++++++++++++++++++++++++++++++ db_schema/location.txt | 15 +++++++++++ src/map_locations.rb | 54 ++++++++++++++++++++++------------------ src/vocabularies.rb | 4 +++ 4 files changed, 95 insertions(+), 24 deletions(-) create mode 100644 data/defined_regions.ttl create mode 100644 db_schema/location.txt diff --git a/data/defined_regions.ttl b/data/defined_regions.ttl new file mode 100644 index 0000000..4bc0595 --- /dev/null +++ b/data/defined_regions.ttl @@ -0,0 +1,46 @@ +@prefix rdfs: . +@prefix schema: . +@prefix wd: . +@prefix region: . + +region:Africa a schema:DefinedRegion ; + rdfs:label "Africa"@en ; + schema:sameAs wd:Q15 . + +region:Asia a schema:DefinedRegion ; + rdfs:label "Asia"@en ; + schema:sameAs wd:Q48 . + +region:Australia a schema:DefinedRegion ; + rdfs:label "Australia"@en ; + schema:sameAs wd:Q3960 . + +region:East_Asia a schema:DefinedRegion ; + rdfs:label "East Asia"@en ; + schema:containedInPlace region:Asia ; + schema:sameAs wd:Q27231 . + +region:Europe a schema:DefinedRegion ; + rdfs:label "Europe"@en ; + schema:sameAs wd:Q46 . + +region:Middle_East a schema:DefinedRegion ; + rdfs:label "Middle East"@en ; + schema:sameAs wd:Q7204 . + +region:North_Africa a schema:DefinedRegion ; + rdfs:label "North Africa"@en ; + schema:containedInPlace region:Africa ; + schema:sameAs wd:Q27381 . + +region:North_America a schema:DefinedRegion ; + rdfs:label "North America"@en ; + schema:sameAs wd:Q49 . + +region:Oceania a schema:DefinedRegion ; + rdfs:label "Oceania"@en ; + schema:sameAs wd:Q538 . + +region:South_America a schema:DefinedRegion ; + rdfs:label "South America"@en ; + schema:sameAs wd:Q18 . diff --git a/db_schema/location.txt b/db_schema/location.txt new file mode 100644 index 0000000..b2bcc80 --- /dev/null +++ b/db_schema/location.txt @@ -0,0 +1,15 @@ +MariaDB [migrants]> show columns from location ; ++------------+--------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++------------+--------------+------+-----+---------+-------+ +| IDLocation | varchar(20) | NO | PRI | NULL | | +| Continent | varchar(50) | YES | | NULL | | +| Country | varchar(50) | YES | | NULL | | +| State | varchar(50) | YES | | NULL | | +| City | varchar(50) | YES | | NULL | | +| latitude | float | YES | | NULL | | +| longitude | float | YES | | NULL | | +| wikipedia | text | YES | | NULL | | +| wikidata | text | YES | | NULL | | +| GeoNamesID | varchar(100) | YES | | NULL | | ++------------+--------------+------+-----+---------+-------+ diff --git a/src/map_locations.rb b/src/map_locations.rb index 6e60149..b6dd1e3 100755 --- a/src/map_locations.rb +++ b/src/map_locations.rb @@ -1,6 +1,13 @@ #!/usr/bin/env ruby require_relative 'database' +require_relative 'vocabularies' +require_relative 'migrants' + +output = File.open(File.join('data', 'locations.ttl'), 'w') + +output.puts prefixes(:wd, :rdfs, :skos, :schema, :tm, :country, :location, :region) +output.puts # Define the regions @@ -43,33 +50,32 @@ REGIONS = { REGIONS.each do |reg_name, reg_attr| reg_attr[:id] = "region:#{toName(reg_name)}" - puts "#{reg_attr[:id]} a tm:Region ; skos:prefLabel \"#{reg_name}\"@en ." + output.puts "#{reg_attr[:id]} a tm: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 +output.puts # Print locations -LOCATIONS.each do |location| - p location - puts "#{location[:id]} a tm:Location ." +DB[:location].each do |location| + id = location[:IDLocation] + props = ["a tm:Location"] + + region = REGIONS[location[:Continent]] + props << "tm:continent #{region[:id]}" if region + props << "tm:country country:#{toName(location[:Country])}" unless location[:Country].to_s.empty? + props << "tm:state #{ttl_literal(location[:State])}" unless location[:State].to_s.empty? + props << "rdfs:label #{ttl_literal(location[:City])}" unless location[:City].to_s.empty? + props << "schema:latitude #{ttl_literal(location[:latitude])}" if location[:latitude] + props << "schema:longitude #{ttl_literal(location[:longitude])}" if location[:longitude] + props << "schema:sameAs <#{location[:wikipedia]}>" unless location[:wikipedia].to_s.empty? + props << "schema:sameAs wd:#{location[:wikidata]}" unless location[:wikidata].to_s.empty? + props << "schema:sameAs " unless location[:GeoNamesID].to_s.empty? + + output.puts "location:#{id} #{props.first} ;" + props[1..-2].each { |p| output.puts " #{p} ;" } + output.puts " #{props.last} ." + output.puts end + +output.close diff --git a/src/vocabularies.rb b/src/vocabularies.rb index a2c8074..d1c3e58 100644 --- a/src/vocabularies.rb +++ b/src/vocabularies.rb @@ -5,6 +5,7 @@ WD = RDF::Vocabulary.new('http://www.wikidata.org/entity/') WDT = RDF::Vocabulary.new('http://www.wikidata.org/prop/direct/') RDFS = RDF::Vocabulary.new('http://www.w3.org/2000/01/rdf-schema#') SCHEMA = RDF::Vocabulary.new('https://schema.org/') +SKOS = RDF::Vocabulary.new('http://www.w3.org/2004/02/skos/core#') XSD = RDF::Vocabulary.new('http://www.w3.org/2001/XMLSchema#') # Internal vocabularies @@ -12,6 +13,7 @@ COUNTRY = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/coun TM = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/mig.ttl#') PERSON = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/persons.ttl#') LOCATION = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/locations.ttl#') +REGION = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/regions.ttl#') RELIGION = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/religions.ttl#') # Mapping from symbols to prefixes @@ -24,7 +26,9 @@ PREFIXES = { tm: TM, person: PERSON, location: LOCATION, + region: REGION, religion: RELIGION, + skos: SKOS, xsd: XSD }