diff options
author | Christoph Helma <helma@in-silico.ch> | 2010-09-08 15:49:07 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2010-09-08 15:49:07 +0200 |
commit | ea33651026aeb6868e7c675304a08eccd7b5e695 (patch) | |
tree | 314ff51e94464c0cf6440da81cd772781bc685e9 /lib | |
parent | da9582a7d176358cf4240972a423a011cbaac132 (diff) |
initial attempts to switch to rdfxml
Diffstat (limited to 'lib')
-rw-r--r-- | lib/owl.rb | 55 |
1 files changed, 36 insertions, 19 deletions
@@ -1,4 +1,7 @@ require 'open3' +require 'rdf' +require 'rdf/raptor' +include RDF # RDF namespaces RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#' @@ -193,8 +196,9 @@ module OpenTox private def initialize + @triples = [] @model = Redland::Model.new Redland::MemoryStore.new - @triples = "" + #@triples = "" end # build new owl object @@ -261,8 +265,15 @@ module OpenTox #stdin, stdout, stderr = Open3.popen3('rapper -I test.org -i ntriples -o rdfxml -') #stdin.puts @triples #stdout - File.open("/tmp/d","w+") {|f| f.puts @triples} - `rapper -i ntriples -o rdfxml /tmp/d` + #File.open("/tmp/d","w+") {|f| f.puts @triples} + #`rapper -i ntriples -o rdfxml /tmp/d` + #@triples + output = RDF::Writer.for(:rdfxml).buffer do |writer| + #@triples.each do |statement| + #writer << statement + #end + end + #output end # returns the first object for subject:root_node and property @@ -343,10 +354,10 @@ module OpenTox # ot:Model,rdf:type,owl:Class def set_type(ot_class, current_node=@root_node) #@triples += "#{ot_class.to_s} #{RDF_TYPE.to_s} #{current_node.to_s}" - @triples << "#{current_node} #{RDF_TYPE} #{node(ot_class).to_s}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - @triples << "#{node(ot_class).to_s} #{RDF_TYPE} #{OWL_TYPE_CLASS}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - #@model.add current_node, RDF_TYPE, node(ot_class) - #@model.add node(ot_class), RDF_TYPE, OWL_TYPE_CLASS + #@triples << "#{current_node} #{RDF_TYPE} #{node(ot_class).to_s}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + #@triples << "#{node(ot_class).to_s} #{RDF_TYPE} #{OWL_TYPE_CLASS}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + add current_node, RDF_TYPE, node(ot_class) + add node(ot_class), RDF_TYPE, OWL_TYPE_CLASS end # example-triples for setting description of a model: @@ -355,10 +366,10 @@ module OpenTox def set_literal(literal_name, literal_value, literal_datatype, current_node=@root_node) #@triples += "#{current_node} #{node(literal_name)} #{Redland::Literal.create(literal_value, literal_datatype)}.\n".gsub(/\[/,'<').gsub(/\]/,'>') #TODO: add datatype - @triples << "#{current_node} #{node(literal_name)} \"#{literal_value}\".\n".gsub(/\[/,'<').gsub(/\]/,'>') - @triples << "#{node(literal_name)} #{RDF_TYPE} #{OWL_TYPE_LITERAL}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - #@model.add current_node, node(literal_name), Redland::Literal.create(literal_value, literal_datatype) - #@model.add node(literal_name), RDF_TYPE, OWL_TYPE_LITERAL + #@triples << "#{current_node} #{node(literal_name)} \"#{literal_value}\".\n".gsub(/\[/,'<').gsub(/\]/,'>') + #@triples << "#{node(literal_name)} #{RDF_TYPE} #{OWL_TYPE_LITERAL}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + add current_node, node(literal_name), Redland::Literal.create(literal_value, literal_datatype) + add node(literal_name), RDF_TYPE, OWL_TYPE_LITERAL end # example-triples for setting algorithm property of a model: @@ -368,14 +379,20 @@ module OpenTox # ot:Algorithm,rdf:type,owl:Class def set_object_property(property, object, object_class, current_node=@root_node) object_node = Redland::Resource.new(object) - @triples << "#{current_node} #{node(property)} #{object_node}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - @triples << "#{node(property)} #{RDF_TYPE} #{OWL_TYPE_OBJECT_PROPERTY}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - @triples << "#{object_node} #{RDF_TYPE} #{node(object_class)}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - @triples << "#{node(object_class)} #{RDF_TYPE} #{OWL_TYPE_CLASS}.\n".gsub(/\[/,'<').gsub(/\]/,'>') - #@model.add current_node, node(property), object_node - #@model.add node(property), RDF_TYPE, OWL_TYPE_OBJECT_PROPERTY - #@model.add object_node, RDF_TYPE, node(object_class) - #@model.add node(object_class), RDF_TYPE, OWL_TYPE_CLASS + #@triples << "#{current_node} #{node(property)} #{object_node}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + #@triples << "#{node(property)} #{RDF_TYPE} #{OWL_TYPE_OBJECT_PROPERTY}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + #@triples << "#{object_node} #{RDF_TYPE} #{node(object_class)}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + #@triples << "#{node(object_class)} #{RDF_TYPE} #{OWL_TYPE_CLASS}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + add current_node, node(property), object_node + add node(property), RDF_TYPE, OWL_TYPE_OBJECT_PROPERTY + add object_node, RDF_TYPE, node(object_class) + add node(object_class), RDF_TYPE, OWL_TYPE_CLASS + end + + def add(s,p,o) + #@triples << "#{s} #{p} #{o}.\n".gsub(/\[/,'<').gsub(/\]/,'>') + @triples << [s,p,o] + #@model.add s,p,o end # this is (a recursiv method) to set nested-data via hashes (not only simple properties) |