The management of literals in Virtuoso can be achieved through the use of a ‘literal class’, which provides a structured way to handle data transformations between SQL and RDF formats. Although this is not extensively documented, examples from the RDF-H test suite and the MusicBrainz demo illustrate the concept well.
Example from RDF-H Test Suite
In the RDF-H test suite, a literal class is defined using functions for mapping and inverse mapping. The CREATE LITERAL CLASS
statement establishes a new literal class with these functions. The mapping function converts an SQL integer to a formatted literal string, using sprintf
to create a URI-like structure based on the user’s role. The inverse mapping function performs the reverse operation, converting a formatted literal back into an SQL integer, ensuring it matches the column value in the SQL table.
Example from MusicBrainz Demo
The MusicBrainz demo provides a clearer example of how a literal class is defined and the purpose of the PL mapping functions. In this example, the mapping function appends a time component to a date string, converting it into a xsd:dateTime
format. The inverse mapping function removes the time component, converting the xsd:dateTime
back to a simple date string.
Additionally, the literal class can have options to declare a datatype or language. For instance, you can specify the datatype for the literal, such as xsd:dateTime
, or a language tag for string literals.
Understanding IRI Classes
IRI Classes in Virtuoso are used to define how SQL data is mapped to RDF IRIs (Internationalized Resource Identifiers) and vice versa. They play a crucial role in ensuring that each SQL entity is uniquely represented in RDF format. The purpose of an IRI Class is to maintain a consistent and unique mapping between SQL data and RDF IRIs, which is essential for data integration and interoperability in semantic web applications.
- Nature of IRI Classes: IRI Classes define the transformation rules for converting SQL data into RDF IRIs. This involves specifying how SQL identifiers are translated into unique RDF identifiers, ensuring that each SQL entity corresponds to a distinct RDF IRI.
- Purpose of IRI Classes: The primary purpose of IRI Classes is to facilitate seamless data exchange between SQL databases and RDF-based systems. By defining a one-to-one mapping, IRI Classes ensure that data integrity is maintained across different data representations.
Summary of Options
The following options are applicable:
- IRI Class Options:
BIJECTION
: Ensures a one-to-one mapping between SQL and RDF representations, meaning each SQL value corresponds to a unique RDF representation and vice versa.
RETURNS
: Specifies expected sprintf
patterns for the IRI, allowing for flexible and precise IRI generation.
- Literal Class Options:
BIJECTION
: Similar to IRI classes, ensures a one-to-one mapping between SQL literals and RDF literals.
DATATYPE <dt_iri>
: Declares the datatype of the literal.
LANG "lang_tag"
: Specifies the language tag for string literals.
RETURNS
: Uses special syntax for possible sprintf
patterns, allowing multiple patterns with a union, such as OPTION( RETURNS 'sprintf_pattern_1' union 'sprintf_pattern_2' )
.
Example:
An example of using the RETURNS
option is OPTION (bijection, returns "http://%U/sys/group?id=%d" union "http://%U/sys/member?id=%d")
, which specifies multiple patterns for mapping.
Conclusion:
The syntax provides a mechanism to map literals to another form using sprintf
-like functions and an inverse function to convert from an external format back to an SQL value. This approach allows for flexible handling of literals, including date values with timezones, by defining custom mapping logic and specifying options for datatype and language. IRI Classes, in particular, ensure that SQL data is accurately and uniquely represented in RDF format, supporting robust data integration and interoperability.