Parent

Redland::Serializer

This module provides RDF graph to syntax serialization support via factory classes providing one or more particular target syntaxes.

Public Class Methods

create_finalizer(serializer) click to toggle source

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
new(name='rdfxml',mime_type="application/rdf+xml",uri=nil) click to toggle source

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
ntriples(uri=nil) click to toggle source

Create a NTriples serializer uri - URI of syntax

# File rdf/redland/serializer.rb, line 21
def Serializer.ntriples(uri=nil)
  return Serializer.new('ntriples','text/plain',uri)
end

Public Instance Methods

feature(uri) click to toggle source

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
model_to_string(base_uri, model) click to toggle source

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
setFeature(uri,value) click to toggle source

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_namespace(prefix, uri) click to toggle source

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
to_file(name,model,base_uri=nil) click to toggle source

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

Go to Redland Home - Language Bindings Home - Ruby API Home

(C) Copyright 2004-2013 Dave Beckett, (C) Copyright 2004-2005 University of Bristol