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();
-
Method Summary
Modifier and TypeMethodDescriptionstatic RDFParserBuilder
create()
Create anRDFParserBuilder
.static RDFParserBuilder
fromString
(String string) Deprecated.static RDFParserBuilder
fromString
(String string, Lang lang) Create anRDFParserBuilder
and set content to be parsed together with the RDF syntax language.void
parse
(org.apache.jena.graph.Graph graph) Parse the source, sending the results to aGraph
.void
Parse the source, sending the results to aDataset
.void
parse
(org.apache.jena.rdf.model.Model model) Parse the source, sending the results to aModel
.void
Parse the source, sending the results to aStreamRDF
.void
parse
(DatasetGraph dataset) Parse the source, sending the results to aDatasetGraph
.static RDFParserBuilder
source
(InputStream input) Create anRDFParserBuilder
and set the source toInputStream
.static RDFParserBuilder
Create anRDFParserBuilder
and set the source to the URI, which can be a filename.static RDFParserBuilder
Create anRDFParserBuilder
and set the source to thePath
.Parse the source in to a freshDataset
and return the dataset.Parse the source in to a freshDatasetGraph
and return the DatasetGraph.org.apache.jena.graph.Graph
toGraph()
Parse the source in to a freshGraph
and return the graph.org.apache.jena.rdf.model.Model
toModel()
Parse the source in to a freshModel
and return the model.
-
Method Details
-
create
Create anRDFParserBuilder
.Often used in a pattern such as:
RDFParser.create() .source("data.ttl") .parse(graph);
-
source
Create anRDFParserBuilder
and set the source to thePath
.This is a shortcut for
RDFParser.create().source(path)
.- Parameters:
path
-- Returns:
- RDFParserBuilder
-
source
Create anRDFParserBuilder
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.Create anRDFParserBuilder
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
Create anRDFParserBuilder
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
Create anRDFParserBuilder
and set the source toInputStream
. TheInputStream
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 aGraph
.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 aModel
.The source must be for triples; any quads are discarded.
This method is equivalent to
parse(model.getGraph())
. -
parse
Parse the source, sending the results to aDatasetGraph
. -
parse
Parse the source, sending the results to aDataset
. This method is equivalent toparse(dataset.asDatasetGraph())
. -
toGraph
public org.apache.jena.graph.Graph toGraph()Parse the source in to a freshGraph
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 freshModel
and return the model.The source must be for triples; any quads are discarded.
-
toDataset
Parse the source in to a freshDataset
and return the dataset.It may be preferable to instead call
parse(Dataset)
supplying your desiredDataset
implementation instead depending on how you intend to further process the parsed data. -
toDatasetGraph
Parse the source in to a freshDatasetGraph
and return the DatasetGraph.It may be preferable to instead call
parse(DatasetGraph)
supplying your desiredDatasetGraph
implementation instead depending on how you intend to further process the parsed data. -
parse
Parse the source, sending the results to aStreamRDF
.
-
fromString(String, Lang)