Package org.wikidata.wdtk.rdf
Class SnakRdfConverter
java.lang.Object
org.wikidata.wdtk.rdf.SnakRdfConverter
- All Implemented Interfaces:
SnakVisitor<Void>
Class to convert Wikibase snaks to RDF. The main entry point for this class
is
writeSnak(Snak, Resource, PropertyContext)
. Alternatively, one
can use setSnakContext(Resource, PropertyContext)
and use the class
as a visitor. SomeValueSnak
and NoValueSnak
require further
RDF triples to be written; the same is true for some complex data values that
might be used with ValueSnak
. In such cases, the class stores the
values to a buffer. Methods for writing additional triples for these buffered
values can be called later.- Author:
- Markus Kroetzsch
-
Constructor Summary
ConstructorDescriptionSnakRdfConverter
(RdfWriter rdfWriter, OwlDeclarationBuffer owlDeclarationBuffer, PropertyRegister propertyRegister, AnyValueConverter valueRdfConverter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
setSnakContext
(org.eclipse.rdf4j.model.Resource subject, PropertyContext propertyContext) Sets the context in which snaks should be used.visit
(NoValueSnak snak) Visits a NoValueSnak and returns a result.visit
(SomeValueSnak snak) Visits a SomeValueSnak and returns a result.Visits a ValueSnak and returns a result.void
Writes all auxiliary triples that have been buffered recently.void
writeSnak
(Snak snak, org.eclipse.rdf4j.model.Resource subject, PropertyContext propertyContext) Writes the given snak for the given subject.
-
Constructor Details
-
SnakRdfConverter
public SnakRdfConverter(RdfWriter rdfWriter, OwlDeclarationBuffer owlDeclarationBuffer, PropertyRegister propertyRegister, AnyValueConverter valueRdfConverter)
-
-
Method Details
-
writeSnak
public void writeSnak(Snak snak, org.eclipse.rdf4j.model.Resource subject, PropertyContext propertyContext) Writes the given snak for the given subject. The context defines if the snak is used as a main snak, qualifier, or in a reference. Some data might be buffered instead of being written immediately. The methodwriteAuxiliaryTriples()
needs to be called to serialize this additional data later on.- Parameters:
snak
- the snake to writesubject
- the resource that should be used as a subject of the serialied triplespropertyContext
- the context in which the snak is used
-
setSnakContext
public void setSnakContext(org.eclipse.rdf4j.model.Resource subject, PropertyContext propertyContext) Sets the context in which snaks should be used. This is useful when converting many snaks that have the same context. In this case, one can set the context manually and use the converter as aSnakVisitor
.- Parameters:
subject
- the resource that should be used as a subject of the serialied triplespropertyContext
- the context in which the snaks that are to be converted are used
-
visit
Description copied from interface:SnakVisitor
Visits a ValueSnak and returns a result.- Specified by:
visit
in interfaceSnakVisitor<Void>
- Parameters:
snak
- the snak to visit- Returns:
- the result for this snak
-
visit
Description copied from interface:SnakVisitor
Visits a SomeValueSnak and returns a result.- Specified by:
visit
in interfaceSnakVisitor<Void>
- Parameters:
snak
- the snak to visit- Returns:
- the result for this snak
-
visit
Description copied from interface:SnakVisitor
Visits a NoValueSnak and returns a result.- Specified by:
visit
in interfaceSnakVisitor<Void>
- Parameters:
snak
- the snak to visit- Returns:
- the result for this snak
-
writeAuxiliaryTriples
public void writeAuxiliaryTriples() throws org.eclipse.rdf4j.rio.RDFHandlerExceptionWrites all auxiliary triples that have been buffered recently. This includes OWL property restrictions but it also includes any auxiliary triples required by complex values that were used in snaks.- Throws:
org.eclipse.rdf4j.rio.RDFHandlerException
- if there was a problem writing the RDF triples
-