Object
This module provides RDF graph to syntax serialization support via factory classes providing one or more particular target syntaxes.
You shouldn't use this. Used internally for cleanup.
# File rdf/redland/serializer.rb, line 26 def Serializer.create_finalizer(serializer) proc {|id| # "Finalizer on #{id}" #log_final.info "closing serializer" Redland::librdf_free_serializer(serializer) } end
Constructor - create a new Serializer object name - the serializer factory name mime_type - the MIME type of the syntax uri - URI of syntax
# File rdf/redland/serializer.rb, line 12 def initialize(name='rdfxml',mime_type="application/rdf+xml",uri=nil) uri = uri.uri if uri @serializer = Redland.librdf_new_serializer($world.world,name,mime_type,uri) raise RedlandError.new("Serializer construction failed") if !@serializer ObjectSpace.define_finalizer(self,Serializer.create_finalizer(@serializer)) end
Get a parser feature. The feature is named via RDF::Redland::URI I<URI>
# File rdf/redland/serializer.rb, line 46 def feature(uri) uri = Uri.new(uri) unless uri.class == Uri value = Redland::librdf_serializer_get_feature(@serializer,uri.uri) if value == "NULL" or value==nil return nil else return Node.new(:from_object=>value) end end
Serialize the RDF graph in model to a string
# File rdf/redland/serializer.rb, line 71 def model_to_string(base_uri, model) if base_uri base_uri = base_uri.uri end return Redland.librdf_serializer_serialize_model_to_string(@serializer, base_uri, model.model) end
Set a serializer feature. The feature is named via RDF::Redland::URI I<URI> and the value is a RDF::Redland::Node.
# File rdf/redland/serializer.rb, line 58 def setFeature(uri,value) uri = Uri.new(uri) unless uri.class == Uri if value.class == String then value = Node.new(:literal=>value) end return (Redland::librdf_serializer_set_feature(@serializer,uri.uri,value.node) == 0) end
Set a serializer namepace to the desired prefix
# File rdf/redland/serializer.rb, line 65 def set_namespace(prefix, uri) uri = Uri.new(uri) unless uri.class == Uri return (Redland::librdf_serializer_set_namespace(@serializer,uri.uri,prefix) == 0) end
Serializes a model and stores it in a file name - the serializer factory name mime_type - the MIME type of the syntax base_uri - URI of syntax
# File rdf/redland/serializer.rb, line 37 def to_file(name,model,base_uri=nil) if base_uri base_uri = base_uri.uri end return Redland.librdf_serializer_serialize_model_to_file(@serializer,name,base_uri,model.model) end
(C) Copyright 2004-2013 Dave Beckett, (C) Copyright 2004-2005 University of Bristol