Minor refactoring

This commit is contained in:
Daniel Hernandez 2026-02-22 10:44:02 +01:00
parent 6bf5b40990
commit 84d4e16d7b
3 changed files with 63 additions and 63 deletions

View file

@ -1,63 +0,0 @@
#!/usr/bin/env ruby
require_relative 'database'
require_relative 'vocabularies'
require_relative 'migrants'
output = File.open(File.join('data', '002-persons.ttl'), 'w')
output.puts prefixes(:wd, :rdfs, :mig, :schema, :person, :location, :xsd)
output.puts
DB[:person].each do |row|
id = row[:IDPerson]
props = ["a schema:Person"]
props << "schema:givenName #{ttl_literal(row[:first_name])}" unless row[:first_name].to_s.empty?
props << "schema:familyName #{ttl_literal(row[:family_name])}" unless row[:family_name].to_s.empty?
props << "tm:religion #{ttl_literal(row[:religion])}" unless row[:religion].to_s.empty?
props << "tm:nameType #{ttl_literal(row[:Nametype])}" unless row[:Nametype].to_s.empty?
case row[:gender]
when 'male' then props << "schema:gender schema:Male"
when 'female' then props << "schema:gender schema:Female"
end
props << "schema:image <#{row[:imageURL]}>" unless row[:imageURL].to_s.empty?
props << "tm:imageSource #{ttl_literal(row[:image_source])}" unless row[:image_source].to_s.empty?
props << "schema:hasOccupation #{ttl_literal(row[:profession])}" unless row[:profession].to_s.empty?
props << "tm:fuzzyBirthDate #{ttl_literal(row[:fuzzybirthdate])}" unless row[:fuzzybirthdate].to_s.empty?
props << "schema:birthDate #{ttl_literal(row[:birthdate])}" if row[:birthdate]
props << "tm:birthDateMax #{ttl_literal(row[:birthdate_max])}" if row[:birthdate_max]
props << "tm:birthInfo #{ttl_literal(row[:'Birth Info'])}" unless row[:'Birth Info'].to_s.empty?
props << "schema:birthPlace location:#{row[:IDBirthPlace]}" unless row[:IDBirthPlace].to_s.empty?
props << "tm:fuzzyDeathDate #{ttl_literal(row[:fuzzydeathdate])}" unless row[:fuzzydeathdate].to_s.empty?
props << "schema:deathDate #{ttl_literal(row[:deathdate])}" if row[:deathdate]
props << "tm:deathDateMax #{ttl_literal(row[:deathdate_max])}" if row[:deathdate_max]
props << "tm:deathInfo #{ttl_literal(row[:'Death Info'])}" unless row[:'Death Info'].to_s.empty?
props << "schema:deathPlace location:#{row[:IDDeathPlace]}" unless row[:IDDeathPlace].to_s.empty?
props << "schema:sameAs <#{row[:Wikipedia]}>" unless row[:Wikipedia].to_s.empty?
props << "schema:sameAs wd:#{row[:Wikidata]}" unless row[:Wikidata].to_s.empty?
props << "tm:gnd #{ttl_literal(row[:GND])}" unless row[:GND].to_s.empty?
props << "tm:lccn #{ttl_literal(row[:LCCN])}" unless row[:LCCN].to_s.empty?
props << "tm:viaf #{ttl_literal(row[:VIAF])}" unless row[:VIAF].to_s.empty?
props << "tm:cerl #{ttl_literal(row[:CERL])}" unless row[:CERL].to_s.empty?
props << "tm:isni #{ttl_literal(row[:ISNI])}" unless row[:ISNI].to_s.empty?
props << "tm:snac #{ttl_literal(row[:SNAC])}" unless row[:SNAC].to_s.empty?
props << "rdfs:comment #{ttl_literal(row[:comment])}" unless row[:comment].to_s.empty?
props << "tm:source #{ttl_literal(row[:Source])}" unless row[:Source].to_s.empty?
props << "tm:importSource #{ttl_literal(row[:Importsource])}" unless row[:Importsource].to_s.empty?
output.puts "person:#{id} #{props.first} ;"
props[1..-2].each { |p| output.puts " #{p} ;" }
output.puts " #{props.last} ."
output.puts
end
output.close

