List defined regions.
This commit is contained in:
parent
84d4e16d7b
commit
eba9136962
4 changed files with 95 additions and 24 deletions
46
data/defined_regions.ttl
Normal file
46
data/defined_regions.ttl
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||||
|
@prefix schema: <https://schema.org/> .
|
||||||
|
@prefix wd: <http://www.wikidata.org/entity/> .
|
||||||
|
@prefix region: <https://daniel.degu.cl/data/theater-migrants/regions.ttl#> .
|
||||||
|
|
||||||
|
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 .
|
||||||
15
db_schema/location.txt
Normal file
15
db_schema/location.txt
Normal file
|
|
@ -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 | |
|
||||||
|
+------------+--------------+------+-----+---------+-------+
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require_relative 'database'
|
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
|
# Define the regions
|
||||||
|
|
||||||
|
|
@ -43,33 +50,32 @@ REGIONS = {
|
||||||
|
|
||||||
REGIONS.each do |reg_name, reg_attr|
|
REGIONS.each do |reg_name, reg_attr|
|
||||||
reg_attr[:id] = "region:#{toName(reg_name)}"
|
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
|
end
|
||||||
|
|
||||||
LOCATIONS = []
|
output.puts
|
||||||
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
|
# Print locations
|
||||||
|
|
||||||
LOCATIONS.each do |location|
|
DB[:location].each do |location|
|
||||||
p location
|
id = location[:IDLocation]
|
||||||
puts "#{location[:id]} a tm:Location ."
|
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 <http://sws.geonames.org/#{location[:GeoNamesID]}/>" 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
|
end
|
||||||
|
|
||||||
|
output.close
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ WD = RDF::Vocabulary.new('http://www.wikidata.org/entity/')
|
||||||
WDT = RDF::Vocabulary.new('http://www.wikidata.org/prop/direct/')
|
WDT = RDF::Vocabulary.new('http://www.wikidata.org/prop/direct/')
|
||||||
RDFS = RDF::Vocabulary.new('http://www.w3.org/2000/01/rdf-schema#')
|
RDFS = RDF::Vocabulary.new('http://www.w3.org/2000/01/rdf-schema#')
|
||||||
SCHEMA = RDF::Vocabulary.new('https://schema.org/')
|
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#')
|
XSD = RDF::Vocabulary.new('http://www.w3.org/2001/XMLSchema#')
|
||||||
|
|
||||||
# Internal vocabularies
|
# 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#')
|
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#')
|
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#')
|
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#')
|
RELIGION = RDF::Vocabulary.new('https://daniel.degu.cl/data/theater-migrants/religions.ttl#')
|
||||||
|
|
||||||
# Mapping from symbols to prefixes
|
# Mapping from symbols to prefixes
|
||||||
|
|
@ -24,7 +26,9 @@ PREFIXES = {
|
||||||
tm: TM,
|
tm: TM,
|
||||||
person: PERSON,
|
person: PERSON,
|
||||||
location: LOCATION,
|
location: LOCATION,
|
||||||
|
region: REGION,
|
||||||
religion: RELIGION,
|
religion: RELIGION,
|
||||||
|
skos: SKOS,
|
||||||
xsd: XSD
|
xsd: XSD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue