#!/usr/bin/env ruby

require_relative 'database'
require_relative 'vocabularies'
require_relative 'migrants'

output = File.open(File.join('data', 'persons_occupations.ttl'), 'w')

output.puts prefixes(:rdfs, :tm, :schema, :person, :personOccupation, :occupation)
output.puts

DB[:person_profession].each do |row|
  puts "mapping persons occupations #{row[:IDProfPerson]}"
  id = row[:IDProfPerson]
  props = ["a tm:PersonOccupation"]

  props << "tm:person person:#{row[:IDPerson]}"                       unless row[:IDPerson].to_s.empty?
  props << "schema:occupation occupation:#{toName(row[:profession])}" unless row[:profession].to_s.empty?
  props << "tm:standardProfession #{ttl_literal(row[:Eprofession])}"  unless row[:Eprofession].to_s.empty?

  output.puts "personOccupation:#{id} #{props.first} ;"
  props[1..-2].each { |p| output.puts "  #{p} ;" }
  output.puts "  #{props.last} ."
  output.puts
end

output.close
