Package org.eclipse.rdf4j.rio.turtle
Class TurtleParser
java.lang.Object
org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
org.eclipse.rdf4j.rio.turtle.TurtleParser
- All Implemented Interfaces:
RDFParser
- Direct Known Subclasses:
N3Parser,TriGParser,TurtleStarParser
RDF parser for RDF-1.1 Turtle files. This parser is not thread-safe,
therefore its public methods are synchronized.
Normalization of integer, floating point and boolean values is dependent on the specified datatype handling.
According to the specification, integers and booleans should be normalized, but floats don't.
Comments can be used anywhere in the document, and extend to the end of the line. The Turtle grammar doesn't
allow comments to be used inside triple constructs that extend over multiple lines, but the author's own parser
deviates from this too.
- Author:
- Arjohn Kampman, Peter Ansell
-
Field Summary
FieldsFields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
rdfHandler, valueFactory -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TurtleParser that will use aSimpleValueFactoryto create RDF model objects.TurtleParser(ValueFactory valueFactory) Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects. -
Method Summary
Modifier and TypeMethodDescriptionprotected intGets the RDF format that this parser can parse.Collection<RioSetting<?>>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 voidprotected voidprotected ResourceParses a collection, e.g.protected voidparseDirective(String directive) protected ResourceParses an implicit blank node.protected StringparseLongString(int closingCharacter) Parses a """long string""".protected ResourceParses a blank node ID, e.g.protected Literalprotected voidParse an objectprotected voidprotected IRIprotected voidprotected voidprotected ValueParses qnames and boolean values, which have equivalent starting characters.protected LiteralParses a quoted string, optionally followed by a language tag or datatype.protected StringParses a quoted string, which is either a "normal string" or a """long string""".protected voidprotected StringparseString(int closingCharacter) Parses a "normal string".protected voidprotected voidprotected TripleParser an RDF-star triple value and returns it.protected IRIparseURI()protected ValueParses an RDF value.protected intPeeks at the next Unicode code point without advancing the reader, and returns its value.protected booleanPeeks at the next two Unicode code points without advancing the reader and returns true if they indicate the start of an RDF-star triple value.protected voidConsumes characters from reader until the first EOL has been read.protected intReads the next Unicode code point.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 voidprotected voidreportStatement(Resource subj, IRI pred, Value obj) protected voidreportWarning(String msg) OverridesAbstractRDFParser.reportWarning(String), adding line number information to the error.protected intskipWSC()Consumes any white space characters (space, tab, line feed, newline) and comments (#-style) from reader.protected voidprotected voidunread(int codePoint) Pushes back a single code point by copying it to the front of the buffer.protected voidPushes back the supplied string by copying it to the front of the buffer.protected voidverifyCharacterOrFail(int codePoint, String expected) Verifies that the supplied character code point codePoint is one of the expected characters specified in expected.Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
clear, clearBNodeIDMap, createBNode, createBNode, createLiteral, createLiteral, createNode, createNode, createStatement, createStatement, createURI, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, set, setBaseURI, setBaseURI, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setValueFactory
-
Field Details
-
subject
-
predicate
-
object
-
-
Constructor Details
-
TurtleParser
public TurtleParser()Creates a new TurtleParser that will use aSimpleValueFactoryto create RDF model objects. -
TurtleParser
Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects.- Parameters:
valueFactory- A ValueFactory.
-
-
Method Details
-
getRDFFormat
Description copied from interface:RDFParserGets the RDF format that this parser can parse. -
getSupportedSettings
- Specified by:
getSupportedSettingsin interfaceRDFParser- Overrides:
getSupportedSettingsin classAbstractRDFParser- Returns:
- A collection of
RioSettings that are supported by this RDFParser.
-
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
-
parseDirective
protected void parseDirective(String directive) throws IOException, RDFParseException, RDFHandlerException -
parsePrefixID
-
parseBase
-
parseTriples
-
parsePredicateObjectList
protected void parsePredicateObjectList() throws IOException, RDFParseException, RDFHandlerException -
parseObjectList
-
parseSubject
-
parsePredicate
-
parseObject
Parse an object -
parseCollection
Parses a collection, e.g. ( item1 item2 item3 ). -
parseImplicitBlank
Parses an implicit blank node. This method parses the token [] and predicateObjectLists that are surrounded by square brackets. -
parseValue
Parses an RDF value. This method parses uriref, qname, node ID, quoted literal, integer, double and boolean. -
parseQuotedLiteral
Parses a quoted string, optionally followed by a language tag or datatype. -
parseQuotedString
Parses a quoted string, which is either a "normal string" or a """long string""".- Returns:
- string
- Throws:
IOExceptionRDFParseException
-
parseString
Parses a "normal string". This method requires that the opening character has already been parsed.- Returns:
- parsed string
- Throws:
IOExceptionRDFParseException
-
parseLongString
Parses a """long string""". This method requires that the first three characters have already been parsed.- Throws:
IOExceptionRDFParseException
-
parseNumber
- Throws:
IOExceptionRDFParseException
-
parseURI
- Throws:
IOExceptionRDFParseException
-
parseQNameOrBoolean
Parses qnames and boolean values, which have equivalent starting characters.- Throws:
IOExceptionRDFParseException
-
parseNodeID
Parses a blank node ID, e.g. _:node1.- Throws:
IOExceptionRDFParseException
-
reportStatement
protected void reportStatement(Resource subj, IRI pred, Value obj) throws RDFParseException, RDFHandlerException - Throws:
RDFParseExceptionRDFHandlerException
-
verifyCharacterOrFail
Verifies that the supplied character code point codePoint is one of the expected characters specified in expected. This method will throw a ParseException if this is not the case.- Throws:
RDFParseException
-
skipWSC
Consumes any white space characters (space, tab, line feed, newline) and comments (#-style) from reader. After this method has been called, the first character that is returned by reader is either a non-ignorable character, or EOF. For convenience, this character is also returned by this method.- Returns:
- The next character code point that will be returned by reader.
- Throws:
IOExceptionRDFHandlerException
-
processComment
Consumes characters from reader until the first EOL has been read. This line of text is then passed to theAbstractRDFParser.rdfHandleras a comment.- Throws:
IOExceptionRDFHandlerException
-
readCodePoint
Reads the next Unicode code point.- Returns:
- the next Unicode code point, or -1 if the end of the stream has been reached.
- Throws:
IOException
-
unread
Pushes back a single code point by copying it to the front of the buffer. After this method returns, a call toreadCodePoint()will return the same code point c again.- Parameters:
codePoint- a single Unicode code point.- Throws:
IOException
-
unread
Pushes back the supplied string by copying it to the front of the buffer. After this method returns, successive calls toreadCodePoint()will return the code points in the supplied string again, starting at the first in the String..- Parameters:
string- the string to un-read.- Throws:
IOException
-
peekCodePoint
Peeks at the next Unicode code point without advancing the reader, and returns its value.- Returns:
- the next Unicode code point, or -1 if the end of the stream has been reached.
- Throws:
IOException
-
reportLocation
protected void reportLocation() -
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.
-
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
-
getLineNumber
protected int getLineNumber() -
peekIsTripleValue
Peeks at the next two Unicode code points without advancing the reader and returns true if they indicate the start of an RDF-star triple value. Such values start with '<<'.- Returns:
- true if the next code points indicate the beginning of an RDF-star triple value, false otherwise
- Throws:
IOException
-
parseTripleValue
Parser an RDF-star triple value and returns it.- Returns:
- An RDF-star triple.
- Throws:
IOException
-
parseAnnotation
- Throws:
IOException
-