Datatyping Models
Datatyping models represent the property of orderedness that literals like dates and numbers possess. They are used to constrain results to be above, below, or between specified dates or numbers.
Datatyping models are generally read-only. You do not insert statements into them as you do with standard or full-text models. Conceptually, they contain every true statement about their datatype, such as 1 is less than 2 and Christmas Day is after Christmas Eve.
Creating Datatyping Models
Use the create
command with an optional type argument of <http://mulgara.org/mulgara#XMLSchemaModel>
in addition to the model name.
For example, to create the datatyping model #xsd
:
create <rmi://mysite.com/server1#xsd> <http://mulgara.org/mulgara#XMLSchemaModel>;
Note - Generally, there is no need to create more than one datatyping model per Mulgara server.
Loading Datatyping Models
As well as having a value, typed literals (such as the number 7.5, as opposed to the untyped text "7.5") also have a datatype, which is identified by a URI.
The primitive datatypes supported by Mulgara are listed in the following table.
Datatype |
Description |
---|---|
|
Character strings. For example, John |
|
The mathematical concept of binary-valued logic. For example, true or false |
|
Arbitrary precision decimal numbers. For example, 1.23 |
|
Single precision floating point numbers. For example, 1.23E4 |
|
Double precision floating point numbers. For example, 1.23E4 |
|
A point in time specified to one second accuracy. For example, 2004-12-24T23:59:59 (one second to Christmas Day 2004, UTC) |
|
A point in time specified to one day accuracy. For example, 2004-12-24 (Christmas Eve 2004) |
|
A specific gregorian month in a specific gregorian year. For example, 2004-12 (December 2004) |
|
A gregorian calendar year. For example, 2004 |
|
A day of the year. For example, 12-25 (Christmas Day) |
|
A day of the month. For example, 25 (25th day of the month) |
|
A month of the year. For example, 12 (12th month of the year) |
|
Arbitrary hex-encoded binary data |
|
Arbitrary Base64-encoded binary data |
The primitive datatypes currently not supported by Mulgara are listed the following table.
Datatype |
Description |
---|---|
|
A duration of time |
|
A Uniform Resource Identifier Reference (URI) |
|
Qualified XML names |
|
The NOTATION attribute type |
The derived datatypes currently supported by Mulgara are listed the following table.
Datatype |
Description |
---|---|
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
The derived datatypes currently not supported by Mulgara are listed the following table.
Datatype |
Description |
---|---|
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
|
Derived from |
Note - The URI prefix for all of the datatypes listed above is http://www.w3.org/2001/XMLSchema#
. For example http://www.w3.org/2001/XMLSchema#string
. More information about these datatypes is in the W3C document XML Schema Part 2: Datatypes.
The syntax to express a typed literal is to separate a literal value and its type with a double-caret (^^
).
For example, consider the statement that a text file was created on Christmas Eve 2004. This could be inserted into a model as follows:
insert <file:/nice.txt> <dc:date> '2004-12-24'^^<http://www.w3.org/2001/XMLSchema#date
>
into <rmi://mysite.com/server1#model>;
Remember that the command alias <http://www.w3.org/2001/XMLSchema#> as xsd;
allows you to write the insert command as follows:
insert <file:/nice.txt> <dc:date> '2004-12-24'^^<xsd:date
>
into <rmi://mysite.com/server1#model>;
Alternatively, the following could be loaded from an RDF/XML file:
<rdf:RDF xmlns:dc = "http://purl.org/dc/elements/1.1/"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema#">
<rdf:Description rdf:about="file:/nice.txt">
<dc:date rdf:datatype="http://www.w3.org/2001/XMLSchema#date"> 2004-12-24 </dc:date>
</rdf:Description>
</rdf:RDF>
Note - Datatyped statements are loaded into normal models, not datatyping models. Datatyping models cannot be written to, as this would be like trying to redefine the fixed nature of numbers or dates.
Querying Datatyping Models
Querying datatyping models is much the same as for normal Mulgara models. Datatyping models contain all statements with the following properties that happen to be true for the relevant datatype:
<mulgara:lt>
The subject is numerically less than the object, where both have a numeric datatype.
<mulgara:gt>
The subject is numerically greater than the object, where both have a numeric datatype.
<mulgara:after>
The subject occurs after the object, where both have a date datatype. That is,
xsd:date
,xsd:dateTime
,xsd:gYear
andxsd:gYearMonth
<mulgara:before>
The subject occurs before the object, where both have a date datatype. That is,
xsd:date
,xsd:dateTime
,xsd:gYear
andxsd:gYearMonth
Note - The datatypes listed above assume a prior alias <http://www.w3.org/2001/XMLSchema#> as xsd;
command was performed.
See the Loading Datatyping Models section for more information on the datatypes supported by Mulgara.
To use a datatyping model in a query, compose a constraint with one of the above properties and direct it at the XML Schema model with the in
clause. For example, the following query lists all resources from the 19th century:
select $doc from <rmi://mysite.com/server1#model>
where $doc <dc:date> $date
and $date <mulgara:before> '2000-01-01' in <rmi://mysite.com/server1#xsd>
and $date <mulgara:after> '1899-12-31' in <rmi://mysite.com/server1#xsd>;
Limitations of Datatyping Models
Datatyping models have the following limitations:
- Mulgara treats values with the
xsd:date
datatype as midnight of the corresponding day. - For
xsd:dateTime
, Mulgara does not parse time zones. - Constraints containing variables for both the subject and object may not work when applied to a datatyping model.
xsd:decimal
and its derived types are currently only implemented as a 64-bit long and are not arbitrary-precision.