SemWeb Documentation

rdfstorage.exe Command Line Tool

The rdfstorage.exe program is a command-line tool that is a part of the SemWeb library for reading and writing RDF and loading RDF into persistent storage like a database, or for validating documents. The program gets data from a source in some format and puts the data elsewhere, in another format, as per the command-line options you provide.

Any validation errors and warnings in input files will be reported to the console.

If you run rdfstorage.exe without any command-line options, the possible options are displayed. On Windows, just type rdfstorage.exe. On Linux, or on Windows but using the Mono .NET runtime, type mono rdfstorage.exe. I'll assume you're using Linux in the examples below. The "$" at the start of the line is the command-prompt: no need to type that.

$ mono rdfstorage.exe
RDFStorage - Move RDF Data Between Storage Types

Usage: rdfstorage [options] file1 file2...
Options:
     -baseuri:URI     The default base URI for the input streams.
     -clear           Clear the storage before importing data.
     -in:format       The format for the input files: xml, n3, url to treat the command-line
                      arguments as URLs (format determined automatically), or a specification
                      string used with Store.Create. The default autodetects from the file name.
     -meta:URI        The URI of a resource that expresses meta information.
     -out:storage     The destination storage.  Default is N3 to standard out.
     -outbaseuri:URI  The base URI for the output stream (if supported).
     -stats           Emit status information to STDERR when writing to STDOUT.

There are three types of command-line arguments: input arguments, output options, and general options. The options that take a parameter are optionaly specified with a colon and no space (as indicated in the help output) or separated by a space.

Input Arguments

Reading Files or URLs

The input command-line arguments specify the source of RDF data that will be written or stored elsewhere. Input can come from a file, a web URL, or a database. The default mode is to read from the file names or URLs specified on the command line and detect their format from their file extension or MIME type for URLs. For example:

$ mono rdfstorage.exe file1.rdf file2.rdf
$ mono rdfstorage.exe http://razor.occams.info/foaf.rdf

The first example reads the two RDF/XML files; the second example reads the RDF file from the web. If no output options are specified, the contents of the files are written in Notation 3 format to standard output, which means you will see the contents written to the console. Or, you can redirect the output to a file:

$ mono rdfstorage.exe file1.rdf file2.rdf > output.n3

Output options are explained in the next section.

If you intend only to validate the input files, on Linux you can redirect the output to /dev/null so you don't have to worry about it. If there are any errors or warnings, they will be written to the console (standard error). Also specify -stats to get a count of the number of triples in the document.

$ mono rdfstorage.exe -stats testfile.rdf > /dev/null

When the file arguments are not correctly understood, you can specify the format with the -in FORMAT option, where FORMAT is either xml or n3 (when reading from files) or url (to read from a URL and automatically detect the type). (Turtle and N-Triples are subsets of the Notation 3 format, so you can use the n3 option to read files of this type.) For instance:

$ mono rdfstorage.exe -in xml file1.rdf file2.rdf > output.n3

Reading from Standard Input

You can read in from standard input, to use pipes or redirection on the command line, by using a dash (-) for the file name. In this case, you really need to use -in xml or -in n3 to specify the format. E.g.:

$ mono rdfstorage.exe -in n3 - < input.n3 > output.n3

Setting the Base URI Explicitly

Both RDF/XML and Notation 3 files can resolve relative URIs found in the document against the URI of the document itself. When loading a document from the web, the client knows the URI he is accessing if it is not specified within the file itself. When a file with relative URIs and no explicit base URI set within the file is being loaded from somewhere besides its original location, use the -baseuri URI option to set the base URI explicitly. This option is overridden by any base URI provided explicitly within the file.

$ mono rdfstorage.exe -in n3 -baseuri http://www.example.org/# - < input.n3 > output.n3

Reading from Databases

To read RDF from a database, you set -in spec and then instead of a file name provide a specification string in one of the formats described in Store.CreateForInput(string). For instance:

$ mono rdfstorage.exe -in spec "mysql:sec:Database=rdf;Server=localhost;User Id=rdf"

Output Options

Writing to Files or Standard Output

The default mode of rdfstorage.exe is to write the RDF in Notation 3 format to standard output. Using the -out DESTINATION option the output can be set to a file or standard output in several formats or to a database. DESTINATION is a specification string of the form described in Store.CreateForOutput(string).

You can output to a file or standard out using -out FORMAT:FILENAME. Four file formats are available: xml (RDF/XML), n3 (Notation 3), turtle (Turtle), nt (N-Triples), and dot (GraphViz format). FILENAME is either the name of the file to write (or overwrite), or a dash (-) to write to standard output.

For example, this will convert a file from RDF/XML to Notation 3:

$ mono rdfstorage.exe -out n3:foaf.n3 foaf.rdf

Or if you prefer using shell redirection:

$ mono rdfstorage.exe -out n3:- - < input.rdf > output.n3

And to convert from Notation 3 to RDF/XML, this time giving an explicit input file type:

$ mono rdfstorage.exe -in n3 -out xml:foaf.rdf foaf.n3

When writing RDF/XML, you can set the value of the xml:base attribute using the -outbaseuri URI option:

$ mono rdfstorage.exe -in n3 -out xml:foaf.rdf -outbaseuri http://www.example.org/ foaf.n3

Storing RDF in a Database

To write RDF to a database, you use -out with a specification string in one of the formats described in Store.CreateForOutput(string). For instance, to write to a MySQL database rdf in tables starting with "sec" use:

$ mono rdfstorage.exe -out "mysql:sec:Database=rdf;Server=localhost;User Id=rdf" database.rdf

The format of the specification string is generally the type of database (mysql, sqlserver, etc.), a colon, the name of the tables to use, a colon, and then a database connection string.

To clear the database's contents (that is, dropping the relevant tables given by the specification string), use the -clear option. The database is cleared before any files are read into it.

$ mono rdfstorage.exe -clear -out "mysql:sec:Database=rdf;Server=localhost;User Id=rdf" database.rdf

General Options

rdfstorage.exe will normally print status messages to standard error (i.e. the console). It hides these messages if it thinks it is writing to the console, so that the output does not get mixed up. To write these messages to the console anyway (for instance if you've redirected standard output to a file), give the -stats option.