#!/usr/bin/perl -w # # jim2ntriples - Turn a JibberJim MySQL dump into NTriples. # # # # ChangeLog # ========= # Version 0.1 - 2004.03.08: # - First release (morten@mfd-consult.dk). # # Copyright (c) 2004 MFD Consult, Morten Frederiksen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # use strict; # Loop through MySQL statements. while($_=<>) { if($_=~/^insert into rdf3 values \('(.+?)','(.+?)','(.+?)',(\d),\d+\);/i) { my ($s,$p,$o,$t)=($1,$2,$3,$4); # Fix MySQL escapes (double quotes and newlines are left as is). $s=~s/\\'/'/g; $p=~s/\\'/'/g; $o=~s/\\'/'/g; # Fix Unicode etc. $s=~s/&#x([0-9a-f]);/\\u$1/ig; $p=~s/&#x([0-9a-f]);/\\u$1/ig; $o=~s/&#x([0-9a-f]);/\\u$1/ig; $s=~s/\x09/\\u0009/g; $p=~s/\x09/\\u0009/g; $o=~s/\x09/\\u0009/g; # Change to NTriple syntax. $s='<'.$s.'>' if($s!~/^_:/); if($s=~/^_:/) { $s=~s/[_-]//g; $s='_'.$s; } $p='<'.$p.'>'; $o='<'.$o.'>' if($o!~/^_:/ && !$t); $o='"'.$o.'"' if($t); if($o=~/^_:/) { $o=~s/[_-]//g; $o='_'.$o; } print "$s $p $o.\n"; } }