Importing RDFΒΆ

TMAPIX I/O is able to import several RDF syntaxes using the RDF to Topic Maps (RTM) mapping vocabulary.

The actual mapping may either be defined within the RDF file which should be deserialized or, more commonly, by an external RDF source. Each RDFTopicMapReader provides several setMappingSource methods to specify the source to read the acutal mapping from. If no external mapping source was defined, the reader assumes that the mapping is part of the main RDF source.

The RDF readers can be used like the TopicMapReader interface but they implement additionally the RDFTopicMapReader interface to support a source to read the RTM mapping from. The following table gives an overview about the provided RDF readers and their associated RDF syntax.

RDFTopicMapReader RDF Syntax
N3TopicMapReader N3
NTriplesTopicMapReader N-Triples
RDFXMLTopicMapReader RDF/XML
TrigTopicMapReader TriG
TrixTopicMapReader TriX
TurtleTopicMapReader Turtle

The following example assumes that the mapping is defined within the main RDF source rdfSource:

import org.tmapix.io.TopicMapReader;
import org.tmapix.io.N3TopicMapReader;

File rdfSource = new File("./example.n3");

// It is assumed that a org.tmapi.core.TopicMap is given
TopicMapReader reader = new N3TopicMapReader(tm, rdfSource);
reader.read();

Usually the mapping source is different from the main RDF source. If an external mapping should be defined, one of the setMappingSource methods can be used:

import org.tmapix.io.RDFTopicMapReader;
import org.tmapix.io.N3TopicMapReader;

File rdfSource = new File("./example.n3");

// Note: The RDFTopicMapReader interface is used since the
// TopicMapReader interface does not provide a setMappingSource method
RDFTopicMapReader reader = new N3TopicMapReader(tm, rdfSource);
reader.setMappingSource("./the-mapping.n3");
reader.read();

The mapping source may use a different syntax than the main RDF source. All RDFTopicMapReader implementations try to detect the mapping source syntax by the file extension. If the syntax cannot be detected, RDF/XML is assumed.

The following example reads a RDF source using RDF/XML and utilises a mapping encoded in N-Triples:

import org.tmapix.io.RDFTopicMapReader;
import org.tmapix.io.RDFXMLTopicMapReader;

File rdfSource = new File("./example.rdf");

RDFTopicMapReader reader = new RDFXMLTopicMapReader(tm, rdfSource);
reader.setMappingSource("./the-mapping.nt");
reader.read();

It is also possible to specify the syntax of the mapping source explicitely:

import org.tmapix.io.RDFTopicMapReader;
import org.tmapix.io.RDFXMLTopicMapReader;
import static org.tinytim.mio.RDFTopicMapReader.MappingSyntax;

File rdfSource = new File("./example.rdf");

RDFTopicMapReader reader = new RDFXMLTopicMapReader(tm, rdfSource);
reader.setMappingSource("./the-mapping.nt");
reader.setMappingSourceSyntax(MappingSyntax.NTRIPLES);
reader.read();