Class ModelBuilder

java.lang.Object
org.eclipse.rdf4j.model.util.ModelBuilder

public class ModelBuilder extends Object
Builder to facilitate easier creation of new RDF Model objects via a fluent interface. All methods returning a ModelBuilder return an immutable reference to the current object, allowing method chaining.

Usage example:

 
    ModelBuilder builder = new ModelBuilder();

    // set some namespaces
    builder.setNamespace("ex", "http://example.org/").setNamespace(FOAF.NS);

    // add a new named graph to the model
    builder.namedGraph("ex:graph1")
               // add statements about resource ex:john
              .subject("ex:john")
                  .add(FOAF.NAME, "John") // add the triple (ex:john, foaf:name "John") to the named graph
                  .add(FOAF.AGE, 42)
                  .add(FOAF.MBOX, "john@example.org");

     // add a triple to the default graph
    builder.defaultGraph().subject("ex:graph1").add(RDF.TYPE, "ex:Graph");

    // return the Model object
    Model m = builder.build();
 
 
Author:
Jeen Broekstra