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 a short cut:
RDFParser parser = RDFParser.create() .source("filename.ttl") .parse(destination);
-
Method Summary
Modifier and TypeMethodDescriptionacceptHeader
(String acceptHeader) Set the HTTP "Accept" header.Set the base URI for parsing.build()
Build anRDFParser
.canonicalValues
(boolean flag) Convert the lexical form of literals to a canonical form.checking
(boolean flag) Set whether to perform checking, NTriples and NQuads default to no checking, other languages to checking.clone()
Duplicate this builder with current settings.Set the context for the parser when built.static RDFParserBuilder
create()
errorHandler
(ErrorHandler handler) Set theErrorHandler
to use.factory
(FactoryRDF factory) Set theFactoryRDF
to use.Force the choice RDF syntax to belang
, and ignore any indications such as file extension or HTTP Content-Type.fromString
(String string) Use the given string as the content to parse.httpClient
(HttpClient httpClient) Set an HTTP client.httpHeader
(String header, String value) Set an HTTP header.labelToNode
(LabelToNode labelToNode) Use the givenLabelToNode
, the policy for converting blank node labels in RDF syntax to Jena'sNode
objects (usually a blank node).Set the hintLang
.Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.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
.Set an initial prefix map for parsing.resolver
(org.apache.jena.irix.IRIxResolver resolver) Provide a specificIRIxResolver
to check and resolve URIs.resolveURIs
(boolean flag) Choose whether to resolve URIs or throw an error.Add a setting to the context for the parser when built.Add a setting to the context for the parser when built.source
(InputStream input) Set the source toInputStream
.Deprecated.UsefromString(java.lang.String)
, or an InputStream or a StringReader.source
(StringReader reader) Set the source toStringReader
.Set the source to a URI; this includes OS file names.Set the source toPath
.streamManager
(StreamManager streamManager) Set the StreamManager to use when opening a URI (including files by name, but not byPath
).strict
(boolean strictMode) Set the parser built to "strict" mode.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
-
source
Set the source toPath
. This clears any other source setting.The parser can be reused.
- Parameters:
path
-- Returns:
- this
-
source
Set the source to a URI; this includes OS file names. File URL should be of the formfile:///...
. This clears any other source setting.The parser can be reused.
- Parameters:
uriOrFile
-- Returns:
- this
-
fromString
Use the given string as the content to parse. This clears any other source setting.The syntax must be set with
.lang(...)
.The parser can be reused.
- Parameters:
string
- The characters to be parsed.- Returns:
- this
-
source
Set the source toInputStream
. This clears any other source setting.The syntax must be set with
.lang(...)
.The
InputStream
will be closed when the parser is called and the parser can not be reused.- Parameters:
input
-- Returns:
- this
-
source
Set the source toStringReader
. This clears any other source setting. TheStringReader
will be closed when the parser is called and the parser can not be reused.The syntax must be set with
.lang(...)
.Consider using
fromString(java.lang.String)
instead.- Parameters:
reader
-- Returns:
- this
-
source
Deprecated.UsefromString(java.lang.String)
, or an InputStream or a StringReader.Set the source toReader
. This clears any other source setting. TheReader
will be closed when the parser is called and the parser can not be reused.The syntax must be set with
.lang(...)
.- Parameters:
reader
-- Returns:
- this
-
streamManager
Set the StreamManager to use when opening a URI (including files by name, but not byPath
).- Parameters:
streamManager
-- Returns:
- this
-
lang
Set the hintLang
. This is the RDF syntax used when there is no way to deduce the syntax (e.g. read from a InputStream, not recognized file extension, no recognized HTTP Content-Type provided).- Parameters:
lang
-- Returns:
- this
-
strict
Set the parser built to "strict" mode. The default is system wide setting ofSysRIOT.isStrictMode()
.- Parameters:
strictMode
-- Returns:
- this
-
forceLang
Force the choice RDF syntax to belang
, and ignore any indications such as file extension or HTTP Content-Type.- Parameters:
lang
-- Returns:
- this
- See Also:
-
acceptHeader
Set the HTTP "Accept" header. The default if not set isWebContent.defaultRDFAcceptHeader
.- Parameters:
acceptHeader
-- Returns:
- this
-
httpHeader
Set an HTTP header. Any previous setting is lost.Consider setting up an
HttpClient
if more complicated setting to an HTTP request is required. -
httpClient
Set an HTTP client. Any previous setting is lost.Consider setting up an
HttpClient
if more complicated setting to an HTTP request is required. -
base
Set the base URI for parsing. The default is to have no base URI. -
resolveURIs
Choose whether to resolve URIs or throw an error.This does not affect all languages: N-Triples and N-Quads never resolve URIs.
If this is flag false, relative URIs cause parse errors.
Only set this to false for debugging and development purposes. -
resolver
Provide a specificIRIxResolver
to check and resolve URIs. Its settings will determine the base IRI and whether to resolve relative IRIs or not. The caller is responsible for giving a resolver that is suitable for the RDF syntax to be parsed. -
prefixes
Set an initial prefix map for parsing.Using this, and
base(java.lang.String)
, mean that Turtle and TriG fragments can be parsed.The caller is responsible for setting any prefixes that are undeclared in the fragment.
Changes made to the prefix map argument after this call will not be seen by the parser. Passing null clears any previous setting.
-
canonicalValues
Convert the lexical form of literals to a canonical form.Two literals can be different RDF terms for the same value.
Examples include (first shown of the pair is the canonical form):
"1"^^xsd:integer
and"+01"^^xsd:integer
"1.0E0"^^xsd:double
and"1"^^xsd:double
"1.0"^^xsd:Decimal
rather than"1"^^xsd:decimal
). See XSD 1.0 3.2.3.2 Canonical representationThe effect on literals where the lexical form does not represent a valid value (for example,
"3000"^^xsd:byte
) is undefined.This option is off by default.
This option can slow parsing down.
For consistent loading of data, it is recommended that data is cleaned and canonicalized before loading so the conversion is done once.
- See Also:
-
langTagLowerCase
Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.Convert language tags to lower case.This is the suggested form in RDF 1.1 for comparsions. However, this is not the recommended canonical form in RFC 5646.
Providing all data is converted consistently, language tag equality is maintained for either lower case or RFC canonicalization styles.
This option can slow parsing down.
- See Also:
-
langTagCanonical
Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.Language tags are case-normalized as defined by RFC 5646. Example:en-GB
, noten-gb
.This does not affect the RDF 1.1 requirement that the value-space of language tags is lower-case.
Providing all data is converted consistently, lang tag equality is maintained for either lower case or RFC canonicalization.
This option can slow parsing down.
- See Also:
-
langTagAsGiven
Deprecated.In Jena5, language tags are always converted to RFC 5646 case format.The form of the language tags as given in the data is preserved. This is the default behaviour of parsing.- See Also:
-
checking
Set whether to perform checking, NTriples and NQuads default to no checking, other languages to checking.Checking adds warnings over and above basic syntax errors.
- URIs - whether IRs confirm to all the rules of the URI scheme
- Literals: whether the lexical form conforms to the rules for the datatype.
- Triples and quads: check slots have a valid kind of RDF term (parsers usually make this a syntax error anyway).
See also
errorHandler(ErrorHandler)
to control the output. The default is to log. This can also be used to turn warnings into exceptions. -
errorHandler
Set theErrorHandler
to use. This replaces any previous setting. The default is use slf4j logger "RIOT".- Parameters:
handler
-- Returns:
- this
-
factory
Set theFactoryRDF
to use.FactoryRDF
control how parser output is turned intoNode
and howTriple
s andQuad
s are built. This replaces any previous setting.
The default is useRiotLib.factoryRDF()
which is providesNode
reuse.
TheFactoryRDF
also determines how blank node labels in RDF syntax are mapped to blank node objects.new Factory(myLabelToNode)
to create anFactoryRDF
and set theLabelToNode
step.- Parameters:
factory
-- Returns:
- this
- See Also:
-
labelToNode
-
labelToNode
Use the givenLabelToNode
, the policy for converting blank node labels in RDF syntax to Jena'sNode
objects (usually a blank node).
Only applies when theFactoryRDF
is not set in theRDFParserBuilder
, otherwise theFactoryRDF
controls the label-to-node process.
SyntaxLabels.createLabelToNode()
is the default policy.
LabelToNode.createUseLabelAsGiven()
uses the label in the RDF syntax directly. This does not produce safe RDF and should only be used for development and debugging.- Parameters:
labelToNode
-- Returns:
- this
- See Also:
-
factory
-
context
Set the context for the parser when built.- Parameters:
context
-- Returns:
- this
- See Also:
-
set
Add a setting to the context for the parser when built. A value of "null" removes a previous setting.- Parameters:
symbol
-value
-- Returns:
- this
-
set
Add a setting to the context for the parser when built.- Parameters:
symbol
-value
-- Returns:
- this
-
parse
Parse the source, sending the results to aStreamRDF
. Short form forbuild().parse(stream)
.- Parameters:
stream
-
-
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. Short form forbuild().parse(graph)
which sends triples and prefixes to theGraph
.- Parameters:
graph
-
-
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. Short form forbuild().parse(model)
which sends triples and prefixes to theModel
.- Parameters:
model
-
-
parse
Parse the source, sending the results to aDatasetGraph
. Short form forbuild().parse(dataset)
which sends triples and prefixes to theDatasetGraph
.- Parameters:
dataset
-
-
parse
Parse the source, sending the results to aDataset
. Short form forbuild().parse(dataset)
which sends triples and prefixes to theDataset
.- Parameters:
dataset
-
-
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. -
toDatasetGraph
Parse the source in to a freshDatasetGraph
and return the DatasetGraph. -
build
Build anRDFParser
. The parser takes it's configuration from this builder and can not then be changed. The source must be set. When a parser is used, it is takes the source and sends output to anStreamRDF
.Shortcuts:
parse(DatasetGraph)
- parse the source and output to aDatasetGraph
parse(Graph)
- parse the source and output to aGraph
parse(StreamRDF)
- parse the source and output to aStreamRDF
- Returns:
- RDFParser
-
clone
Duplicate this builder with current settings. Changes to setting to this builder do not affect the clone.
-