public class RDFParserBuilder extends Object
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);
| Modifier and Type | Method and Description |
|---|---|
RDFParserBuilder |
base(String base)
Set the base URI for parsing.
|
RDFParser |
build()
Build an
RDFParser. |
RDFParserBuilder |
canonicalLiterals(boolean flag)
Convert the lexical form of literals to a canonical form.
|
RDFParserBuilder |
checking(boolean flag)
Set whether to perform checking,
NTriples and NQuads default to no checking, olther langauges to checking.
|
RDFParserBuilder |
clone()
Duplicate this builder with current settings.
|
RDFParserBuilder |
context(Context context) |
static RDFParserBuilder |
create() |
RDFParserBuilder |
errorHandler(ErrorHandler handler)
Set the
ErrorHandler to use. |
RDFParserBuilder |
factory(FactoryRDF factory)
Set the
FactoryRDF to use. |
RDFParserBuilder |
forceLang(Lang lang)
Force the choice RDF syntax to be
lang, and ignore any indications such as file extension
or HTTP Content-Type. |
RDFParserBuilder |
fromString(String string)
Use the given string as the content to parse.
|
RDFParserBuilder |
httpAccept(String acceptHeader)
Set the HTTP "Accept" header.
|
RDFParserBuilder |
httpClient(org.apache.http.client.HttpClient httpClient)
Set the HttpClient to use.
|
RDFParserBuilder |
httpHeader(String header,
String value)
Set an HTTP header.
|
RDFParserBuilder |
labelToNode(LabelToNode labelToNode)
Use the given
LabelToNode, the policy for converting blank node labels in
RDF syntax to Jena's Node objects (usually a blank node). |
RDFParserBuilder |
lang(Lang lang)
Set the hint
Lang. |
void |
parse(DatasetGraph dataset)
Parse the source, sending the results to a
DatasetGraph. |
void |
parse(Graph graph)
Parse the source, sending the results to a
Graph. |
void |
parse(StreamRDF stream)
Parse the source, sending the results to a
StreamRDF. |
RDFParserBuilder |
resolveURIs(boolean flag)
Choose whether to resolve URIs.
This does not affect all langages: N-Triples and N-Quads never resolve URIs. Relative URIs are bad data. Only set this to false for debugging and development purposes. |
RDFParserBuilder |
source(InputStream input)
Set the source to
InputStream. |
RDFParserBuilder |
source(Path path)
Set the source to
Path. |
RDFParserBuilder |
source(Reader reader)
Deprecated.
Use
fromString(java.lang.String), or an InputStream or a StringReader. |
RDFParserBuilder |
source(String uriOrFile)
Set the source to a URI; this includes OS file names.
|
RDFParserBuilder |
source(StringReader reader)
Set the source to
StringReader. |
public static RDFParserBuilder create()
public RDFParserBuilder source(Path path)
Path.
This clears any other source setting.
The parser can be reused.
path - public RDFParserBuilder source(String uriOrFile)
file:///....
This clears any other source setting.
The parser can be reused.
uriOrFile - public RDFParserBuilder fromString(String string)
The syntax must be set with .lang(...).
The parser can be reused.
string - The characters to be parsed.public RDFParserBuilder source(InputStream input)
InputStream.
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.
input - public RDFParserBuilder source(StringReader reader)
StringReader.
This clears any other source setting.
The StringReader 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.
reader - @Deprecated public RDFParserBuilder source(Reader reader)
fromString(java.lang.String), or an InputStream or a StringReader.Reader.
This clears any other source setting.
The Reader will be closed when the
parser is called and the parser can not be reused.
The syntax must be set with .lang(...).
reader - public RDFParserBuilder lang(Lang lang)
Lang. This is the RDF syntax used when there is no way to
deduce the syntax (e.g. read from a InputStream, no recognized file extension, no
recognized HTTP Content-Type provided).lang - public RDFParserBuilder forceLang(Lang lang)
lang, and ignore any indications such as file extension
or HTTP Content-Type.lang - Langpublic RDFParserBuilder httpAccept(String acceptHeader)
WebContent.defaultRDFAcceptHeader.acceptHeader - public RDFParserBuilder httpHeader(String header, String value)
Consider setting up an HttpClient if more complicated
setting to an HTTP request is required.
public RDFParserBuilder httpClient(org.apache.http.client.HttpClient httpClient)
public RDFParserBuilder base(String base)
public RDFParserBuilder resolveURIs(boolean flag)
public RDFParserBuilder canonicalLiterals(boolean flag)
Two literals can be different RDF terms for the same value.
Examples include (first shows of the pair is the canonical form):
"1"^^xsd:integer and "+01"^^xsd:integer
"1.0E0"^^xsd:double and "1"^^xsd:double
The canonical forms follow XSD 1.1
"1.0"^^xsd:Decimal
rather than "1"^^xsd:decimal). See XSD 1.0 3.2.3.2
Canonical representation
Language tags are case-normalized as defined by
RFC 5646. Example: en-GB
not en-gb. This does not affect the RDF 1.1 requirement that the
value-space of language tags is lower-case.
The 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.
public RDFParserBuilder checking(boolean flag)
Checking adds warnings over and above basic syntax errors.
See also errorHandler(ErrorHandler) to control the output. The default is to log.
Thsi can also be used to turn warnings into exceptions.
public RDFParserBuilder errorHandler(ErrorHandler handler)
ErrorHandler to use.
This replaces any previous setting.
The default is use slf4j logger "RIOT".handler - public RDFParserBuilder factory(FactoryRDF factory)
FactoryRDF to use. FactoryRDF control how parser output is
turned into Node and how Triples and Quads are built. This
replaces any previous setting.
RiotLib.factoryRDF() which is provides Node
reuse.
FactoryRDF also determines how blank node labels in RDF syntax are
mapped to BlankNodeId. Use
new Factory(myLabelToNode)
to create an FactoryRDF and set the LabelToNode step.factory - labelToNodepublic RDFParserBuilder labelToNode(LabelToNode labelToNode)
LabelToNode, the policy for converting blank node labels in
RDF syntax to Jena's Node objects (usually a blank node).
FactoryRDF is not set in the
RDFParserBuilder, otherwise the FactoryRDF 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.labelToNode - factorypublic RDFParserBuilder context(Context context)
public void parse(StreamRDF stream)
StreamRDF.
Short form for build().parse(stream).stream - public void parse(Graph graph)
Graph. The source must be for
triples; any quads are discarded.
Short form for build().parse(stream)
where stream sends tripes and prfixes to the Graph.graph - public void parse(DatasetGraph dataset)
DatasetGraph.
Short form for build().parse(stream)
where stream sends tripes and prefixes to the DatasetGraph.dataset - public RDFParser build()
RDFParser. 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 an StreamRDF.
Shortcuts:
parse(DatasetGraph) - parse the source and output to a DatasetGraph
parse(Graph) - parse the source and output to a Graph
parse(StreamRDF) - parse the source and output to a StreamRDF
public RDFParserBuilder clone()
Licenced under the Apache License, Version 2.0