Casting Functions

This topic describes the functions that are available for coercing data types in Anzo.

Typographical Conventions

This documentation uses the following conventions in function syntax:

  • CAPS: Although SPARQL is case-insensitive, function names and other keywords are written in uppercase for readability.
  • [ argument ]: Brackets are used to indicate optional arguments. Arguments without brackets are required.

Functions

  • BNODE: Creates a blank node.
  • BOOLEAN: Casts a literal value to a boolean data type.
  • BYTE: Casts a literal value to a byte data type.
  • CONCATURL: Concatenates two or more strings and returns the result as a URI.
  • DATATYPE: Returns the data type of the given value.
  • DATETIME (or xsd:dateTime): Returns a dateTime value from the given string, long, or dateTime.
  • DATEVALUE: Casts a string to a date.
  • DECIMAL: Casts a literal value to a decimal data type.
  • DOUBLE: Casts a literal value to a double data type.
  • DURATION: Returns an xsd:duration value from the given numeric or duration value.
  • DURATIONFORMAT: Converts a duration or numeric value to a string in the specified duration format.
  • ENCODE_FOR_URI: Encodes the specified string as a URI.
  • FLOAT: Casts a literal value to a float data type.
  • FORMATDATE: Casts a numeric or date value to a string in the specified date format.
  • FORMATFRACTION: Converts a numeric value into a fraction string.
  • FORMATNUMBER: Casts a numeric value to a string in the specified format.
  • INT: Casts a literal value to an int data type.
  • INTEGER: Casts a literal value to an integer data type.
  • LONG: Casts a literal value to a long data type.
  • PARSEDATETIME: Attempts to convert the given string or plain literal to a date, time, or dateTime value.
  • RAD: Converts to radians an angle value that is in degrees.
  • SERIALIZE: Creates a literal value from the string representation of the specified RDF term.
  • SHORT: Casts a literal value to a short data type.
  • STR: Casts an RDF term type value to a string.
  • TEXT: Casts a numeric or dateTime value to a string in the specified format.
  • TIMEVALUE: Converts the specified RDF term type value to an xsd:time value.
  • TOURI: Casts a string literal value to a URI.
  • UUID: Generates a Universally Unique Identifier (UUID).
  • xsd:date: Converts the specified string, date, or dateTime value to an xsd:date.

BNODE

This function creates a blank node.

Syntax

BNODE([ value ])
Argument Type Description
value string An optional string value from which to create the blank node.

Returns

Type Description
blank node The generated blank node.

BOOLEAN

This function casts a literal value to a boolean data type.

Syntax

BOOLEAN(value)
Argument Type Description
value literal The literal value to cast to a boolean type.

Returns

Type Description
boolean The input cast to boolean.

BYTE

This function casts a literal value to a byte data type.

Syntax

BYTE(value)
Argument Type Description
value literal The literal value to cast to a byte type.

Returns

Type Description
byte The input value cast to a byte.

CONCATURL

This function concatenates two or more strings and returns the result as a URI.

Syntax

CONCATURL(text1, text2 [, textN ])
Argument Type Description
text1–N string The strings that you want to concatenate to form a URI.

Returns

Type Description
URI The concatenated string as a URI.

DATATYPE

This function returns the data type of the given literal value.

Syntax

DATATYPE(value)
Argument Type Description
value literal The literal value for which to return the data type.

Returns

Type Description
URI The data type.

DATETIME (or xsd:dateTime)

This function returns a dateTime value from the given string, long, or dateTime.

Syntax

DATETIME(value)
Argument Type Description
value string, long, dateTime The string, long, or dateTime value from which to return a dateTime.

Returns

Type Description
dateTime The dateTime value.

DATEVALUE

This function casts the given string value to a date.

Syntax

DATEVALUE(value)
Argument Type Description
value string The string value from which to return the date.

Returns

Type Description
date The string cast to a date.

DECIMAL

This function casts a literal value to a decimal data type.

Syntax

DECIMAL(value)
Argument Type Description
value literal The literal value to convert to a decimal type.

Returns

Type Description
decimal The literal value cast to a decimal type.

DOUBLE

This function casts a literal value to a double data type.

Syntax

DOUBLE(value)
Argument Type Description
value literal The literal value to convert to a double type.

Returns

Type Description
double The literal value cast to a double type.

DURATION

This function returns an xsd:duration value from the given numeric or duration value.

Syntax

DURATION(value)
Argument Type Description
value duration, numeric The duration or numeric value from which to return an xsd:duration.

Returns

Type Description
duration The duration value.

DURATIONFORMAT

This function converts a duration or numeric value to a string in the specified duration format.

Syntax

DURATIONFORMAT(value [, format ])
Argument Type Description
value duration, numeric The duration or numeric value to format.
format string An optional value that specifies the format to use for the resulting duration string. Anzo supports Pattern Tokens for defining the format:
  • y for year digits
  • M for months
  • d for days
  • H for hours
  • m for minutes
  • s for seconds
  • S for milliseconds
  • 'text' for arbitrary text content

If format is not specified, H:mm:ss.SSS is used.

Returns

Type Description
string The duration as a string.

ENCODE_FOR_URI

This function encodes the specified string as a URI and returns a string in URI format.

Syntax

ENCODE_FOR_URI(text)
Argument Type Description
text string The string value to encode as a URI.

Returns

Type Description
string The string as a URI.

FLOAT

