class Turtle extends Ntriples

Class to parse Turtle with no external dependencies.

It is a translation from Java to PHP of the Sesame Turtle Parser: http://bit.ly/TurtleParser

Lasted updated against version: ecda6a15a200a2fc6a062e2e43081257c3ccd4e6 (Mon Jul 29 12:05:58 2013)

Properties

protected Graph $graph from Parser
protected $format The format of the document currently being parsed from Parser
protected $baseUri The base URI for the document currently being parsed from Parser
protected $tripleCount from Parser
protected $data
protected $namespaces
protected $subject
protected $predicate
protected $object
protected $line
protected $column
protected $bytePos
protected $dataLength

Methods

remapBnode($name)

Create a new, unique bnode identifier from a source identifier.

from Parser
resetBnodeMap()

Delete the bnode mapping - to be called at the start of a new parse

from Parser
checkParseParams($graph, $data, $format, $baseUri)

Check, cleanup parameters and prepare for parsing

from Parser
parse($graph, $data, $format, $baseUri)

Parse Turtle into an Graph

addTriple($resource, $property, $value)

Add a triple to the current graph, and keep count of the number of triples

from Parser
string
unescapeString(string $str)

Decodes an encoded N-Triples string. Any -escape sequences are substituted with their decoded value.

from Ntriples
parseNtriplesSubject($sub, $lineNum)

No description

from Ntriples
parseNtriplesObject($obj, $lineNum)

No description

from Ntriples
__construct()

Constructor

parseStatement()

Parse a statement [2]

parseDirective($directive)

Parse a directive [3]

parsePrefixID()

Parse a prefixID [4]

parseBase()

Parse base [5]

parseTriples()

Parse triples [6] modified to use a pointer instead of manipulating the input buffer directly.

parsePredicateObjectList()

Parse a predicateObjectList [7]

parseObjectList()

Parse a objectList [8]

parseSubject()

Parse a subject [10]

parsePredicate()

Parse a predicate [11]

parseObject()

Parse a object [12]

parseImplicitBlank()

Parses a blankNodePropertyList [15]

parseCollection()

