Class SnakRdfConverter

java.lang.Object
org.wikidata.wdtk.rdf.SnakRdfConverter
All Implemented Interfaces:
SnakVisitor<Void>

public class SnakRdfConverter extends Object implements 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 Details

  • 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 method writeAuxiliaryTriples() needs to be called to serialize this additional data later on.
      Parameters:
      snak - the snake to write
      subject - the resource that should be used as a subject of the serialied triples
      propertyContext - 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 a SnakVisitor.
      Parameters:
      subject - the resource that should be used as a subject of the serialied triples
      propertyContext - the context in which the snaks that are to be converted are used
    • visit

      public Void visit(ValueSnak snak)
      Description copied from interface: SnakVisitor
      Visits a ValueSnak and returns a result.
      Specified by:
      visit in interface SnakVisitor<Void>
      Parameters:
      snak - the snak to visit
      Returns:
      the result for this snak
    • visit

      public Void visit(SomeValueSnak snak)
      Description copied from interface: SnakVisitor
      Visits a SomeValueSnak and returns a result.
      Specified by:
      visit in interface SnakVisitor<Void>
      Parameters:
      snak - the snak to visit
      Returns:
      the result for this snak
    • visit

      public Void visit(NoValueSnak snak)
      Description copied from interface: SnakVisitor
      Visits a NoValueSnak and returns a result.
      Specified by:
      visit in interface SnakVisitor<Void>
      Parameters:
      snak - the snak to visit
      Returns:
      the result for this snak
    • writeAuxiliaryTriples

      public void writeAuxiliaryTriples() throws org.eclipse.rdf4j.rio.RDFHandlerException
      Writes 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