Class RDFParser

java.lang.Object
org.apache.jena.riot.RDFParser

public class RDFParser extends Object
An RDFParser is a process that will generate triples and quads; RDFParserBuilder provides the means to create parsers.

An RDFParser has a predefined source; the target for output is given when the "parse" step is called. It can be used multiple times in which case the same source is reread. The destination can vary. The application is responsible for concurrency of the destination of the parse operation.

Parser output is sent to a StreamRDF. The general process is

    StreamRDF destination = ...
    RDFParser parser = RDFParser.create().source("filename.ttl").build();
    parser.parse(destination);
 
There are various convenience forms to perform common tasks such as to parse a file and create a Model:
    Model model = RDFParser.source("filename.ttl").toModel();
 
See Also:
  • Method Details

    • create

      public static RDFParserBuilder create()
      Create an RDFParserBuilder.

      Often used in a pattern such as:

          RDFParser.create()
              .source("data.ttl")
              .parse(graph);
       
    • source

      public static RDFParserBuilder source(Path path)
      Create an RDFParserBuilder and set the source to the Path.

      This is a shortcut for RDFParser.create().source(path).

      Parameters:
      path -
      Returns:
      RDFParserBuilder
    • source

      public static RDFParserBuilder source(String uriOrFile)
      Create an RDFParserBuilder and set the source to the URI, which can be a filename.

      This is a shortcut for RDFParser.create().source(uriOrFile).

      Parameters:
      uriOrFile -
      Returns:
      RDFParserBuilder
    • fromString

      @Deprecated public static RDFParserBuilder fromString(String string)
      Deprecated.
      Create an RDFParserBuilder and set content to be parsed to the string. The syntax must be set with .lang(...).

      Shortcut for RDFParser.create.fromString(string).

      Parameters:
      string -
      Returns:
      RDFParserBuilder
    • fromString

      public static RDFParserBuilder fromString(String string, Lang lang)
      Create an RDFParserBuilder and set content to be parsed together with the RDF syntax language.

      Shortcut for RDFParser.create.fromString(string).lang(lang).

      Parameters:
      string -
      lang -
      Returns:
      RDFParserBuilder
    • source

      public static RDFParserBuilder source(InputStream input)
      Create an RDFParserBuilder and set the source to InputStream. The InputStream will be closed when the parser is called and the parser can not be reused. The syntax must be set with .lang(...).

      This is a shortcut for RDFParser.create().source(input).

      Parameters:
      input -
      Returns:
      RDFParserBuilder
    • parse

      public void parse(org.apache.jena.graph.Graph graph)
      Parse the source, sending the results to a Graph.

      The source must be for triples; any quads are discarded.

    • parse

      public void parse(org.apache.jena.rdf.model.Model model)
      Parse the source, sending the results to a Model.

      The source must be for triples; any quads are discarded.

      This method is equivalent to parse(model.getGraph()).

    • parse

      public void parse(DatasetGraph dataset)
      Parse the source, sending the results to a DatasetGraph.
    • parse

      public void parse(Dataset dataset)
      Parse the source, sending the results to a Dataset. This method is equivalent to parse(dataset.asDatasetGraph()).
    • toGraph

      public org.apache.jena.graph.Graph toGraph()
      Parse the source in to a fresh Graph and return the graph.

      The source must be for triples; any quads are discarded.

    • toModel

      public org.apache.jena.rdf.model.Model toModel()
      Parse the source in to a fresh Model and return the model.

      The source must be for triples; any quads are discarded.

    • toDataset

      public Dataset toDataset()
      Parse the source in to a fresh Dataset and return the dataset.
    • toDatasetGraph

      public DatasetGraph toDatasetGraph()
      Parse the source in to a fresh DatasetGraph and return the DatasetGraph.
    • parse

      public void parse(StreamRDF destination)
      Parse the source, sending the results to a StreamRDF.