org.openrdf.rio.turtle
Class TurtleParser

java.lang.Object
  extended by org.openrdf.rio.helpers.RDFParserBase
      extended by org.openrdf.rio.turtle.TurtleParser
All Implemented Interfaces:
RDFParser
Direct Known Subclasses:
TriGParser

public class TurtleParser
extends RDFParserBase

RDF parser for Turtle files. This parser is not thread-safe, therefore its public methods are synchronized.

This implementation is based on the 2006/01/02 version of the Turtle specification, with slight deviations:

Author:
Arjohn Kampman

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openrdf.rio.RDFParser
RDFParser.DatatypeHandling
 
Field Summary
 
Fields inherited from class org.openrdf.rio.helpers.RDFParserBase
rdfHandler
 
Constructor Summary
TurtleParser()
          Creates a new TurtleParser that will use a ValueFactoryImpl to create RDF model objects.
TurtleParser(ValueFactory valueFactory)
          Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects.
 
Method Summary
 RDFFormat getRDFFormat()
          Gets the RDF format that this parser can parse.
 void parse(InputStream in, String baseURI)
          Implementation of the parse(InputStream, String) method defined in the RDFParser interface.
 void parse(Reader reader, String baseURI)
          Implementation of the parse(Reader, String) method defined in the RDFParser interface.
protected  void parseBase()
           
protected  Resource parseCollection()
          Parses a collection, e.g.
protected  void parseDirective()
           
protected  Resource parseImplicitBlank()
          Parses an implicit blank node.
protected  String parseLongString()
          Parses a """long string""".
protected  BNode parseNodeID()
          Parses a blank node ID, e.g.
protected  Literal parseNumber()
           
protected  void parseObject()
           
protected  void parseObjectList()
           
protected  URI parsePredicate()
           
protected  void parsePredicateObjectList()
           
protected  void parsePrefixID()
           
protected  Value parseQNameOrBoolean()
          Parses qnames and boolean values, which have equivalent starting characters.
protected  Literal parseQuotedLiteral()
          Parses a quoted string, optionally followed by a language tag or datatype.
protected  String parseQuotedString()
          Parses a quoted string, which is either a "normal string" or a """long string""".
protected  void parseStatement()
           
protected  String parseString()
          Parses a "normal string".
protected  void parseSubject()
           
protected  void parseTriples()
           
protected  URI parseURI()
           
protected  Value parseValue()
          Parses an RDF value.
protected  int peek()
           
protected  int read()
           
protected  void reportError(String msg)
          Overrides RDFParserBase.reportError(String), adding line number information to the error.
protected  void reportFatalError(Exception e)
          Overrides RDFParserBase.reportFatalError(Exception), adding line number information to the error.
protected  void reportFatalError(String msg)
          Overrides RDFParserBase.reportFatalError(String), adding line number information to the error.
protected  void reportLocation()
           
protected  void reportStatement(Resource subj, URI pred, Value obj)
           
protected  void reportWarning(String msg)
          Overrides RDFParserBase.reportWarning(String), adding line number information to the error.
protected  void skipLine()
          Consumes characters from reader until the first EOL has been read.