63
src/map_persons.rb Normal file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env ruby
require_relative 'database'
require_relative 'vocabularies'
require_relative 'migrants'
output = File.open(File.join('data', '002-persons.ttl'), 'w')
output.puts prefixes(:wd, :rdfs, :tm, :schema, :person, :location, :xsd)
output.puts
DB[:person].each do |row|
id = row[:IDPerson]
props = ["a schema:Person"]
props << "schema:givenName #{ttl_literal(row[:first_name])}" unless row[:first_name].to_s.empty?
props << "schema:familyName #{ttl_literal(row[:family_name])}" unless row[:family_name].to_s.empty?
props << "tm:religion #{ttl_literal(row[:religion])}" unless row[:religion].to_s.empty?
props << "tm:nameType #{ttl_literal(row[:Nametype])}" unless row[:Nametype].to_s.empty?
case row[:gender]
when 'male' then props << "schema:gender schema:Male"
when 'female' then props << "schema:gender schema:Female"
end
props << "schema:image <#{row[:imageURL]}>" unless row[:imageURL].to_s.empty?
props << "tm:imageSource #{ttl_literal(row[:image_source])}" unless row[:image_source].to_s.empty?
props << "schema:hasOccupation #{ttl_literal(row[:profession])}" unless row[:profession].to_s.empty?
props << "tm:fuzzyBirthDate #{ttl_literal(row[:fuzzybirthdate])}" unless row[:fuzzybirthdate].to_s.empty?
props << "schema:birthDate #{ttl_literal(row[:birthdate])}" if row[:birthdate]
props << "tm:birthDateMax #{ttl_literal(row[:birthdate_max])}" if row[:birthdate_max]
props << "tm:birthInfo #{ttl_literal(row[:'Birth Info'])}" unless row[:'Birth Info'].to_s.empty?
props << "schema:birthPlace location:#{row[:IDBirthPlace]}" unless row[:IDBirthPlace].to_s.empty?
props << "tm:fuzzyDeathDate #{ttl_literal(row[:fuzzydeathdate])}" unless row[:fuzzydeathdate].to_s.empty?
props << "schema:deathDate #{ttl_literal(row[:deathdate])}" if row[:deathdate]
props << "tm:deathDateMax #{ttl_literal(row[:deathdate_max])}" if row[:deathdate_max]
props << "tm:deathInfo #{ttl_literal(row[:'Death Info'])}" unless row[:'Death Info'].to_s.empty?
props << "schema:deathPlace location:#{row[:IDDeathPlace]}" unless row[:IDDeathPlace].to_s.empty?
props << "schema:sameAs <#{row[:Wikipedia]}>" unless row[:Wikipedia].to_s.empty?
props << "schema:sameAs wd:#{row[:Wikidata]}" unless row[:Wikidata].to_s.empty?
props << "tm:gnd #{ttl_literal(row[:GND])}" unless row[:GND].to_s.empty?
props << "tm:lccn #{ttl_literal(row[:LCCN])}" unless row[:LCCN].to_s.empty?
props << "tm:viaf #{ttl_literal(row[:VIAF])}" unless row[:VIAF].to_s.empty?
props << "tm:cerl #{ttl_literal(row[:CERL])}" unless row[:CERL].to_s.empty?
props << "tm:isni #{ttl_literal(row[:ISNI])}" unless row[:ISNI].to_s.empty?
props << "tm:snac #{ttl_literal(row[:SNAC])}" unless row[:SNAC].to_s.empty?
props << "rdfs:comment #{ttl_literal(row[:comment])}" unless row[:comment].to_s.empty?
props << "tm:source #{ttl_literal(row[:Source])}" unless row[:Source].to_s.empty?
props << "tm:importSource #{ttl_literal(row[:Importsource])}" unless row[:Importsource].to_s.empty?
output.puts "person:#{id} #{props.first} ;"
props[1..-2].each { |p| output.puts " #{p} ;" }
output.puts " #{props.last} ."
output.puts
end
output.close