Destination

Destination

The Destination package provides an abstraction over a destination of RDF statements. All classes are located in the namespace org.dbpedia.extraction.destinations.


 

 

1 Overview


The Destination class accepts graphs and writes them to the output. A graph is represented by the Graph class which holds a set of statements, organized in different datasets


2 Available destinations

2.1 FileDestination

A FileDestination writes the supplied statements to files in the file system. A formatter can be provided to specifiy the format of the output. A pattern can be specified to write statements to different files, depending on the dataset.


It accepts three arguments:

  • formatter : Formatter (optional): The formatter used to serialize the statements. If no formatter is provided, the statements are written using the N-Triples format.
  • baseDir : File (optional): The base directory of the output files. If no base directory is provided, the output is written to current directory.
  • filePattern : (Dataset => String) (optional): The pattern according to which the statements are split into different files by their dataset. If no pattern is provided, one file for each dataset is generated. In this case the file names are generated from the name of the corresponding dataset.

2.2 StringDestination

A StringDestination writes the supplied statements to an in-memory string buffer. A formatter can be provided to specifiy the format of the output. After close()has been called, the formatted output can be retrieved by calling toString.


It accepts one argument:

  • formatter : Formatter (optional): The formatter used to serialize the statements. If no formatter is provided, the statements are written using the N-Triples format.

2.3 CompositeDestination

A CompositeDestination can be used to write to different child destinations. It forwards each graph to all child destinations.


It accepts one argument:

  • destinations : Traversable[Destination] : The child destinations.

3 Using a destination

After instantiation, graphs are written to the destination using the write method. All destination classes are thread-safe, thus it is safe to write to them from multiple threads without any further synchronization.
It is important to close a destination after use for two reasons:

  • Statements may be buffered internally and not yet written to the output.
  • Some formatters need to write a footer, which is not written until the destination is closed.

Example

val destination = new FileDestination(new NQuadsFormatter())
destination.write(someGraph)
destination.close()

 

4 Implementing new destinations

A new destination can be implemented by inheriting from Destination and overriding the write(graph : Graph) : Unit method. Optionally, the close() : Unit method can be overriden in order finalize the destination.
Note that each implementation of Destination must be thread-safe.