Class NTriplesParser
java.lang.Object
org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
org.eclipse.rdf4j.rio.ntriples.NTriplesParser
- All Implemented Interfaces:
RDFParser
- Direct Known Subclasses:
NQuadsParser
RDF parser for N-Triples files. A specification of NTriples can be found in
this section of the RDF Test Cases document. This parser
is not thread-safe, therefore its public methods are synchronized.
- Author:
- Arjohn Kampman
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected char[]protected longprotected Valueprotected IRIprotected BufferedReaderprotected ResourceFields inherited from class AbstractRDFParser
rdfHandler, valueFactoryModifier and TypeFieldDescriptionprotected RDFHandlerThe RDFHandler that will handle the parsed RDF.protected ValueFactoryThe ValueFactory to use for creating RDF model objects. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new NTriplesParser that will use aSimpleValueFactoryto create object for resources, bNodes and literals.NTriplesParser(ValueFactory valueFactory) Creates a new NTriplesParser that will use the supplied ValueFactory to create RDF model objects. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidVerifies that there is only whitespace or comments until the end of the line.protected voidclear()Clears any information that has been collected while parsing.protected IRICreates aIRIobject for the specified URI-string.Gets the RDF format that this parser can parse.Collection<RioSetting<?>> protected voidhandleStatement(boolean ignoredAnError) voidparse(InputStream in, String baseURI) Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.voidParses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.protected IRIparseIRI()protected Resourceprotected voidprotected voidprotected voidprotected voidprotected voidreportError(Exception e, RioSetting<Boolean> setting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected voidreportError(String msg, RioSetting<Boolean> setting) OverridesAbstractRDFParser.reportError(String, RioSetting), adding line number information to the error.protected voidOverridesAbstractRDFParser.reportFatalError(Exception), adding line number information to the error.protected voidreportFatalError(String msg) OverridesAbstractRDFParser.reportFatalError(String), adding line number information to the error.protected voidreportWarning(String msg) OverridesAbstractRDFParser.reportWarning(String), adding line number information to the error.protected booleanprotected voidskipWhitespace(boolean throwEOF) protected voidMethods inherited from class AbstractRDFParser
clearBNodeIDMap, createBNode, createBNode, createLiteral, createLiteral, createLiteral, createNode, createNode, createStatement, createStatement, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, set, setBaseURI, setBaseURI, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setValueFactoryModifier and TypeMethodDescriptionprotected voidDeprecated.protected BNodeDeprecated.protected BNodecreateBNode(String nodeID) Deprecated.protected LiteralcreateLiteral(String label, String lang, CoreDatatype datatype, long lineNo, long columnNo) Creates aLiteralobject with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.protected LiteralcreateLiteral(String label, String lang, IRI datatype) Creates aLiteralobject with the supplied parameters.protected LiteralcreateLiteral(String label, String lang, IRI datatype, long lineNo, long columnNo) Creates aLiteralobject with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.protected Resourceprotected ResourcecreateNode(String nodeID) protected StatementcreateStatement(Resource subj, IRI pred, Value obj) Creates a newStatementobject with the supplied components.protected StatementcreateStatement(Resource subj, IRI pred, Value obj, Resource context) Creates a newStatementobject with the supplied components.protected StringgetNamespace(String prefix) Gets the namespace that is associated with the specified prefix or throws anRDFParseException.Retrieves the current parser configuration as a single object.protected voidbooleanprotected voidreportError(Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected voidreportError(String msg, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected voidreportError(String msg, Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected voidreportFatalError(Exception e, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards.protected voidreportFatalError(String msg, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.protected voidreportFatalError(String message, Exception e, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards.protected voidreportLocation(long lineNo, long columnNo) Reports the specified line- and column number to the registeredParseLocationListener, if any.protected voidreportWarning(String msg, long lineNo, long columnNo) Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.protected IRIresolveURI(String uriSpec) Resolves a URI-string against the base URI and creates aIRIobject for it.<T> RDFParserset(RioSetting<T> setting, T value) Set a setting on the parser, and return this parser object to allow chaining.protected voidsetBaseURI(String uriSpec) Parses the supplied URI-string and sets it as the base URI for resolving relative URIs.protected voidsetBaseURI(ParsedIRI baseURI) Sets the base URI for resolving relative URIs.protected voidsetNamespace(String prefix, String namespace) Associates the specified prefix to the specified namespace.Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.setParserConfig(ParserConfig config) Sets all supplied parser configuration options.voidsetPreserveBNodeIDs(boolean preserveBNodeIDs) Set whether the parser should preserve bnode identifiers specified in the source (default is false).setRDFHandler(RDFHandler handler) Sets the RDFHandler that will handle the parsed RDF data.setValueFactory(ValueFactory valueFactory) Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.
-
Field Details
-
reader
-
lineChars
protected char[] lineChars -
currentIndex
protected int currentIndex -
lineNo
protected long lineNo -
subject
-
predicate
-
object
-
-
Constructor Details
-
NTriplesParser
public NTriplesParser()Creates a new NTriplesParser that will use aSimpleValueFactoryto create object for resources, bNodes and literals. -
NTriplesParser
Creates a new NTriplesParser that will use the supplied ValueFactory to create RDF model objects.- Parameters:
valueFactory- A ValueFactory.
-
-
Method Details
-
getRDFFormat
-
parse
public void parse(InputStream in, String baseURI) throws IOException, RDFParseException, RDFHandlerException Description copied from interface:RDFParserParses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.- Parameters:
in- The InputStream from which to read the data.baseURI- The URI associated with the data in the InputStream. May benull. Parsers for syntax formats that do not support relative URIs will ignore this argument.Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).
- Throws:
IOException- If an I/O error occurred while data was read from the InputStream.RDFParseException- If the parser has found an unrecoverable parse error.RDFHandlerException- If the configured statement handler has encountered an unrecoverable error.
-
parse
public void parse(Reader reader, String baseURI) throws IOException, RDFParseException, RDFHandlerException Description copied from interface:RDFParserParses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.- Parameters:
reader- The Reader from which to read the data.baseURI- The URI associated with the data in the InputStream. May benull. Parsers for syntax formats that do not support relative URIs will ignore this argument.Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).
- Throws:
IOException- If an I/O error occurred while data was read from the InputStream.RDFParseException- If the parser has found an unrecoverable parse error.RDFHandlerException- If the configured statement handler has encountered an unrecoverable error.
-
parseStatement
- Throws:
RDFParseExceptionRDFHandlerException
-
skipWhitespace
protected void skipWhitespace(boolean throwEOF) -
shouldParseLine
protected boolean shouldParseLine() -
parseSubject
protected void parseSubject() -
parsePredicate
protected void parsePredicate() -
parseObject
protected void parseObject() -
assertLineTerminates
Verifies that there is only whitespace or comments until the end of the line.- Throws:
RDFParseException
-
handleStatement
protected void handleStatement(boolean ignoredAnError) -
parseIRI
-
parseNode
-
createURI
Description copied from class:AbstractRDFParserCreates aIRIobject for the specified URI-string.- Overrides:
createURIin classAbstractRDFParser- Throws:
RDFParseException
-
reportWarning
OverridesAbstractRDFParser.reportWarning(String), adding line number information to the error.- Overrides:
reportWarningin classAbstractRDFParser
-
reportError
OverridesAbstractRDFParser.reportError(String, RioSetting), adding line number information to the error.- Overrides:
reportErrorin classAbstractRDFParser- Parameters:
msg- The message to use forParseErrorListener.error(String, long, long)and forRDFParseException(String, long, long).setting- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)returns true an exception will be thrown.- Throws:
RDFParseException- IfRioConfig.get(RioSetting)returns true, andParserConfig.isNonFatalError(RioSetting)returns true for the given setting.
-
reportError
Description copied from class:AbstractRDFParserReports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseExceptionwhen the given setting has been set to true and it is not a nonFatalError.- Overrides:
reportErrorin classAbstractRDFParser- Parameters:
e- The exception whose message will be used forParseErrorListener.error(String, long, long)and forRDFParseException(String, long, long).setting- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)returns true an exception will be thrown.- Throws:
RDFParseException- IfRioConfig.get(RioSetting)returns true, andParserConfig.isNonFatalError(RioSetting)returns true for the given setting.
-
reportFatalError
OverridesAbstractRDFParser.reportFatalError(String), adding line number information to the error.- Overrides:
reportFatalErrorin classAbstractRDFParser- Throws:
RDFParseException
-
reportFatalError
OverridesAbstractRDFParser.reportFatalError(Exception), adding line number information to the error.- Overrides:
reportFatalErrorin classAbstractRDFParser- Throws:
RDFParseException
-
throwEOFException
- Throws:
RDFParseException
-
clear
protected void clear()Description copied from class:AbstractRDFParserClears any information that has been collected while parsing. This method must be called by subclasses when finishing the parse process.- Overrides:
clearin classAbstractRDFParser
-
getSupportedSettings
- Specified by:
getSupportedSettingsin interfaceRDFParser- Overrides:
getSupportedSettingsin classAbstractRDFParser- Returns:
- A collection of
RioSettings that are supported by this RDFParser.
-
AbstractRDFParser.clear()instead.