#!/usr/bin/env ruby a = ARGV.shift file = File.new(a) # Example input: # PREFIX : # PREFIX u: # CONSTRUCT { [ a :Person; :name ?n; :homepage ?hp; u:bloodtype ?bt ] } # LQRAPS ?n ?hp ?bt # Dan Brickley http://danbri.org/ A+ # etc prefix = {} construct = "" lqraps = {} vars=[] puts file.each do |l| next if l =~ /^#\s+$/ if l =~ /^#\s*LQRAPS\s*(.*)$/ spec = $1 spec.chomp! vars = spec.split(/\t/) puts "# Vars: #{spec}" end if l =~ /^# PREFIX (\w*): <(.*)>$/ prefix[$1]=$2 puts "@prefix #{$1}: <#{$2}> ." end if l =~ /^# CONSTRUCT \{(.*)\}$/ construct = $1 puts "# template is: " + construct end next if l =~ /^#/ && !construct next unless l =~ /\w/ unless l =~ /^#/ puts # debug: puts '# ' + l fields = l.split(/\t/) i=0 row = construct.clone while (i < vars.length) do # puts "Variable #{i} is #{vars[i]} value is: #{fields[i]} " re=vars[i] re.gsub!(/\?/,"") re.chomp! val = fields[i] val.chomp! if val =~ /^http:\// # need a better design val = '<' + val + '>' else val = '"' + val + '"' end row.gsub!(/\?#{re}/, val) i+=1 end puts row + '.' puts end end