Class RDFParserBuilder
- java.lang.Object
-
- org.apache.jena.riot.RDFParserBuilder
-
public class RDFParserBuilder extends java.lang.ObjectAnRDFParseris a process that will generate triples;RDFParserBuilderprovides the means to setup the parser.An
RDFParserhas 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 isStreamRDF 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RDFParserBuilderbase(java.lang.String base)Set the base URI for parsing.RDFParserbuild()Build anRDFParser.RDFParserBuildercanonicalLiterals(boolean flag)Deprecated.RDFParserBuildercanonicalValues(boolean flag)Convert the lexical form of literals to a canonical form.RDFParserBuilderchecking(boolean flag)Set whether to perform checking, NTriples and NQuads default to no checking, other languages to checking.RDFParserBuilderclone()Duplicate this builder with current settings.RDFParserBuildercontext(Context context)Set the context for the parser when built.static RDFParserBuildercreate()RDFParserBuildererrorHandler(ErrorHandler handler)Set theErrorHandlerto use.RDFParserBuilderfactory(FactoryRDF factory)Set theFactoryRDFto use.RDFParserBuilderforceLang(Lang lang)Force the choice RDF syntax to belang, and ignore any indications such as file extension or HTTP Content-Type.RDFParserBuilderfromString(java.lang.String string)Use the given string as the content to parse.RDFParserBuilderhttpAccept(java.lang.String acceptHeader)Set the HTTP "Accept" header.RDFParserBuilderhttpClient(org.apache.http.client.HttpClient httpClient)Set the HttpClient to use.RDFParserBuilderhttpHeader(java.lang.String header, java.lang.String value)Set an HTTP header.RDFParserBuilderlabelToNode(LabelToNode labelToNode)Use the givenLabelToNode, the policy for converting blank node labels in RDF syntax to Jena'sNodeobjects (usually a blank node).RDFParserBuilderlang(Lang lang)Set the hintLang.RDFParserBuilderlangTagAsGiven()The form of the language tags as given in the data is preserved.RDFParserBuilderlangTagCanonical()Language tags are case-normalized as defined by RFC 5646.RDFParserBuilderlangTagLowerCase()Convert language tags to lower case.voidparse(Graph graph)Parse the source, sending the results to aGraph.voidparse(Dataset dataset)Parse the source, sending the results to aDataset.voidparse(Model model)Parse the source, sending the results to aModel.voidparse(StreamRDF stream)Parse the source, sending the results to aStreamRDF.voidparse(DatasetGraph dataset)Parse the source, sending the results to aDatasetGraph.RDFParserBuilderresolver(IRIxResolver resolver)Provide a specificIRIxResolverto check and resolve URIs.RDFParserBuilderresolveURIs(boolean flag)Choose whether to resolve URIs.
This does not affect all languages: N-Triples and N-Quads never resolve URIs.
Relative URIs are bad data.
Only set this to false for debugging and development purposes.RDFParserBuilderset(Symbol symbol, java.lang.Object value)Added a setting to the context for the parser when built.RDFParserBuildersource(java.io.InputStream input)Set the source toInputStream.RDFParserBuildersource(java.io.Reader reader)Deprecated.UsefromString(java.lang.String), or an InputStream or a StringReader.RDFParserBuildersource(java.io.StringReader reader)Set the source toStringReader.RDFParserBuildersource(java.lang.String uriOrFile)Set the source to a URI; this includes OS file names.RDFParserBuildersource(java.nio.file.Path path)Set the source toPath.RDFParserBuilderstreamManager(StreamManager streamManager)Set the StreamManager to use when opening a URI (including files by name, but not byPath).RDFParserBuilderstrict(boolean strictMode)Set the parser built to "strict" mode.
-
-
-
Method Detail
-
create
public static RDFParserBuilder create()
-
source
public RDFParserBuilder source(java.nio.file.Path path)
Set the source toPath. This clears any other source setting.The parser can be reused.
- Parameters:
path-- Returns:
- this
-
source
public RDFParserBuilder source(java.lang.String uriOrFile)
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
public RDFParserBuilder fromString(java.lang.String string)
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
public RDFParserBuilder source(java.io.InputStream input)
Set the source toInputStream. This clears any other source setting.The syntax must be set with
.lang(...).The
InputStreamwill be closed when the parser is called and the parser can not be reused.- Parameters:
input-- Returns:
- this
-
source
public RDFParserBuilder source(java.io.StringReader reader)
Set the source toStringReader. This clears any other source setting. TheStringReaderwill 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 public RDFParserBuilder source(java.io.Reader reader)
Deprecated.UsefromString(java.lang.String), or an InputStream or a StringReader.Set the source toReader. This clears any other source setting. TheReaderwill 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
public RDFParserBuilder streamManager(StreamManager streamManager)
Set the StreamManager to use when opening a URI (including files by name, but not byPath).- Parameters:
streamManager-- Returns:
- this
-
lang
public RDFParserBuilder lang(Lang 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, no recognized file extension, no recognized HTTP Content-Type provided).- Parameters:
lang-- Returns:
- this
-
strict
public RDFParserBuilder strict(boolean strictMode)
Set the parser built to "strict" mode. The default is system wide setting ofSysRIOT.isStrictMode().- Parameters:
strictMode-- Returns:
- this
-
forceLang
public RDFParserBuilder forceLang(Lang lang)
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:
Lang
-
httpAccept
public RDFParserBuilder httpAccept(java.lang.String acceptHeader)
Set the HTTP "Accept" header. The default if not set isWebContent.defaultRDFAcceptHeader.- Parameters:
acceptHeader-- Returns:
- this
-
httpHeader
public RDFParserBuilder httpHeader(java.lang.String header, java.lang.String value)
Set an HTTP header. Any previous setting is lost.Consider setting up an
HttpClientif more complicated setting to an HTTP request is required.
-
httpClient
public RDFParserBuilder httpClient(org.apache.http.client.HttpClient httpClient)
Set the HttpClient to use. This will override any HTTP header settings set for this builder.
-
base
public RDFParserBuilder base(java.lang.String base)
Set the base URI for parsing. The default is to have no base URI.
-
resolveURIs
public RDFParserBuilder resolveURIs(boolean flag)
Choose whether to resolve URIs.
This does not affect all languages: N-Triples and N-Quads never resolve URIs.
Relative URIs are bad data.
Only set this to false for debugging and development purposes.
-
resolver
public RDFParserBuilder resolver(IRIxResolver resolver)
Provide a specificIRIxResolverto 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.
-
canonicalLiterals
@Deprecated public RDFParserBuilder canonicalLiterals(boolean flag)
Deprecated.UsecanonicalValuesand one oflangTagCanonical()andlangTagLowerCase()This operation is equivalent to
this.canonicalValues(flag); if ( flag ) this.langTagCanonical(); else this.langTagAsGiven(); return this;Convert the lexical form of literals to a canonical form.
-
canonicalValues
public RDFParserBuilder canonicalValues(boolean flag)
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):
The canonical forms follow XSD 1.1 <href="https://www.w3.org/TR/xmlschema11-2/#canonical-lexical-representation">2.3.1 Canonical Mapping</a> except in the case of xsd:decimal where it follows the older XSD 1.0 which makes it legal for Turtle's short form ("1"^^xsd:integerand"+01"^^xsd:integer"1.0E0"^^xsd:doubleand"1"^^xsd:double"1.0"^^xsd:Decimalrather 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(),langTagCanonical()
-
langTagLowerCase
public RDFParserBuilder langTagLowerCase()
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()
-
langTagCanonical
public RDFParserBuilder langTagCanonical()
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:
langTagLowerCase()
-
langTagAsGiven
public RDFParserBuilder langTagAsGiven()
The form of the language tags as given in the data is preserved. This is the default behaviour of parsing.- See Also:
langTagLowerCase(),langTagCanonical()
-
checking
public RDFParserBuilder checking(boolean flag)
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
public RDFParserBuilder errorHandler(ErrorHandler handler)
Set theErrorHandlerto use. This replaces any previous setting. The default is use slf4j logger "RIOT".- Parameters:
handler-- Returns:
- this
-
factory
public RDFParserBuilder factory(FactoryRDF factory)
Set theFactoryRDFto use.FactoryRDFcontrol how parser output is turned intoNodeand howTriples andQuads are built. This replaces any previous setting.
The default is useRiotLib.factoryRDF()which is providesNodereuse.
TheFactoryRDFalso determines how blank node labels in RDF syntax are mapped toBlankNodeId. Usenew Factory(myLabelToNode)to create anFactoryRDFand set theLabelToNodestep.- Parameters:
factory-- Returns:
- this
- See Also:
labelToNode
-
labelToNode
public RDFParserBuilder labelToNode(LabelToNode labelToNode)
Use the givenLabelToNode, the policy for converting blank node labels in RDF syntax to Jena'sNodeobjects (usually a blank node).
Only applies when theFactoryRDFis not set in theRDFParserBuilder, otherwise theFactoryRDFcontrols 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
public RDFParserBuilder context(Context context)
Set the context for the parser when built. If a context is already partly set for this builder, merge the new settings into the outstanding context. If the context argument is null, do nothing.- Parameters:
context-- Returns:
- this
- See Also:
Context
-
set
public RDFParserBuilder set(Symbol symbol, java.lang.Object value)
Added a setting to the context for the parser when built. A value of "null" removes a previous setting.- Parameters:
symbol-value-- Returns:
- this
- See Also:
Context
-
parse
public void parse(StreamRDF stream)
Parse the source, sending the results to aStreamRDF. Short form forbuild().parse(stream).- Parameters:
stream-
-
parse
public void parse(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(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
public void parse(DatasetGraph dataset)
Parse the source, sending the results to aDatasetGraph. Short form forbuild().parse(dataset)which sends triples and prefixes to theDatasetGraph.- Parameters:
dataset-
-
parse
public void parse(Dataset dataset)
Parse the source, sending the results to aDataset. Short form forbuild().parse(dataset)which sends triples and prefixes to theDataset.- Parameters:
dataset-
-
build
public RDFParser 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 aDatasetGraphparse(Graph)- parse the source and output to aGraphparse(StreamRDF)- parse the source and output to aStreamRDF
- Returns:
- RDFParser
-
clone
public RDFParserBuilder clone()
Duplicate this builder with current settings. Changes to setting to this builder do not affect the clone.
-
-