summaryrefslogtreecommitdiff
path: root/_posts/2013-06-05-simplify-rdfwriter-method.md
blob: 6ebe9a33107291d87c0baf12293df76926496438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
layout: post
title: "simplify RDF::Writer method"
description: ""
category: "Development" 
tags: ["RDF"]
---
{% include JB/setup %}

Simplify the RDF::Writer method if you have already an rdf graph like:

    @rdf = RDF::Graph.new
    RDF::Reader.for(format).new(rdf) do |reader|
      reader.each_statement{ |statement| @rdf << statement }
    end

To parse it to another format simpy use:

    RDF::Writer.for(format).buffer(:encoding => Encoding::ASCII) do |writer|
      writer << @rdf
    end

instead of:

    RDF::Writer.for(format).buffer(:encoding => Encoding::ASCII) do |writer|
      @rdf.each{|statement| writer << statement}
    end

and use the base class RDF::Writer instead of subclasses like RDF::Turtle::Writer.
It is much more time-efficient !