#:include: ../shared/license.rdoc class NTriple ; end class NTripleFile < NTriple attr_reader :line def line=(_line) @line=_line @about_uri=@predicat_uri=@value_uri=@value_litteral=nil @split=@line.split(" ",3) end def about_uri @about_uri=urialias(@split[0]) if !@about_uri return @about_uri end def predicat_uri @predicat_uri=urialias(@split[1]) if !@predicat_uri return @predicat_uri end def value_uri @value_uri=urialias(@split[2]) if ! @value_uri return @value_uri end def value_litteral @value_litteral=@split[2][1,@split[2].length-5] if !@value_literral return @value_litteral end def valueIsReference? case @split[2][0] when 60 then return true when 34 then return false else raise Warning.new,"Bad ntriple detected" end end COMMENT_SIGNATURE="#"[0] def isComment? return @line[0]==COMMENT_SIGNATURE end def isOntoMDXHeader? return @line.to_s=="#!ontomdx\n" end end module Mrdf_Model def loadMetaModelFromFile(fileName,ignoreHeader=false) @updateCount=@updateCount+1 raise Exception.new("nil fileName passed to loadMetaModelFromFile") if fileName.nil? m=fileName+".rb" #log.debug "m=#{m}" if( File.exists?(m) && File.mtime(m) > File.mtime(fileName) ) log.debug "Using cache in #{m}" require(m) loadModelFromFile(fileName,ignoreHeader) else log.debug "Generating cache in #{m}" loadModelFromFile(fileName,ignoreHeader) self.generateClassesFromMetamodel(m) end end def loadModelFromFile (srcFileName,ignoreHeader=false) fileName=translateToNt(srcFileName) @updateCount=@updateCount+1 #Crdf_Resource.new(self,"xx").initUpdate [false,true].each { |modeData| begin File.open(fileName,"r") { |aFile| parseModelStream(aFile,modeData,ignoreHeader) } rescue Exception => e raise Exception.new(e.message+"ERROR *** current file is: \"#{fileName}\"\nERROR ***\n") end } end def parseModelStream(stream,modeData,ignoreHeader=false) aFile=stream i=0 nt=NTripleFile.new() aFile.each_line { |nt.line| begin i=i+1 if(!ignoreHeader) ignoreHeader=true next if nt.isOntoMDXHeader? p="\nERROR *** " raise Exception.new("#{p}#{p}ontomdx was given a model file without#{p}a valid ontomdx plugin file header.#{p}If you have used a model file created by a modeler plugin,#{p}upgrade your plugin.#{p}Il you have used a plain RDF or RDFS file,#{p}specify ignoreHeader=true when loading model with loadModel.#{p}\n") end next if nt.isComment? parse(nt,modeData) rescue WarningRubyTypeUndefined => z log.error "WARNING ["+(modeData ? "data":"res")+" :nt.line "+i.to_s+", "+z.to_s+", Will create a default type. Possible discrepancies if defined later on. In case of problem, Consider bootstraping]:"+nt.line #log.debug "z.res=#{z.res}" z.res.createRubyClassMinimal(self) i=i-1 retry rescue WarningURIundefined => z log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+z.to_s+",Will create a default entry]:"+nt.line #log.debug "z.uri=#{z.uri}" Crdf_Resource.new(self,z.uri) #parse(nt.line,modeData) i=i-1 retry rescue Warning => w log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+w.to_s+"]:"+nt.line end } end # moved to ontomde-redland-win # WIN_PATH_RAPPER=File.expand_path("#{File.dirname(__FILE__)}/../../dist/redland-1.0.3-Win32/rapper.exe").tr('/','\\\\') PLATFORM_IS_UNIX=!(RUBY_PLATFORM.index("inux").nil?) def rapperRun(param) if PLATFORM_IS_UNIX cmd="rapper "+param else cmd='"'+WIN_PATH_RAPPER+'"'+param end return if system(cmd) raise Exception.new("\n***\n***Error running command\n***\n***#{cmd}\n***\n") end def translateToNt(srcFileName) return srcFileName if ! (srcFileName=~/.rdfs*$/ ) fileName="#{srcFileName}.cache.deleteMe.nt" if( File.exists?(fileName) && File.mtime(fileName) > File.mtime(srcFileName) ) log.debug "INFO:Using cache in #{fileName}" else raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ") if PLATFORM_IS_UNIX param=' -q -o ntriples -i rdfxml '+srcFileName+' > '+fileName else param=' -q -o ntriples -i rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+'' end rapperRun(param) end return fileName end def translateToXML(srcFileName,fileName) raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ") || srcFileName.include?(" ") if PLATFORM_IS_UNIX param=' -q -i ntriples -o rdfxml '+srcFileName+' > '+fileName+'' else param=' -q -i ntriples -o rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+'' end rapperRun(param) return fileName end end