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 RDFParserBuildercreate()Create anRDFParserBuilder.static RDFParserBuilderfromString(String string) Deprecated.static RDFParserBuilderfromString(String string, Lang lang) Create anRDFParserBuilderand set content to be parsed together with the RDF syntax language.voidparse(org.apache.jena.graph.Graph graph) Parse the source, sending the results to aGraph.voidParse the source, sending the results to aDataset.voidparse(org.apache.jena.rdf.model.Model model) Parse the source, sending the results to aModel.voidParse the source, sending the results to aStreamRDF.voidparse(DatasetGraph dataset) Parse the source, sending the results to aDatasetGraph.static RDFParserBuildersource(InputStream input) Create anRDFParserBuilderand set the source toInputStream.static RDFParserBuilderCreate anRDFParserBuilderand set the source to the URI, which can be a filename.static RDFParserBuilderCreate anRDFParserBuilderand set the source to thePath.Parse the source in to a freshDatasetand return the dataset.Parse the source in to a freshDatasetGraphand return the DatasetGraph.org.apache.jena.graph.GraphtoGraph()Parse the source in to a freshGraphand return the graph.org.apache.jena.rdf.model.ModeltoModel()Parse the source in to a freshModeland return the model.
-
Method Details
-
create
Create anRDFParserBuilder.Often used in a pattern such as:
RDFParser.create() .source("data.ttl") .parse(graph); -
source
Create anRDFParserBuilderand set the source to thePath.This is a shortcut for
RDFParser.create().source(path).- Parameters:
path-- Returns:
- RDFParserBuilder
-
source
Create anRDFParserBuilderand 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 anRDFParserBuilderand 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 anRDFParserBuilderand 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 anRDFParserBuilderand set the source toInputStream. TheInputStreamwill 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 freshGraphand 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 freshModeland return the model.The source must be for triples; any quads are discarded.
-
toDataset
Parse the source in to a freshDatasetand return the dataset.It may be preferable to instead call
parse(Dataset)supplying your desiredDatasetimplementation instead depending on how you intend to further process the parsed data. -
toDatasetGraph
Parse the source in to a freshDatasetGraphand return the DatasetGraph.It may be preferable to instead call
parse(DatasetGraph)supplying your desiredDatasetGraphimplementation instead depending on how you intend to further process the parsed data. -
parse
Parse the source, sending the results to aStreamRDF.
-
fromString(String, Lang)