RDF API tutorials
The following examples illustrate RDF API usage.
Language-tagged literals
To create language-tagged plain literals, you can use the rdf_literal() API function as follows:
<?php
rdf_literal('Hello!', 'en');
rdf_literal('Wazup?', 'en-US');
rdf_literal('¡Hola!', 'es');
?>Datatyped literals
When dealing with datatyped literals, RDF API functions allow you to work with standard PHP types for those cases where an obvious mapping exists between the PHP type and an equivalent XML Schema type; these are as follows:
- boolean
- XSD serialization: xsd:boolean
- XSD unserialization: xsd:boolean
- integer
- XSD serialization: xsd:integer
- XSD unserialization: xsd:integer, xsd:long, xsd:unsignedLong, xsd:unsignedInt
- double
- XSD serialization: xsd:double
- XSD unserialization: xsd:double, xsd:float, xs:decimal
- string
- XSD serialization: xsd:string
- XSD unserialization: xsd:string, xsd:normalizedString, xsd:token, xsd:language
For dealing with any other datatyped literals, wrap the lexical representation using rdf_literal(); some examples follow.
Base-64 encoded data
<?php
rdf_literal(base64_encode($text), NULL, xsd::base64Binary);
?>Dates and times
<?php
rdf_literal('2007-12-31T23:59:59Z', NULL, xsd::dateTime);
rdf_literal('2007-12-31', NULL, xsd::date);
rdf_literal('23:59:59.123-06:00', NULL, xsd::time);
?>