Class RDFParser


  • public class RDFParser
    extends java.lang.Object
    An RDFParser is a process that will generate triples; RDFParserBuilder provides the means to setup the parser.

    An RDFParser has a predefined source; the target for output is given when the "parse" method 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. The process is

        StreamRDF destination = ...
        RDFParser parser = RDFParser.create().source("filename.ttl").build();
        parser.parse(destination);
     
    or using abbreviated forms:
     RDFParser.source("filename.ttl").parse(destination);
     
    The destination StreamRDF and can be given as a Graph or DatasetGraph as well.
    See Also:
    The interface to the syntax parsing process for each RDF syntax.
    • Method Detail

      • 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​(java.nio.file.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​(java.lang.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

        public static RDFParserBuilder fromString​(java.lang.String string)
        Create an RDFParserBuilder and set content to parse to be the given string. The syntax must be set with .lang(...).

        Shortcut for RDFParser.create.fromString(string).

        Parameters:
        string -
        Returns:
        RDFParserBuilder
      • source

        public static RDFParserBuilder source​(java.io.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​(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​(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​(Dataset dataset)
        Parse the source, sending the results to a Dataset. This method is equivalent to parse(dataset.asDatasetGraph()).
      • parse

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