require 'sequel'
require 'sparql/client'
require 'rdf'

# Database connectors

DB = Sequel.mysql2(host: 'localhost', user: 'migrants', database: 'migrants', password: '1234')

WIKIDATA = SPARQL::Client.new('https://query.wikidata.org/sparql')

# Vocabularies
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#')


# Common functions

def toName(name)
  name.gsub(/[^a-zA-Z0-9_-]/, '_').gsub(/_+/, '_').gsub(/\A_+|_+\z/, '')
end

def get_wd_name(uri)
  uri.to_s.gsub('http://www.wikidata.org/entity/', 'wd:')
end

def get_geo_name(id)
  "geo:#{id}"
end