This function casts a literal value to a float data type.

Syntax

FLOAT(value)
Argument Type Description
value literal The literal value to convert to a float type.

Returns

Type Description
float The literal value cast to a float type.

FORMATDATE

This function converts a numeric or date value into a string with the specified date format.

Syntax

FORMATDATE(value, format)
Argument Type Description
value date, numeric The date or numeric value to convert to a string in the specified date format.
format string The format to use for the resulting date string. Anzo supports Pattern Tokens for defining the format:
  • y for year digits
  • M for months
  • d for days
  • 'text' for arbitrary text content

For example, "yyyy.MM.dd" or "dd/MM/yyyy".

Returns

Type Description
string The date as a string.

FORMATFRACTION

This function converts a numeric value into a fraction string.

Syntax

FORMATFRACTION(value [, tolerance ] [, whole_number ])
Argument Type Description
value numeric The numeric value to convert to fraction text.
tolerance double An optional double value that specifies the precision of the fraction. The default value is 0.0001. The resulting fractional representation is the original value + or - the tolerance. The smaller the tolerance, the more precise the fraction is. For example, 399/800 vs. 1/2.
whole_number boolean An optional boolean value that specifies whether to include whole numbers in the result. For example, if true, the result would be formatted like 1 2/3 instead of 5/3.

Returns

Type Description
string The fraction string.

FORMATNUMBER

This function casts a numeric value to a string in the specified format.

Syntax

TEXT(value, format)
Argument Type Description
value numeric The numeric value to convert to a string.
format string A text string that specifies the format to follow when converting the value to a string. Anzo supports Java Decimal Format.

Returns

Type Description
string The numeric value as a string.

INT

This function casts a literal value to an int data type.

Syntax

INT(value)
Argument Type Description
value literal The literal value to convert to an int type.

Returns

Type Description
int The literal value cast to an int type.

INTEGER

This function casts a literal value to an integer data type.

Syntax

INTEGER(value)
Argument Type Description
value literal The literal value to convert to an integer type.

Returns

Type Description
integer The literal value cast to an integer type.

LONG

This function casts a literal value to a long data type.

Syntax

LONG(value)
Argument Type Description
value literal The literal value to convert to a long type.

Returns

Type Description
long The literal value cast to a long type.

PARSEDATETIME

This function attempts to convert the given string or plain literal to a date, time, or dateTime value. For values that do not include a timezone, Anzo stores them in GMT. Values that include a timezone are stored as the appropriate value in GMT for that timezone.

Syntax

PARSEDATETIME(value [, output_type ] [, format ])
Argument Type Description
value string, literal The string or plain literal value to convert to a date, time, or dateTime.
output_type URI An optional URI (xsd:date, xsd:time, or xsd:dateTime) that specifies the type of value to return. If output_type is not specified, dateTime is returned.
format string An optional string that species the format to use for the resulting date, time, or dateTime value. Anzo supports Pattern Tokens for defining the format:
  • y for year digits
  • M for months
  • d for days
  • H for hours
  • m for minutes
  • s for seconds
  • S for milliseconds
  • 'text' for arbitrary text content

For example, "yyyy.MM.dd HH:mm" or "dd/MM/yyyy HH:mm:ss".

Returns

Type Description
date, time, or dateTime The conversion of the string to the desired type.

RAD

This function converts to radians an angle value that is in degrees.

Syntax

RAD(angle)
Argument Type Description
angle double The angle value to convert to radians.

Returns

Type Description
double The angle in radians.

SERIALIZE

This function creates a literal value from the string representation of the specified RDF term type value.

Syntax

SERIALIZE(value)
Argument Type Description
value RDF term The literal, URI, or blank node value for which to generate a plain literal.

Returns

Type Description
string The string representation of the input term.

SHORT

This function casts a literal value to a short data type.

Syntax

SHORT(value)
Argument Type Description
value literal The literal value to convert to a short type.

Returns

Type Description
short The literal value cast to a short type.

STR

This function casts the specified RDF term type value to a string.

Syntax

STR(value)
Argument Type Description
value RDF term The literal, URI, or blank node value to convert to a string.

Returns

Type Description
string The term cast to a string type.

TEXT

This function casts a numeric or dateTime value to a string in the specified format.

Syntax

TEXT(value, format)
Argument Type Description
value numeric, dateTime The numeric or datetime value to convert to a string.
format string A text string that specifies the format to follow when converting the value to a string. For numeric values, Anzo supports Java Decimal Format. For dateTime values, Simple Date Format is supported.

Returns

Type Description
string The string in the specified format.

TIMEVALUE

This function converts the specified RDF term type value to an xsd:time value.

Syntax

TIMEVALUE(value)
Argument Type Description
value RDF term The literal, URI, or blank node value to convert to a time value.

Returns

Type Description
time The conversion of the term to a time value.

TOURI

This function casts a string literal value to a URI.

Syntax

TOURI(text)
Argument Type Description
text string The string literal to cast to a URI.

Returns

Type Description
URI The literal value as a URI.

UUID

This function generates a Universally Unique Identifier (UUID).

Syntax

UUID()

Returns

Type Description
URI The UUID.

xsd:date

This function converts the specified string, date, or dateTime value to an xsd:date.

Syntax

xsd:date(value)
Argument Type Description
value string, date, dateTime The string, date, or dateTime value to convert to an xsd:date.

Returns

Type Description
date The input values converted to dates.