protected  int skipWSC()
          Consumes any white space characters (space, tab, line feed, newline) and comments (#-style) from reader.
protected  void throwEOFException()
           
protected  void unread(int c)
           
protected  void verifyCharacter(int c, String expected)
          Verifies that the supplied character c is one of the expected characters specified in expected.
 
Methods inherited from class org.openrdf.rio.helpers.RDFParserBase
clear, clearBNodeIDMap, createBNode, createBNode, createLiteral, createStatement, createStatement, createURI, datatypeHandling, getNamespace, getParseErrorListener, getParseLocationListener, getRDFHandler, preserveBNodeIDs, reportError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, setBaseURI, setBaseURI, setDatatypeHandling, setNamespace, setParseErrorListener, setParseLocationListener, setPreserveBNodeIDs, setRDFHandler, setStopAtFirstError, setValueFactory, setVerifyData, stopAtFirstError, verifyData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurtleParser

public TurtleParser()
Creates a new TurtleParser that will use a ValueFactoryImpl to create RDF model objects.


TurtleParser

public TurtleParser(ValueFactory valueFactory)
Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects.

Parameters:
valueFactory - A ValueFactory.
Method Detail

getRDFFormat

public RDFFormat getRDFFormat()
Description copied from interface: RDFParser
Gets the RDF format that this parser can parse.


parse

public void parse(InputStream in,
                  String baseURI)
           throws IOException,
                  RDFParseException,
                  RDFHandlerException
Implementation of the parse(InputStream, String) method defined in the RDFParser interface.

Parameters:
in - The InputStream from which to read the data, must not be null. The InputStream is supposed to contain UTF-8 encoded Unicode characters, as per the Turtle specification.
baseURI - The URI associated with the data in the InputStream, must not be null.
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 encountered an unrecoverable error.
IllegalArgumentException - If the supplied input stream or base URI is null.

parse

public void parse(Reader reader,
                  String baseURI)
           throws IOException,
                  RDFParseException,
                  RDFHandlerException
Implementation of the parse(Reader, String) method defined in the RDFParser interface.

Parameters:
reader - The Reader from which to read the data, must not be null.
baseURI - The URI associated with the data in the Reader, must not be null.
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 encountered an unrecoverable error.
IllegalArgumentException - If the supplied reader or base URI is null.

parseStatement

protected void parseStatement()
                       throws IOException,
                              RDFParseException,
                              RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseDirective

protected void parseDirective()
                       throws IOException,
                              RDFParseException,
                              RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parsePrefixID

protected void parsePrefixID()
                      throws IOException,
                             RDFParseException,
                             RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseBase

protected void parseBase()
                  throws IOException,
                         RDFParseException,
                         RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseTriples

protected void parseTriples()
                     throws IOException,
                            RDFParseException,
                            RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parsePredicateObjectList

protected void parsePredicateObjectList()
                                 throws IOException,
                                        RDFParseException,
                                        RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseObjectList

protected void parseObjectList()
                        throws IOException,
                               RDFParseException,
                               RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseSubject

protected void parseSubject()
                     throws IOException,
                            RDFParseException,
                            RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parsePredicate

protected URI parsePredicate()
                      throws IOException,
                             RDFParseException
Throws:
IOException
RDFParseException

parseObject

protected void parseObject()
                    throws IOException,
                           RDFParseException,
                           RDFHandlerException
Throws:
IOException
RDFParseException
RDFHandlerException

parseCollection

protected Resource parseCollection()
                            throws IOException,
                                   RDFParseException,
                                   RDFHandlerException
Parses a collection, e.g. ( item1 item2 item3 ).

Throws:
IOException
RDFParseException
RDFHandlerException

parseImplicitBlank

protected Resource parseImplicitBlank()
                               throws IOException,
                                      RDFParseException,
                                      RDFHandlerException
Parses an implicit blank node. This method parses the token [] and predicateObjectLists that are surrounded by square brackets.

Throws:
IOException
RDFParseException
RDFHandlerException

parseValue

protected Value parseValue()
                    throws IOException,
                           RDFParseException
Parses an RDF value. This method parses uriref, qname, node ID, quoted literal, integer, double and boolean.

Throws:
IOException
RDFParseException

parseQuotedLiteral

protected Literal parseQuotedLiteral()
                              throws IOException,
                                     RDFParseException
Parses a quoted string, optionally followed by a language tag or datatype.

Throws:
IOException
RDFParseException

parseQuotedString

protected String parseQuotedString()
                            throws IOException,
                                   RDFParseException
Parses a quoted string, which is either a "normal string" or a """long string""".

Throws:
IOException
RDFParseException

parseString

protected String parseString()
                      throws IOException,
                             RDFParseException
Parses a "normal string". This method assumes that the first double quote has already been parsed.

Throws:
IOException
RDFParseException

parseLongString

protected String parseLongString()
                          throws IOException,
                                 RDFParseException
Parses a """long string""". This method assumes that the first three double quotes have already been parsed.

Throws:
IOException
RDFParseException

parseNumber

protected Literal parseNumber()
                       throws IOException,
                              RDFParseException
Throws:
IOException
RDFParseException

parseURI

protected URI parseURI()
                throws IOException,
                       RDFParseException
Throws:
IOException
RDFParseException

parseQNameOrBoolean

protected Value parseQNameOrBoolean()
                             throws IOException,
                                    RDFParseException
Parses qnames and boolean values, which have equivalent starting characters.

Throws:
IOException
RDFParseException

parseNodeID

protected BNode parseNodeID()
                     throws IOException,
                            RDFParseException
Parses a blank node ID, e.g. _:node1.

Throws:
IOException
RDFParseException

reportStatement

protected void reportStatement(Resource subj,
                               URI pred,
                               Value obj)
                        throws RDFParseException,
                               RDFHandlerException
Throws:
RDFParseException
RDFHandlerException

verifyCharacter

protected void verifyCharacter(int c,
                               String expected)
                        throws RDFParseException
Verifies that the supplied character c is one of the expected characters specified in expected. This method will throw a ParseException if this is not the case.

Throws:
RDFParseException

skipWSC

protected int skipWSC()
               throws IOException
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 that will be returned by reader.
Throws:
IOException

skipLine

protected void skipLine()
                 throws IOException
Consumes characters from reader until the first EOL has been read.

Throws:
IOException

read

protected int read()
            throws IOException
Throws:
IOException

unread

protected void unread(int c)
               throws IOException
Throws:
IOException

peek

protected int peek()
            throws IOException
Throws:
IOException

reportLocation

protected void reportLocation()

reportWarning

protected void reportWarning(String msg)
Overrides RDFParserBase.reportWarning(String), adding line number information to the error.

Overrides:
reportWarning in class RDFParserBase

reportError

protected void reportError(String msg)
                    throws RDFParseException
Overrides RDFParserBase.reportError(String), adding line number information to the error.

Overrides:
reportError in class RDFParserBase
Throws:
RDFParseException
See Also:
RDFParserBase.setStopAtFirstError(boolean)

reportFatalError

protected void reportFatalError(String msg)
                         throws RDFParseException
Overrides RDFParserBase.reportFatalError(String), adding line number information to the error.

Overrides:
reportFatalError in class RDFParserBase
Throws:
RDFParseException

reportFatalError

protected void reportFatalError(Exception e)
                         throws RDFParseException
Overrides RDFParserBase.reportFatalError(Exception), adding line number information to the error.

Overrides:
reportFatalError in class RDFParserBase
Throws:
RDFParseException

throwEOFException

protected void throwEOFException()
                          throws RDFParseException
Throws:
RDFParseException


Copyright © 2001-2008 Aduna. All Rights Reserved.