#!/usr/bin/perl ############## # Owl Converter - converts DAML+OIL ontologies to OWL # (c) 2002, Jennifer Golbeck # v 1.1, released 19 Mar 03 # # Anyone is welcome to use, modify, and distribute this code as # long as this message is left in the script ############## #### The following segment of code uses CGI Lib ### use CGI qw(:standard); $file = ¶m('inFile'); $outFile = ¶m('outFile'); $defaultNs = ¶m('defaultNs'); if ($file eq "") { print "Error: No inFile specified\n"; exit; } if ($outFile eq "") { print "Error: No outFile specified\n"; exit; } ##### End code for CGI Lib Users ##### ### Users without CGI Lib - uncomment these 3 lines ### #$file = "damlFile.daml"; #$outFile = "owlFile.owl"; #$defaultNs = "newDefaultNamespace"; ############################ print "Converting $file to OWL in file $outFile\n\n"; #0 means we're not there yet, 1 means we're in the RDF tag, 2 means we're done with it $inheader=0; #do we need to ignore their defaultNs $ignore=0; #have we added their defaultNs $addedDefaultNs=0; #abbreviation for the daml namespace $damlns=""; $damlEntity=""; $rdfURI = "http://www.w3.org/1999/02/22-rdf-syntax-ns"; $damlURI = "http://www.daml.org/2001/03/daml+oil"; $owlURI = "http://www.w3.org/2002/07/owl"; open (OWL, ">$outFile"); open (FILE, $file); while () { if ($inheader<2) { if (($_ =~ /<.*RDF/) && $inheader==0) { $inheader=1; } if (($_ =~ /<.*!DOCTYPE/) && $inheader==0) { $inheader=.5; } if ($inheader<0.5) { print OWL "$_"; } if ($inheader==0.5) { #find the daml ns if ($_ =~ //){ $damlEntity= "&$1;"; $damlEntity =~ s/ |\t//ig; #print "found entity $damlEntity\n"; $owlEntity = "/) { $inheader=0; } break; } if ($inheader==1) { #print "search $damlEntity\n"; if ($damlEntity ne "" && $_ =~ /xmlns:(.*)=(.*)$damlEntity/){ #print "found ns $1\n"; $damlns= $1; $owlns = "xmlns:owl = \"\&owl\;"; $_ =~ s/xmlns:(.*)=(.*)$damlEntity/$owlns/; } #find the daml ns if ($_ =~ /xmlns:(.*)=(.*)http:\/\/www.daml.org\/2001\/03\/daml\+oil/){ $damlns= $1; $owlns = " xmlns:owl=\"http:\/\/www.w3.org\/2002\/07\/owl"; $_ =~ s/xmlns:(.*)=(.*)http:\/\/www.daml.org\/2001\/03\/daml\+oil/$owlns/; } if ($_ =~ /xmlns=\"http:\/\/www.daml.org\/2001\/03\/daml\+oil/) { $damlns = ""; $owlns = " xmlns=\"http:\/\/www.w3.org\/2002\/07\/owl"; $_ =~ s/xmlns=http:\/\/www.daml.org\/2001\/03\/daml\+oil/$owlns/; if ($defaultNs ne "" || $defaultNs =~ /^\s*$/) { $ignore=1; $addedDefaultNs=1; } } #get rid of any spaces in the daml ns $damlns =~ s/ |\t//ig; #replace defaultNs if we have one if (!($defaultNs =~ /^\s*$/) && $defaultNs ne "" && ignore != 1 && $addedDefaultNs !=1) { if ($_ =~ /xmlns(\s*)=(\s*)\"(\S+)\"/) { $_ =~ s/$3/$defaultNs/; $addedDefaultNs=1; } } if ($_ =~ />/) { $inheader=2; #if we haven't had to replace a default ns so far, but one was given, add it if ($addedDefaultNs == 0 && $defaultNs ne "") { $_ =~ s/>/ xmlns=\"$defaultNs\">/; } } $_ =~ s/www\.daml\.org/www\.mindswap\.org/g; print OWL "$_"; #print "$_"; break; } } else { #done with the header. set up the damlns in case it was the default ns if ($damlns ne "") { $_ =~ s/$damlns:/owl:/g; } if ($damlEntity ne "") { $_ =~ s/$damlEntity/\&owl\;/g; } #print "$_ $damlURI\n"; if ($_ =~ /&owl;#List/) { print "yes"; } $_ =~ s/http:\/\/www.daml.org\/2001\/03\/daml\+oil/http:\/\/www.w3.org\/2002\/07\/owl/g; $_ =~ s/ardinalityQ/ardinality/g; $_ =~ s/hasClassQ/hasClass/g; $_ =~ s/UnambiguousProperty/InverseFunctionalProperty/g; $_ =~ s/UniqueProperty/FunctionalProperty/g; $_ =~ s/hasClass/someValuesFrom/g; $_ =~ s/toClass/allValuesFrom/g; $_ =~ s/owl:Property/rdf:Property/g; $_ =~ s/owl:collection/Collection/g; $_ =~ s/$owlURI#List/$rdfURI#List/g; $_ =~ s/\&owl\;#List/$rdfURI#List/g; $_ =~ s/www\.daml\.org/www\.mindswap\.org/g; print OWL "$_"; #print "$_"; } }