Purtle
Fast streaming RDF serializer for PHP
|
Base class for RdfWriter implementations. More...
Public Member Functions | |
__construct ( $role, BNodeLabeler $labeler=null) | |
prefix ( $prefix, $iri) | |
Registers a prefix. | |
getPrefixes () | |
Returns the prefix map. | |
sub () | |
getRole () | |
blank ( $label=null) | |
start () | |
finish () | |
drain () | |
about ( $base, $local=null) | |
a ( $typeBase, $typeLocal=null) | |
say ( $base, $local=null) | |
is ( $base, $local=null) | |
text ( $text, $language=null) | |
value ( $value, $typeBase=null, $typeLocal=null) | |
Public Member Functions inherited from Wikimedia\Purtle\RdfWriter | |
getMimeType () | |
Returns the MIME type of the RDF serialization the writer produces. | |
Public Attributes | |
const | DOCUMENT_ROLE = 'document' |
Role ID for writers that will generate a full RDF document. | |
const | SUBDOCUMENT_ROLE = 'sub' |
Protected Member Functions | |
newSubWriter ( $role, BNodeLabeler $labeler) | |
registerShorthand ( $shorthand, $prefix, $local) | |
Registers a shorthand that can be used instead of a qname, like 'a' can be used instead of 'rdf:type'. | |
isShorthand ( $shorthand) | |
Determines whether $shorthand can be used as a shorthand. | |
isPrefix ( $prefix) | |
Determines whether $shorthand can legally be used as a prefix. | |
isValidLanguageCode ( $languageCode) | |
write ( $w) | |
Appends string to the output buffer. | |
expandShorthand (&$base, &$local) | |
If $base is a shorthand, $base and $local are updated to hold whatever qname the shorthand was associated with. | |
expandQName (&$base, &$local) | |
If $base is a registered prefix, $base will be replaced by the base IRI associated with that prefix, with $local appended. | |
state ( $newState) | |
Perform a state transition. | |
writeSubject ( $base, $local=null) | |
Must be implemented to generate output that starts a statement (or set of statements) about a subject. | |
writePredicate ( $base, $local=null) | |
Must be implemented to generate output that represents the association of a predicate with a subject that was previously defined by a call to writeSubject(). | |
writeResource ( $base, $local=null) | |
Must be implemented to generate output that represents a resource used as the object of a statement. | |
writeText ( $text, $language) | |
Must be implemented to generate output that represents a text used as the object of a statement. | |
writeValue ( $value, $typeBase, $typeLocal=null) | |
Must be implemented to generate output that represents a (typed) literal used as the object of a statement. | |
expandSubject (&$base, &$local) | |
Perform any expansion (shorthand to qname, qname to IRI) desired for subject identifiers. | |
expandPredicate (&$base, &$local) | |
Perform any expansion (shorthand to qname, qname to IRI) desired for predicate identifiers. | |
expandResource (&$base, &$local) | |
Perform any expansion (shorthand to qname, qname to IRI) desired for resource identifiers. | |
expandType (&$base, &$local) | |
Perform any expansion (shorthand to qname, qname to IRI) desired for type identifiers. | |
Protected Attributes | |
const | STATE_START = 0 |
const | STATE_DOCUMENT = 5 |
const | STATE_SUBJECT = 10 |
const | STATE_PREDICATE = 11 |
const | STATE_OBJECT = 12 |
const | STATE_FINISH = 666 |
$prefixes = [] | |
$currentSubject = [ null, null ] | |
$currentPredicate = [ null, null ] | |
$role | |
$transitionTable | |
Base class for RdfWriter implementations.
Subclasses have to implement at least the writeXXX() methods to generate the desired output for the respective RDF constructs. Subclasses may override the startXXX() and finishXXX() methods to generate structural output, and override expandXXX() to transform identifiers.
@license GPL-2.0-or-later
Wikimedia\Purtle\RdfWriterBase::__construct | ( | $role, | |
BNodeLabeler | $labeler = null ) |
string | $role | The writer's role, use the XXX_ROLE constants. |
BNodeLabeler | null | $labeler |
InvalidArgumentException |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
final |
string | $typeBase | The data type's QName prefix if $typeLocal is given, or an IRI or shorthand if $typeLocal is null. |
string | null | $typeLocal | The data type's QName suffix, or null if $typeBase is an IRI or shorthand. |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
string | $base | A QName prefix if $local is given, or an IRI if $local is null. |
string | null | $local | A QName suffix, or null if $base is an IRI. |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
string | null | $label | node label; will be generated if not given. |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
|
protected |
Perform any expansion (shorthand to qname, qname to IRI) desired for predicate identifiers.
string | &$base | |
string | null | &$local |
Reimplemented in Wikimedia\Purtle\NTriplesRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
protected |
If $base is a registered prefix, $base will be replaced by the base IRI associated with that prefix, with $local appended.
$local will be set to null.
Otherwise, $base and $local remain unchanged.
string | &$base | |
string | null | &$local |
LogicException |
|
protected |
Perform any expansion (shorthand to qname, qname to IRI) desired for resource identifiers.
string | &$base | |
string | null | &$local |
Reimplemented in Wikimedia\Purtle\NTriplesRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
protected |
If $base is a shorthand, $base and $local are updated to hold whatever qname the shorthand was associated with.
Otherwise, $base and $local remain unchanged.
string | &$base | |
string | null | &$local |
|
protected |
Perform any expansion (shorthand to qname, qname to IRI) desired for subject identifiers.
string | &$base | |
string | null | &$local |
Reimplemented in Wikimedia\Purtle\NTriplesRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
protected |
Perform any expansion (shorthand to qname, qname to IRI) desired for type identifiers.
string | null | &$base | |
string | null | &$local |
Reimplemented in Wikimedia\Purtle\NTriplesRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
final |
Implements Wikimedia\Purtle\RdfWriter.
Wikimedia\Purtle\RdfWriterBase::getPrefixes | ( | ) |
Returns the prefix map.
|
final |
|
final |
string | $base | A QName prefix if $local is given, or an IRI if $local is null. |
string | null | $local | A QName suffix, or null if $base is an IRI. |
Implements Wikimedia\Purtle\RdfWriter.
|
protected |
Determines whether $shorthand can legally be used as a prefix.
string | $prefix |
|
protected |
Determines whether $shorthand can be used as a shorthand.
string | $shorthand |
|
protected |
string | null | $languageCode |
|
abstractprotected |
string | $role | |
BNodeLabeler | $labeler |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\NTriplesRdfWriter, Wikimedia\Purtle\TurtleRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
Wikimedia\Purtle\RdfWriterBase::prefix | ( | $prefix, | |
$iri ) |
Registers a prefix.
string | $prefix | |
string | $iri | The base IRI |
LogicException |
Implements Wikimedia\Purtle\RdfWriter.
|
protected |
Registers a shorthand that can be used instead of a qname, like 'a' can be used instead of 'rdf:type'.
string | $shorthand | |
string | $prefix | |
string | $local |
|
final |
string | $base | A QName prefix. |
string | null | $local | A QName suffix. |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
Implements Wikimedia\Purtle\RdfWriter.
|
finalprotected |
Perform a state transition.
Writer states roughly correspond to states in a naive regular parser for the respective syntax. State transitions may generate output, particularly of structural elements which correspond to terminals in a respective parser.
int | $newState | one of the self::STATE_... constants |
LogicException |
|
final |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
string | $text | the text to be placed in the output |
string | null | $language | the language the text is in |
Implements Wikimedia\Purtle\RdfWriter.
|
final |
string | $value | the value encoded as a string |
string | null | $typeBase | The data type's QName prefix if $typeLocal is given, or an IRI or shorthand if $typeLocal is null. |
string | null | $typeLocal | The data type's QName suffix, or null if $typeBase is an IRI or shorthand. |
Implements Wikimedia\Purtle\RdfWriter.
|
finalprotected |
Appends string to the output buffer.
string | $w |
|
abstractprotected |
Must be implemented to generate output that represents the association of a predicate with a subject that was previously defined by a call to writeSubject().
string | $base | |
string | null | $local |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\NTriplesRdfWriter, Wikimedia\Purtle\TurtleRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
abstractprotected |
Must be implemented to generate output that represents a resource used as the object of a statement.
string | $base | |
string | null | $local |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\NTriplesRdfWriter, Wikimedia\Purtle\TurtleRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
abstractprotected |
Must be implemented to generate output that starts a statement (or set of statements) about a subject.
Depending on the requirements of the output format, the implementation may be empty.
string | $base | |
string | null | $local |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\NTriplesRdfWriter, Wikimedia\Purtle\TurtleRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
abstractprotected |
Must be implemented to generate output that represents a text used as the object of a statement.
string | $text | the text to be placed in the output |
string | null | $language | the language the text is in |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\N3RdfWriterBase, Wikimedia\Purtle\NTriplesRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
|
abstractprotected |
Must be implemented to generate output that represents a (typed) literal used as the object of a statement.
string | $value | the value encoded as a string |
string | null | $typeBase | |
string | null | $typeLocal |
Reimplemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\XmlRdfWriter, Wikimedia\Purtle\N3RdfWriterBase, and Wikimedia\Purtle\NTriplesRdfWriter.
|
protected |