Purtle
Fast streaming RDF serializer for PHP
|
Writer interface for RDF output. More...
Public Member Functions | |
blank ( $label=null) | |
Returns the local name of a blank node, for use with the "_" prefix. | |
start () | |
Start the document. | |
finish () | |
Finish the document. | |
drain () | |
Generates an RDF string from the current buffers state and returns it. | |
prefix ( $prefix, $iri) | |
Declare a prefix for later use. | |
about ( $base, $local=null) | |
Start an "about" (subject) clause, given a subject. | |
say ( $base, $local=null) | |
Start a predicate clause. | |
is ( $base, $local=null) | |
Produce a resource as the object of a statement. | |
text ( $text, $language=null) | |
Produce a text literal as the object of a statement. | |
value ( $value, $typeBase=null, $typeLocal=null) | |
Produce a typed or untyped literal as the object of a statement. | |
a ( $typeBase, $typeLocal=null) | |
Shorthand for say( 'a' )->is( $type ). | |
sub () | |
Returns a document-level sub-writer. | |
getMimeType () | |
Returns the MIME type of the RDF serialization the writer produces. | |
Writer interface for RDF output.
RdfWriter instances are generally stateful, but should be implemented to operate in a stream-like manner with a minimum of state.
This is intended to provide a "fluent interface" that allows programmers to use a turtle-like structure when generating RDF output. E.g.:
To get the generated RDF output, use the drain() method.
Caveats:
@license GPL-2.0-or-later
Wikimedia\Purtle\RdfWriter::a | ( | $typeBase, | |
$typeLocal = null ) |
Shorthand for say( 'a' )->is( $type ).
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. |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::about | ( | $base, | |
$local = null ) |
Start an "about" (subject) clause, given a subject.
Can occur at the beginning odf the output sequence, but can later only follow a call to is(), text(), or value(). Should fail if called at an inappropriate time in the output sequence.
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. |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::blank | ( | $label = null | ) |
Returns the local name of a blank node, for use with the "_" prefix.
string | null | $label | node label, will be generated if not given. |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::drain | ( | ) |
Generates an RDF string from the current buffers state and returns it.
The buffer is reset to the empty state. Before the result string is generated, implementations should close any pending syntactical structures (close tags, generate footers, etc).
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::finish | ( | ) |
Finish the document.
May generate a footer.
This will detach all sub-writers that had earlier been returned by sub().
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::getMimeType | ( | ) |
Returns the MIME type of the RDF serialization the writer produces.
Implemented in Wikimedia\Purtle\JsonLdRdfWriter, Wikimedia\Purtle\NTriplesRdfWriter, Wikimedia\Purtle\TurtleRdfWriter, and Wikimedia\Purtle\XmlRdfWriter.
Wikimedia\Purtle\RdfWriter::is | ( | $base, | |
$local = null ) |
Produce a resource as the object of a statement.
Can only follow a call to say() or a call to one of is(), text(), or value(). Should fail if called at an inappropriate time in the output sequence.
string | $base | A QName prefix if $local is given, or an IRI or shorthand if $local is null. |
string | null | $local | A QName suffix, or null if $base is an IRI or shorthand. |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::prefix | ( | $prefix, | |
$iri ) |
Declare a prefix for later use.
Prefixes should be declared before being used. Should not be called after start().
string | $prefix | |
string | $iri | a IRI |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::say | ( | $base, | |
$local = null ) |
Start a predicate clause.
Can only follow a call to about() or say(). Should fail if called at an inappropriate time in the output sequence.
string | $base | A QName prefix if $local is given, or a shorthand. MUST NOT be an IRI. |
string | null | $local | A QName suffix, or null if $base is a shorthand. |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::start | ( | ) |
Wikimedia\Purtle\RdfWriter::sub | ( | ) |
Returns a document-level sub-writer.
This can be used to generate parts statements out of sequence. Output generated by the sub-writer will be present in the return value of drain(), after any output generated by this writer itself.
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::text | ( | $text, | |
$language = null ) |
Produce a text literal as the object of a statement.
Can only follow a call to say() or a call to one of is(), text(), or value(). Should fail if called at an inappropriate time in the output sequence.
string | $text | the text to be placed in the output |
string | null | $language | the language the text is in |
Implemented in Wikimedia\Purtle\RdfWriterBase.
Wikimedia\Purtle\RdfWriter::value | ( | $value, | |
$typeBase = null, | |||
$typeLocal = null ) |
Produce a typed or untyped literal as the object of a statement.
Can only follow a call to say() or a call to one of is(), text(), or value(). Should fail if called at an inappropriate time in the output sequence.
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. |
Implemented in Wikimedia\Purtle\RdfWriterBase.