Parses a collection [16], e.g: ( item1 item2 item3 )

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""".

string
parseString(string $closingCharacter)

Parses a "normal string". This method requires that the opening character has already been parsed.

string
parseLongString(string $closingCharacter)

Parses a """long string""". This method requires that the first three characters have already been parsed.

parseNumber()

Parses a numeric value, either of type integer, decimal or double

parseURI()

Parses a URI / IRI

parseQNameOrBoolean()

Parses qnames and boolean values, which have equivalent starting characters.

readLocalEscapedChar()

No description

parseNodeID()

Parses a blank node ID, e.g: _:node1

resolve($uri)

No description

verifyCharacterOrFail($c, $expected)

Verifies that the supplied character $c is one of the expected characters specified in $expected. This method will throw a exception if this is not the case.

skipWSC()

Skip through whitespace and comments

processComment()

Consumes characters from reader until the first EOL has been read.

read()

Read a single character from the input buffer.

peek()

Gets the next character to be returned by read() without moving the pointer position. Speeds up the mb_substr() call by only giving it the next 4 bytes to parse.

unread($chars)

Steps back, restoring the previous character read() to the input buffer

unskipWS()

Reverse skips through whitespace in 4 byte increments.

createBNode()

No description

static 
isWhitespace($c)

Returns true if $c is a whitespace character

static 
isPrefixStartChar($c)

No description

static 
isNameStartChar($c)

No description

static 
isNameChar($c)

No description

static 
isLocalEscapedChar($c)

No description

static 
isPrefixChar($c)

No description

static 
isLanguageStartChar($c)

No description

static 
isLanguageChar($c)

No description

Details

in Parser at line 70
protected remapBnode($name)

Create a new, unique bnode identifier from a source identifier.

If the source identifier has previously been seen, the same new bnode identifier is returned.

Parameters

$name

in Parser at line 82
protected resetBnodeMap()

Delete the bnode mapping - to be called at the start of a new parse

in Parser at line 91
protected checkParseParams($graph, $data, $format, $baseUri)

Check, cleanup parameters and prepare for parsing

Parameters

$graph
$data
$format
$baseUri

at line 91
parse($graph, $data, $format, $baseUri)

Parse Turtle into an Graph

Parameters

$graph
$data
$format
$baseUri

Exceptions

Exception

in Parser at line 148
protected addTriple($resource, $property, $value)

Add a triple to the current graph, and keep count of the number of triples

Parameters

$resource
$property
$value

in Ntriples at line 58
protected string unescapeString(string $str)

Decodes an encoded N-Triples string. Any -escape sequences are substituted with their decoded value.

Parameters

string $str An encoded N-Triples string.

Return Value

string The unencoded string.

in Ntriples at line 110
protected parseNtriplesSubject($sub, $lineNum)

Parameters

$sub
$lineNum

in Ntriples at line 132
protected parseNtriplesObject($obj, $lineNum)

Parameters

$obj
$lineNum

at line 76
__construct()

Constructor

at line 129
protected parseStatement()

Parse a statement [2]

at line 161
protected parseDirective($directive)

Parse a directive [3]

Parameters

$directive

at line 187
protected parsePrefixID()

Parse a prefixID [4]

at line 227
protected parseBase()

Parse base [5]

at line 240
protected parseTriples()

Parse triples [6] modified to use a pointer instead of manipulating the input buffer directly.

at line 284
protected parsePredicateObjectList()

Parse a predicateObjectList [7]

at line 315
protected parseObjectList()

Parse a objectList [8]

at line 330
protected parseSubject()

Parse a subject [10]

at line 356
protected parsePredicate()

Parse a predicate [11]

at line 394
protected parseObject()

Parse a object [12]

at line 421
protected parseImplicitBlank()

Parses a blankNodePropertyList [15]

This method parses the token [] and predicateObjectLists that are surrounded by square brackets.

at line 460
protected parseCollection()

Parses a collection [16], e.g: ( item1 item2 item3 )

at line 531
protected parseValue()

Parses an RDF value. This method parses uriref, qname, node ID, quoted literal, integer, double and boolean.

at line 569
protected parseQuotedLiteral()

Parses a quoted string, optionally followed by a language tag or datatype.

at line 655
protected parseQuotedString()

Parses a quoted string, which is either a "normal string" or a """long string""".

at line 693
protected string parseString(string $closingCharacter)

Parses a "normal string". This method requires that the opening character has already been parsed.

Parameters

string $closingCharacter The type of quote to use (either ' or ")

Return Value

string

Exceptions

Exception

at line 739
protected string parseLongString(string $closingCharacter)

Parses a """long string""". This method requires that the first three characters have already been parsed.

Parameters

string $closingCharacter The type of quote to use (either ' or ")

Return Value

string

Exceptions

Exception

at line 782
protected parseNumber()

Parses a numeric value, either of type integer, decimal or double

at line 881
protected parseURI()

Parses a URI / IRI

at line 932
protected parseQNameOrBoolean()

Parses qnames and boolean values, which have equivalent starting characters.

at line 1031
protected readLocalEscapedChar()

at line 1050
protected parseNodeID()

Parses a blank node ID, e.g: _:node1

at line 1088
protected resolve($uri)

Parameters

$uri

at line 1103
protected verifyCharacterOrFail($c, $expected)

Verifies that the supplied character $c is one of the expected characters specified in $expected. This method will throw a exception if this is not the case.

Parameters

$c
$expected

at line 1133
protected skipWSC()

Skip through whitespace and comments

at line 1152
protected processComment()

Consumes characters from reader until the first EOL has been read.

at line 1178
protected read()

Read a single character from the input buffer.

Returns -1 when the end of the file is reached. Does not manipulate the data variable. Keeps track of the byte position instead.

at line 1201
protected peek()

Gets the next character to be returned by read() without moving the pointer position. Speeds up the mb_substr() call by only giving it the next 4 bytes to parse.

at line 1218
protected unread($chars)

Steps back, restoring the previous character read() to the input buffer

Parameters

$chars

at line 1235
protected unskipWS()

Reverse skips through whitespace in 4 byte increments.

(Keeps the byte pointer accurate when unreading.)

at line 1253
protected createBNode()

at line 1265
static isWhitespace($c)

Returns true if $c is a whitespace character

Parameters

$c

at line 1272
static isPrefixStartChar($c)

Parameters

$c

at line 1293
static isNameStartChar($c)

Parameters

$c

at line 1305
static isNameChar($c)

Parameters

$c

at line 1324
static isLocalEscapedChar($c)

Parameters

$c

at line 1330
static isPrefixChar($c)

Parameters

$c

at line 1344
static isLanguageStartChar($c)

Parameters

$c

at line 1353
static isLanguageChar($c)

Parameters

$c