#!/usr/bin/env ruby

require 'set'
require_relative 'database'
require_relative 'vocabularies'
require_relative 'migrants'

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

output.puts prefixes(:schema, :occupation)
output.puts

seen = Set.new

DB[:person_profession].distinct.select(:profession).where(Sequel.~(profession: nil)).where(Sequel.~(profession: 'Other')).order(:profession).each do |row|
  name = row[:profession].strip
  next if name.empty?
  next unless seen.add?(name.downcase)

  output.puts "occupation:#{toName(name)} a schema:Occupation ;"
  output.puts "  schema:name #{ttl_literal(name)} ."
  output.puts
end

output.close
