Difference between revisions of "DTB"

From RIF
Jump to: navigation, search
(Cast functions for Datatypes and rif:iri)
(Symbol Spaces)
(2 intermediate revisions by one user not shown)
Line 54: Line 54:
 
A '''''symbol space''''' is a named subset of the set of all constants, <tt>Const</tt> in RIF. Each symbol in <tt>Const</tt> belongs to exactly one symbol space.  
 
A '''''symbol space''''' is a named subset of the set of all constants, <tt>Const</tt> in RIF. Each symbol in <tt>Const</tt> belongs to exactly one symbol space.  
  
Each symbol space has an associated lexical space, a unique identifier, and,
+
Each symbol space has an associated lexical space and a unique identifier. More precisely,
possibly, one or more aliases. More precisely,
+
 
* The '''''lexical space''''' of a symbol space is a non-empty set of Unicode character strings.  
 
* The '''''lexical space''''' of a symbol space is a non-empty set of Unicode character strings.  
 
* The '''''identifier''''' of a symbol space is a sequence of Unicode characters that form an absolute IRI.
 
* The '''''identifier''''' of a symbol space is a sequence of Unicode characters that form an absolute IRI.
* An '''''alias''''' is also a sequence of unicode characters, but it is not required to form an IRI.
 
* Different symbol spaces cannot share the same identifier or an alias.
 
  
The identifiers and aliases of symbol spaces are '''not''' themselves constant symbols in RIF.
+
The identifiers of symbol spaces are '''not''' themselves constant symbols in RIF. However, to simplify the language, we will often use symbol space identifiers to refer to the actual symbol spaces (for instance, we may use "symbol space <tt>xsd:string</tt>" instead of "symbol space ''identified by'' <tt>xsd:string</tt>").  
 
+
To simplify the language, we will often use symbol space identifiers to refer to the actual symbol spaces (for instance, we may use "symbol space <tt>xsd:string</tt>" instead of "symbol space ''identified by'' <tt>xsd:string</tt>").  
+
  
 
To refer to a constant in a particular RIF symbol space, we use the following presentation syntax:  
 
To refer to a constant in a particular RIF symbol space, we use the following presentation syntax:  

Revision as of 08:18, 27 May 2008

__NUMBEREDHEADINGS__


Document title:
RIF Data Types and Built-Ins (Second Edition)
Editors
Axel Polleres, DERI
Harold Boley, National Research Council Canada
Michael Kifer, State University of New York at Stony Brook
Abstract
Status of this Document
rough draft

Copyright © 2008 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.


This document, developed by the Rule Interchange Format (RIF) Working Group, specifies a list of primitive datatypes, built-in functions and built-in predicates required by RIF dialects such as the RIF Basic Logic Dialect. This list shall be viewed as a catalogue which dialects can use by referencing which datatypes and builtins must be supported by implementations of these specific dialects. Some of the datatypes are adopted from XML Schema Part 2: Datatypes Second Edition. A large part of the definitions of the listed functions and operators are adapted from XQuery 1.0 and XPath 2.0 Functions and Operators.


1 Naming and notational conventions used in this document

Throughout this document we use the following prefixes for compact IRIs [CURIE] used for symbol spaces or for IRI constants in RIF's presentation syntax:

  • the xsd: prefix stands for the XML Schema namespace URI http://www.w3.org/2001/XMLSchema#,
  • the rdf: prefix stands for http://www.w3.org/1999/02/22-rdf-syntax-ns#,
  • the rif: prefix stands for http://www.w3.org/2007/rif#,
  • the func: prefix stands for http://www.w3.org/2007/rif-builtin-function#, and
  • the pred: prefix stands for http://www.w3.org/2007/rif-builtin-predicate#

2 Symbol Spaces and Data Types

2.1 Symbol Spaces

This section reproduces the definition of symbol spaces, which are part of the syntactic and semantic framework for RIF's logic-based dialects (RIF-FLD).

Definition (Symbol space). A symbol space is a named subset of the set of all constants, Const in RIF. Each symbol in Const belongs to exactly one symbol space.

Each symbol space has an associated lexical space and a unique identifier. More precisely,

  • The lexical space of a symbol space is a non-empty set of Unicode character strings.
  • The identifier of a symbol space is a sequence of Unicode characters that form an absolute IRI.

The identifiers of symbol spaces are not themselves constant symbols in RIF. However, to simplify the language, we will often use symbol space identifiers to refer to the actual symbol spaces (for instance, we may use "symbol space xsd:string" instead of "symbol space identified by xsd:string").

To refer to a constant in a particular RIF symbol space, we use the following presentation syntax:

"literal"^^symspace

where literal is called the lexical part of the symbol, and symspace is an identifier or an alias of the symbol space. Here literal is a sequence of Unicode characters that must be an element in the lexical space of the symbol space symspace. For instance, "1.2"^^xsd:decimal and "1"^^xsd:decimal are legal symbols because 1.2 and 1 are members of the lexical space of the XML Schema data type xsd:decimal. On the other hand, "a+2"^^xsd:decimal is not a legal symbol, since a+2 is not part of the lexical space of xsd:decimal.

The set of all symbol spaces that partition Const is considered to be part of the logic language of RIF-FLD.


RIF requires that all dialects include the following symbol spaces. Rule sets that are exchanged through RIF can use additional symbol spaces.

  • xsd:string (http://www.w3.org/2001/XMLSchema#string)
  • xsd:time (http://www.w3.org/2001/XMLSchema#time)
  • xsd:date (http://www.w3.org/2001/XMLSchema#date)
  • xsd:dateTime (http://www.w3.org/2001/XMLSchema#dateTime)
  • xsd:decimal (http://www.w3.org/2001/XMLSchema#decimal) and all the symbol spaces that corresponds to the subtypes of xsd:decimal as specified in [XML-SCHEMA2].

Editor's note: The group still discussed whether all subtypes of xsd:decimal shall be supported or whether a basic subset such as xsd:integer and xsd:long should be supported.

The lexical spaces of the above symbol spaces are defined in the document [XML-SCHEMA2].

  • xsd:dayTimeDuration (http://www.w3.org/2001/XMLSchema#dayTimeDuration)
  • xsd:dayTimeDuration (http://www.w3.org/2001/XMLSchema#yearMonthDuration)

These two symbol spaces represent two subtypes of the XML Schema datatype xsd:duration with well-defined value spaces, since xsd:duration does not have a well-defined value space (this may be corrected in later revisions of XML Schema datatypes, in which case the revised datatype would be suitable for RIF DTB). The lexical spaces of the above symbol spaces are defined in the document [XDM].

  • rdf:XMLLiteral (http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral).

This symbol space represents XML content. The lexical space of rdf:XMLLiteral is defined in the document [RDF-CONCEPTS].

  • rif:text (for text strings with language tags attached).

This symbol space represents text strings with a language tag attached. The lexical space of rif:text is the set of all Unicode strings of the form ...@LANG, i.e., strings that end with @LANG where LANG is a language identifier as defined in [RFC-3066].

  • rif:iri (for internationalized resource identifiers or IRIs).

Constant symbols that belong to this symbol space are intended to be used in a way similar to RDF resources [RDF-SCHEMA]. The lexical space consists of all absolute IRIs as specified in [RFC-3987]; it is unrelated to the XML primitive type anyURI. A rif:iri constant must be interpreted as a reference to one and the same object regardless of the context in which that constant occurs.

  • rif:local (for constant symbols that are not visible outside of the RIF document in which they occur).

Symbols in this symbol space are local to the RIF documents in which they occur. This means that occurrences of the same rif:local constant in different documents are viewed as unrelated distinct constants, but occurrences of the same rif:local constant in the same document must refer to the same object. The lexical space of rif:local is the same as the lexical space of xsd:string.

2.2 Data Types

Data types in RIF are symbol spaces which have special semantics. That is, each datatype is characterized by a fixed lexical space, value space and lexical-to-value-mapping.

Definition (Primitive data type). A primitive data type (or just a data type, for short) is a symbol space that has

  • an associated set, called the value space, and
  • a mapping from the lexical space of the symbol space to the value space, called lexical-to-value-space mapping.   ☐

Semantic structures are always defined with respect to a particular set of data types, denoted by DTS. In a concrete dialect, DTS always includes the data types supported by that dialect. All RIF dialects must support the following primitive data types:

  • xsd:long
  • xsd:integer
  • xsd:decimal
  • xsd:string
  • xsd:time
  • xsd:dateTime
  • xsd:dayTimeDuration
  • xsd:yearMonthDuration
  • rdf:XMLLiteral
  • rif:text

Their value spaces and the lexical-to-value-space mappings are defined as follows:

  • For the XML Schema data types of RIF, namely xsd:long, xsd:integer, xsd:decimal, xsd:string, xsd:time, and xsd:dateTime, the value spaces and the lexical-to-value-space mappings are defined in the XML Schema specification [XML-SCHEMA2].
  • The value spaces and the lexical-to-value-space mappings for the primitive data types xsd:dayTimeDuration and xsd:yearMonthDuration are defined in the XQuery 1.0 and XPath 2.0 Data Model [XDM].
  • The value space and lexical-to-value-space mapping for the primitive data type rdf:XMLLiteral is defined in RDF [RDF-CONCEPTS].
  • The value space rif:text is the set of all pairs of the form (string, lang), where string is a Unicode character sequence and lang is a lowercase Unicode character sequence which is a natural language identifier as defined by [RFC-3066]. The lexical-to-value-space mapping of rif:text, denoted Lrif:text, maps each symbol string@lang in the lexical space of rif:text to (string, lower-case(lang)), where lower-case(lang) is lang written in all-lowercase letters.

The value space and the lexical-to-value-space mapping for rif:text defined here are compatible with RDF's semantics for strings with named tags [RDF-SEMANTICS].

3 Syntax and Semantics of Built-ins

3.1 Syntax of Built-ins

A RIF built-in function or predicate is a special case of externally defined terms, which are defined in RIF Framework for Logic Dialects and also reproduced in the direct definition of RIF Basic Logic Dialect (RIF-BLD).

In RIF's presentation syntax built-in predicates and functions are syntactically represented as external terms of the form:

'External' '(' Expr ')'

where Expr is a positional term as defined in in RIF Framework for Logic Dialects (see also in RIF Basic Logic Dialect). For RIF's normative syntax, see XML Serialization Syntax for RIF-BLD.

RIF-FLD introduces the notion of an external schema to describe both the well-formed externally defined terms and their semantics. In the special case of a RIF built-in, external schemas have especially simple form. A built-in named f that takes n arguments has the schema

( ?X1 ... ?Xn;   f(?X1 ... ?Xn) )

Here f(?X1 ... ?Xn) is the actual term that is used to refer to the built-in (in expressions of the form External(f(?X1 ... ?Xn))) and ?X1 ... ?Xn is the list of all variables in that term.

For convenience, a complete definition of external schemas is reproduced in Appendix: Schemas for Externally Defined Terms.


3.2 Semantics of Built-ins

The semantics of external terms in RIF-FLD and RIF-BLD is defined using two mappings: Iexternal and Itruth ο Iexternal.

  • Iexternal. This mapping takes an external schema, σ, and returns a mapping, Iexternal(σ).

    If σ represents a built-in function, Iexternal(σ) must be that function.

    For each built-in function with external schema σ, the present document specifies the mapping Iexternal(σ).

  • Itruth. This mapping takes an element of the domain of interpretation and returns a truth value.

    In RIF logical semantics, this mapping is used to assign truth values to formulas. In the special case of RIF built-ins, it is used to assign truth values to RIF built-in predicates. The built-in predicates can have the truth values t or f only.

    For a built-in predicate with schema σ, RIF-FLD and RIF-BLD require that the truth-valued mapping Itruth ο Iexternal(σ) must agree with the specification of the corresponding built-in predicate.

    For each RIF built-in predicate with schema σ, the present document specifies Itruth ο Iexternal(σ).

4 List of Supported Built-in Predicates and Functions

This section defines the syntax and semantics of all built-in predicates and functions in RIF. For each built-in, the following is defined:

  1. The name of the built-in.
  2. The external schema of the built-in.
  3. For a built-in function, how it maps its arguments into a result.

    As explained in Section Semantics of Built-ins, this corresponds to the mapping Iexternal(σ) in the formal semantics of RIF-FLD and RIF-BLD, where σ is the external schema of the built-in.

  4. For a built-in predicate, its truth value when the arguments are substituted with values in the domain.

    As explained in Section Semantics of Built-ins, this corresponds to the mapping Itruth ο Iexternal(σ) in the formal semantics of RIF-FLD and RIF-BLD, where σ is the external schema of the built-in.

  5. The intended domains for the arguments of the built-in.

    Typically, built-in functions and predicates are defined over the value spaces of appropriate data types. These are the intended domains of the arguments. When an argument falls outside of its intended domain, it is understood as an error. Since this document defines a model-theoretic semantics for RIF built-ins, which does not support the notion of an error, the definitions leave the values of the built-in predicates and functions unspecified in such cases. This means that for different semantic structures, the value of Iexternal(σ)(a1 ... an) can be anything if one of the arguments is not in its intended domain. Similarly, Itruth ο Iexternal(σ)(a1 ... an) can be t in some interpretations and f in others.

    This indeterminacy in case of an error implies that applications must not make any assumptions about the values of built-ins in such situations. Implementations are even allowed to abort in such cases and the only safe way to communicate rule sets that contain built-ins among RIF-compliant systems is to use data type guards.


Many built-in functions and predicates described below are adapted from XQuery 1.0 and XPath 2.0 Functions and Operators and, when appropriate, we will refer to the definitions in that specification in order to avoid copying them.

4.1 Guard Predicates for Datatypes

RIF requires guard predicates for all its supported datatypes.

  • Schema: The schemas for these predicates have the general form

    ( ?arg1; pred:isDATATYPE ( ?arg1 ) )

  • Intended domain:

    Guard predicates do not depend on a specific intended domain.

  • Mapping:

    Itruth ο Iexternal( ?arg1; pred:isDATATYPE ( ?arg1 ) )(s1) = t if and only if s1 is in the value space of DATATYPE and f otherwise.

Accordingly, the following schemas are defined:

  1. ( ?arg1; pred:isLong ( ?arg1 ) )

  2. ( ?arg1; pred:isInteger( ?arg1 ) )

  3. ( ?arg1; pred:isDecimal ( ?arg1 ) )

  4. ( ?arg1; pred:isString ( ?arg1 ) )

  5. ( ?arg1; pred:isTime ( ?arg1 ) )

  6. ( ?arg1; pred:isDateTime ( ?arg1 ) )

  7. ( ?arg1; pred:isDayTimeDuration ( ?arg1 ) )

  8. ( ?arg1; pred:isYearMonthDuration ( ?arg1 ) )

  9. ( ?arg1; pred:isXMLLiteral ( ?arg1 ) )

  10. ( ?arg1; pred:isText ( ?arg1 ) )

4.2 Negative Guard Predicates for Datatypes

Likewise, RIF has negative guards for all its supported datatypes.

  • Schema: The schemas for negative guards have the general form

    ( ?arg1; pred:isNotDATATYPE ( ?arg1 ) )

  • Intended domain:

    Negative guard predicates do not depend on a specific intended domain.

  • Mapping:

    Itruth ο Iexternal( ?arg1; pred:isNotDATATYPE ( ?arg1 ) )(s1) = f if and only if s1 is in the value space of DATATYPE and t otherwise.

Accordingly, the following schemas are defined:

  1. ( ?arg1; pred:isNotLong ( ?arg1 ) )

  2. ( ?arg1; pred:isNotInteger ( ?arg1 ) )

  3. ( ?arg1; pred:isNotDecimal ( ?arg1 ) )

  4. ( ?arg1; pred:isNotString ( ?arg1 ) )

  5. ( ?arg1; pred:isNotTime ( ?arg1 ) )

  6. ( ?arg1; pred:isNotDateTime ( ?arg1 ) )

  7. ( ?arg1; pred:isNotDayTimeDuration ( ?arg1 ) )

  8. ( ?arg1; pred:isNotYearMonthDuration ( ?arg1 ) )

  9. ( ?arg1; pred:isNotXMLLiteral ( ?arg1 ) )

  10. ( ?arg1; pred:isNotText ( ?arg1 ) )

Future dialects may extend this list of guards to other datatypes, but RIF does not require guards for all datatypes.

4.3 Cast functions for Datatypes and rif:iri

RIF requires cast functions for all its supported datatypes, i.e. for each datatype DATATYPE there is an external function as follows:

  • Schema:

    ( ?arg1; DATATYPE ( ?arg1 ) )

  • Intended domain:

    The value spaces of datatypes castable to DATATYPE according to the table in Section 17.1 of XQuery 1.0 and XPath 2.0 Functions and Operators.

  • Mapping:

    Iexternal( ?arg1; DATATYPE ( ?arg1 ) )(s1) = s1' such that s1' is the conversion of s1 to the value space of xsd:DATATYPE according to the table in Section 17.1 of XQuery 1.0 and XPath 2.0 Functions and Operators. Note that these conversions are only partial.

    If an argument value is outside of the intended domain or outside the partial conversions defined in XQuery 1.0 and XPath 2.0 Functions and Operators, the value of the function is left unspecified and can vary from one semantic structure to another.

Note that neither the remaining data types xsd:long and rif:XMLLiteral, nor the symbol space rif:iri do not appear in the conversion table of XQuery 1.0 and XPath 2.0 Functions and Operators, but the following considerations apply:

  • The conversions from and to xsd:long follow the same considerations as xsd:integer in that table, by the XPath, XQuery type hierarchy in Section 1.6 of XQuery 1.0 and XPath 2.0 Functions and Operators.
  • Any rif:XMLLiteral can be cast to xsd:string by preserving the lexical value and just changing the symbol space. An xsd:string can be cast to rdf:XMLLiteral if and only if its value is in the lexical space of rdf:XMLLiteral as defined in Resource Description Framework (RDF): Concepts and Abstract Syntax.
  • Any rif:text can be cast to xsd:string by preserving the lexical value of its string part.
  • Additionally we allow conversions from and to rif:iri following the same considerations as conversions from and to xsd:anyURI.

Although rif:iri is not a datatype, I left conversions from and to rif:iris in the list of cast functions, since I see some use cases in the context of RDF if you want to extract a string from an IRI and vice versa. See also the use case mentioned in http://lists.w3.org/Archives/Public/public-rif-wg/2008Mar/0011.html

4.4 Numeric Functions and Predicates

The following functions and predicates are adapted from the respective numeric functions and operators in XQuery 1.0 and XPath 2.0 Functions and Operators.

4.4.1 Numeric Functions

1. op:numeric-add

  • Schema:

    (?arg1 ?arg2; func:numeric-add(?arg1 ?arg2))

  • Intended domains:

    The value spaces of xsd:integer, xsd:long, or xsd:decimal for both arguments.

  • Mapping:

    When both s1 and s2 belong to their intended domains, External(func:numeric-add(s1 s2)) evaluates to the result of op:numeric-add(s1, s2) as defined in XQuery 1.0 and XPath 2.0 Functions and Operators.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

The following numeric built-in functions are defined accordingly with respect to their corresponding operators in XQuery 1.0 and XPath 2.0 Functions and Operators and we will only add further explanations where needed.

2. op:numeric-subtract

(?arg1 ?arg2; func:numeric-subtract( ?arg1 ?arg2) )

3. op:numeric-multiply

(?arg1 ?arg2; func:numeric-multiply( ?arg1 ?arg2) )

4. op:numeric-divide

(?arg1 ?arg2; func:numeric-divide( ?arg1 ?arg2) )

  • Intended domains:

    The value spaces of xsd:integer, xsd:long, or xsd:decimal for the first argument and xsd:integer, xsd:long, or xsd:decimal without zero for the second argument.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another, which here particularly means that RIF does not prescribe the behavior on division by zero.

4.4.2 Numeric Predicates

1. op:numeric-equal

  • Schema:

    (?arg1 ?arg2; pred:numeric-equal(?arg1 ?arg2))

  • Intended domains:

    The value spaces of xsd:integer, xsd:long, or xsd:decimal for both arguments.

  • Mapping:

    When both s1 and s2 belong to their intended domains, External(pred:numeric-equal(s1 s2)) is t if and only if op:numeric-equal(s1, s2) returns true, as defined in XQuery 1.0 and XPath 2.0 Functions and Operators.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.

The following numeric built-in predicates are defined acordingly with respect to their corresponding operators in XQuery 1.0 and XPath 2.0 Functions and Operators.

2. op:numeric-less-than

(?arg1 ?arg2; pred:numeric-less-than( ?arg1 ?arg2) )

3. op:numeric-greater-than

(?arg1 ?arg2; pred:numeric-greater-than( ?arg1 ?arg2) )

4.5 Functions and Predicates on Strings

The following functions and predicates are adapted from the respective functions and operators on strings in XQuery 1.0 and XPath 2.0 Functions and Operators.


Editor's note: The following treatment of built-ins which may have multiple arities is a strawman proposal currently under discussion in the working group.

In the following, we encounter several versions of some built-ins with varying arity, since XPath and XQuery allow overloading, i.e. the same function or operator name occurring with different arities. We treat this likewise in RIF, by numbering the different versions of the respective built-ins and treating the unnumbered version as syntactic sugar, i.e. for instance instead of External( func:concat2( str1, str2) ) and External( func:concat3( str1 str2 str3 ) ) we equally allow simply to write External( func:concat( str1, str2) ) and External( func:concat( str1 str2 str3 ) ). Note that this is really purely syntactic sugar, and does not mean that for external predicates and functions we lift the restriction made in BLD that each function and predicate has a unique assigned arity. Those schemata for which we allow this syntactic sugar, appear in the same box.

4.5.1 Functions on Strings

1. fn:compare

  • Schema:

    ( ?comparand1 ?comparand2; func:compare1(?comparand1 ?comparand2) )

    ( ?comparand1 $comparand2 $collation; func:compare2(?comparand1 ?comparand2 ?collation) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Iexternal( ( ?comparand1 ?comparand2; func:compare1(?comparand1 ?comparand2) )(s1 s2) = res such that res = -1, 0, or 1, depending on whether the value of the s1 is respectively less than, equal to, or greater than the value of s2, according to the rules of the collation that is used.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

The following schemata are defined analogously with respect to their corresponding operators as defined in XQuery 1.0 and XPath 2.0 Functions and Operators and we only give informal descriptions of the respective mappings Iexternal.

2. fn:concat

  • Schema:

    ( ?arg1; func:concat1(1 ) )

    ( ?arg1 ?arg2; func:concat2(?arg1 ?arg2 ) )

    ...

    ( ?arg1  ?arg2 ... ?argn; func:concatn(?arg1 ?arg2 ... ?argn ) )

  • Intended domains:

    Following the definition of fn:concat this function accepts xs:anyAtomicType arguments and casts them to xsd:string. Thus, the intended domain for all arguments is the union of all value spaces castable to String xsd:string as defined in Section Cast functions for Datatypes and rif:iri above.

  • Mapping:

    Returns the xsd:string that is the concatenation of the values of its arguments after conversion.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

3. fn:string-join

  • Schema:

    ( ?arg1 ?arg2; func:string-join2(?arg1 ?arg2 ) )

    ( ?arg1 ?arg2 ?arg3; func:string-join2(?arg1 ?arg2 ?arg3 ) )

    ...

    ( ?arg1  ?arg2 ... ?argn; func:string-joinn(?arg1 ?arg2 ... ?argn ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns a xsd:string created by concatenating the arguments 1 to (n-1) using the nth argument as a separator.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

4. fn:substring

  • Schema:

    ( ?sourceString ?startingLoc; func:substring1( ?sourceString ?startingLoc) )

    ( ?sourceString ?startingLoc ?length ; func:substring2( ?sourceString ?startingLoc ?length) )

  • Intended domains:

    The value space of xsd:string for  ?sourceString and the union of the value spaces of xsd:integer, xsd:long, or xsd:decimal for the remaining two arguments.

  • Mapping:

    Returns the portion of the value of ?sourceString beginning at the position indicated by the value of ?startingLoc and continuing for the number of characters indicated by the value of ?length. The characters returned do not extend beyond ?sourceString. If ?startingLoc is zero or negative, only those characters in positions greater than zero are returned.

    If an argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

5. fn:string-length

  • Schema:

    ( func:string-length1() )

    ( ?arg ; func:string-length2( ?arg ) )

  • Intended domains:

    The value space of xsd:string for  ?arg.

  • Mapping:

    Returns an xsd:integer equal to the length in characters of the argument if it is a xsd:string.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

6. fn:upper-case

  • Schema:

    ( ?arg ; func:upper-case( ?arg ) )

  • Intended domains:

    The value space of xsd:string for  ?arg.

  • Mapping:

    Returns the value of ?arg after translating every character to its upper-case correspondent as defined in the appropriate case mappings section in the Unicode standard.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

7. fn:lower-case

  • Schema:

    ( ?arg ; func:lower-case( ?arg ) )

  • Intended domains:

    The value space of xsd:string for  ?arg.

  • Mapping:

    Returns the value of ?arg after translating every character to its lower-case correspondent as defined in the appropriate case mappings section in the Unicode standard.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

8. fn:encode-for-uri

  • Schema:

    ( ?arg ; func:encode-for-uri( ?arg ) )

  • Intended domains:

    The value space of xsd:string for  ?arg.

  • Mapping:

    This function encodes reserved characters in an xsd:string that is intended to be used in the path segment of a URI. It is invertible but not idempotent.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

9. fn:iri-to-uri

  • Schema:

    ( ?iri ; func:iri-to-uri ( ?iri ) )

  • Intended domains:

    The value space of xsd:string for  ?iri.

  • Mapping:

    This function converts an xsd:string containing an IRI into a URI according to the rules spelled out in Section 3.1 of RFC 3987. It is idempotent but not invertible.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.


10. fn:escape-html-uri

  • Schema:

    ( ?uri ;func:escape-html-uri( ?uri ) )

  • Intended domains:

    The value space of xsd:string for  ?uri.

  • Mapping:

    This function escapes all characters except printable characters of the US-ASCII coded character set, specifically the octets ranging from 32 to 126 (decimal). The effect of the function is to escape a URI in the manner html user agents handle attribute values that expect URIs. Each character in $uri to be escaped is replaced by an escape sequence, which is formed by encoding the character as a sequence of octets in UTF-8, and then representing each of these octets in the form %HH, where HH is the hexadecimal representation of the octet. This function must always generate hexadecimal values using the upper-case letters A-F.

    If the argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

11. fn:substring-before

  • Schema:

    ( ?arg1 ?arg2; func:substring-before1( ?arg1 ?arg2 ) )

    ( ?arg1 ?arg2 ?collation; func:substring-before2( ?arg1 ?arg2 ?collation ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns the substring of the value of ?arg1 that precedes in the value of ?arg1 the first occurrence of a sequence of collation units that provides a minimal match to the collation units of ?arg2 according to the collation that is used.

    If any argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

12. fn:substring-after

  • Schema:

    ( ?arg1 ?arg2; func:substring-after1( ?arg1 ?arg2 ) )

    ( ?arg1 ?arg2 ?collation; func:substring-after2( ?arg1 ?arg2 ?collation ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns the substring of the value of ?arg1 that follows in the value of ?arg1 the first occurrence of a sequence of collation units that provides a minimal match to the collation units of ?arg2 according to the collation that is used.

    If any argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

13. fn:replace

  • Schema:

    ( ?input ?pattern ?replacement; func:replace1( ?input ?pattern ?replacement ) )

    ( ?input ?pattern ?replacement ?flags; func:replace2( ?input ?pattern ?replacement ?flags ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    The function returns the xsd:string that is obtained by replacing each non-overlapping substring of ?input that matches the given ?pattern with an occurrence of the ?replacement string.

    If any argument value is outside of its intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

Editor's note: I removed fn:tokenize from previous versions, since tokenizer returns a sequence of strings, we might reconsider this if we (re-)introduce lists, but I left this out for the moment.

4.5.2 Predicates on Strings

1. fn:contains

  • Schema:

    ( ?arg1 ?arg2; pred:contains1( ?arg1 ?arg2 ) )

    ( ?arg1 ?arg2 ?collation ; pred:contains2( ?arg1 ?arg2 ?collation ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns true or false indicating whether or not the value of ?arg1 contains (at the beginning, at the end, or anywhere within) at least one sequence of collation units that provides a minimal match to the collation units in the value of ?arg2, according to the collation that is used. "Minimal match" is defined in Unicode Collation Algorithm.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.


2. fn:starts-with

  • Schema:

    ( ?arg1 ?arg2; pred:starts-with1( ?arg1 ?arg2 )

    ( ?arg1 ?arg2 ?collation; pred:starts-with2( ?arg1 ?arg2 ?collation)

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns true or false indicating whether or not the value of ?arg1 starts with a sequence of collation units that provides a minimal match to the collation units of ?arg2 according to the collation that is used.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.


3. fn:ends-with

  • Schema:

    (?arg1 ?arg2; fn:ends-with1( ?arg1 ?arg2 ) )

    (?arg1 ?arg2 ?collation; fn:ends-with2( ?arg1 ?arg2 ?collation) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns true or false indicating whether or not the value of ?arg1 ends with a sequence of collation units that provides a minimal match to the collation units of ?arg2 according to the collation that is used.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

4. fn:matches

  • Schema:

    ( ?input ?pattern; pred:matches1( ?input ?pattern) )

    ( ?input ?pattern ?flags; pred:matches2( ?input ?pattern ?flags ) )

  • Intended domains:

    The value space of xsd:string for all arguments.

  • Mapping:

    Returns true if the input matches the regular expression supplied as pattern as influenced by the flags, if present; otherwise, it returns false. The effect of calling the first version of this function (omitting the flags) is the same as the effect of calling the second version with the flags argument set to a zero-length string.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

4.6 Functions and Predicates on Dates and Times

If not stated otherwise, in the following we define schemas for functions and operators defined on the date and time datatypes in XQuery 1.0 and XPath 2.0 Functions and Operators.

As defined in Section 3.3.2 Dates and Times, xsd:dateTime, xsd:date, xsd:time, xsd:gYearMonth, xsd:gYear, xsd:gMonthDay, xsd:gMonth, xsd:gDay values, referred to collectively as date/time values, are represented as seven components or properties: year, month, day, hour, minute, second and timezone. The value of the first five components are xsd:integers. The value of the second component is an xsd:decimal and the value of the timezone component is an xsd:dayTimeDuration. For all the date/time datatypes, the timezone property is optional and may or may not be present. Depending on the datatype, some of the remaining six properties must be present and some must be absent. Absent, or missing, properties are represented by the empty sequence. This value is referred to as the local value in that the value is in the given timezone. Before comparing or subtracting xsd:dateTime values, this local value must be translated or normalized to UTC.

4.6.1 Functions on Dates and Times

1. fn:year-from-dateTime

  • Schema:

    ( ?arg ; func:year-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Iexternal( ?arg ; func-year-from-dateTime( ?arg ) )(s) = res

    such that res is the result of fn:year-from-dateTime(s) as defined in XQuery 1.0 and XPath 2.0 Functions and Operators.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

Note that we we slightly deviate here from the original definition of fn:year-from-dateTime which says: "If ?arg is the empty sequence, returns the empty sequence." We have no terminology of "sequence". The following schemata are defined analogously with respect to their corresponding operators as defined in XQuery 1.0 and XPath 2.0 Functions and Operators and we only give informal descriptions of the respective mappings Iexternal.

2. fn:month-from-dateTime

  • Schema:

    ( ?arg ; func:month-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Returns an xsd:integer between 1 and 12, both inclusive, representing the month component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

3. fn:day-from-dateTime

  • Schema:

    ( ?arg ; func:day-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Returns an xsd:integer between 1 and 31, both inclusive, representing the day component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

4. fn:hours-from-dateTime

  • Schema:

    ( ?arg ; func:hours-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Returns an xsd:integer between 0 and 23, both inclusive, representing the hours component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

5. fn:minutes-from-dateTime

  • Schema:

    ( ?arg ; func:minutes-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Returns an xsd:integer between 0 and 59, both inclusive, representing the minutes component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

6. fn:seconds-from-dateTime

  • Schema:

    ( ?arg ; func:seconds-from-dateTime( ?arg ) )

  • Intended domains:

    The value space of xsd:dateTime for ?arg.

  • Mapping:

    Returns an xsd:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

7. fn:year-from-date

  • Schema:

    ( ?arg ; func:year-from-date( ?arg ) )

  • Intended domains:

    The value space of xsd:date for ?arg.

  • Mapping:

    Returns an xsd:integer representing the year in the localized value of ?arg. The value may be negative.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

8. fn:month-from-date

  • Schema:

    ( ?arg ; func:month-from-date( ?arg ) )

  • Intended domains:

    The value space of xsd:date for ?arg.

  • Mapping:

    Returns an xsd:integer between 1 and 12, both inclusive, representing the month component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

9. fn:day-from-date

  • Schema:

    ( ?arg ; func:day-from-date( ?arg ) )

  • Intended domains:

    The value space of xsd:date for ?arg.

  • Mapping:

    Returns an xsd:integer between 1 and 31, both inclusive, representing the day component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

10. fn:hours-from-time

  • Schema:

    ( ?arg ; func:hours-from-time( ?arg ) )

  • Intended domains:

    The value space of xsd:time for ?arg.

  • Mapping:

    Returns an xsd:integer between 0 and 23, both inclusive, representing the hours component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

11. fn:minutes-from-time

  • Schema:

    ( ?arg ; func:minutes-from-time( ?arg ) )

  • Intended domains:

    The value space of xsd:time for ?arg.

  • Mapping:

    Returns an xsd:integer between 0 and 59, both inclusive, representing the minutes component in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

12. fn:seconds-from-time

  • Schema:

    ( ?arg ; func:seconds-from-time( ?arg ) )

  • Intended domains:

    The value space of xsd:time for ?arg.

  • Mapping:

    Returns an xsd:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of ?arg.

    If an argument value is outside of the intended domain, the value of the function is left unspecified and can vary from one semantic structure to another.

4.6.2 Predicates on Date and Time Values

1. op:dateTime-equal

  • Schema:

    ( ?arg1 ?arg2; pred:dateTime-equal( ?arg1 ?arg2) )

  • Intended domains:

    The value space of xsd:dateTime for both arguments.

  • Mapping:

    where Itruth ο Iexternal( ?arg1 ?arg2; pred:dateTime-equal( ?arg1 ?arg2 ) )(s1 s2) = t

    if and only if op:dateTime-equal(s1, s2) returns true, as defined in XQuery 1.0 and XPath 2.0 Functions and Operators, f in case false is returned, The following schemata are defined analogously with respect to their corresponding operators as defined in XQuery 1.0 and XPath 2.0 Functions and Operators and we only give informal descriptions of the respective mappings Itruth ο Iexternal.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.

2. op:dateTime-less-than

  • Schema:

    ( ?arg1 ?arg2; pred:dateTime-less-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:dateTime for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is less than the value of ?arg2 as defined in op:dateTime-less-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.


3. op:dateTime-greater-than

  • Schema:

    ( ?arg1 ?arg2; pred:dateTime-greater-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:dateTime for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is greater than the value of ?arg2 as defined in op:dateTime-greater-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.

4. op:date-equal

  • Schema:

    ( ?arg1 ?arg2; pred:date-equal( ?arg1 ?arg2) )

  • Intended domains:

    The value space of xsd:date for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 equals ?arg2 as defined in op:date-date-equal.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.


5. op:date-less-than

  • Schema:

    ( ?arg1 ?arg2; pred:date-less-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:date for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is less than ?arg2 as defined in op:date-date-less-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.

6. op:date-greater-than

  • Schema:

    ( ?arg1 ?arg2; pred:date-greater-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:date for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is greater than ?arg2 as defined in op:date-date-greater-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.

7. op:time-equal

  • Schema:

    ( ?arg1 ?arg2; pred:time-equal( ?arg1 ?arg2) )

  • Intended domains:

    The value space of xsd:time for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 equals ?arg2 as defined in op:date-time-equal.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.


8. op:time-less-than

  • Schema:

    ( ?arg1 ?arg2; pred:time-less-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:time for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is less than ?arg2 as defined in op:date-time-less-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.


9. op:time-greater-than

  • Schema:

    ( ?arg1 ?arg2; pred:time-greater-than(?arg1 ?arg2 ) )

  • Intended domains:

    The value space of xsd:time for both arguments.

  • Mapping:

    Returns true if and only if the value of ?arg1 is greater than ?arg2 as defined in op:date-time-greater-than.

    If an argument value is outside of the intended domain, the truth value of the function is left unspecified and can vary from one semantic structure to another.


4.7 Functions and Predicates on rif:text

The following function serves to extract the language tag from values in the rif:text value space.

  • Schema:

    (?arg ; func:lang( ?arg ) )

  • Intended domains:

    The value space of rif:text for ?arg.

  • Mapping:

    Iexternal(?arg ; func:lang( ?arg ) )(s) = res such that res is the language tag string of s, if s is in the value space of rif:text and ""^^xsd:string otherwise.

5 References

[RDF-CONCEPTS]
Resource Description Framework (RDF): Concepts and Abstract Syntax, Klyne G., Carroll J. (Editors), W3C Recommendation, 10 February 2004, http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/. Latest version available at http://www.w3.org/TR/rdf-concepts/.

[RDF-SEMANTICS]
RDF Semantics, Patrick Hayes, Editor, W3C Recommendation, 10 February 2004, http://www.w3.org/TR/2004/REC-rdf-mt-20040210/. Latest version available at http://www.w3.org/TR/rdf-mt/.

[RDF-SCHEMA]
RDF Vocabulary Description Language 1.0: RDF Schema, Brian McBride, Editor, W3C Recommendation 10 February 2004, http://www.w3.org/TR/rdf-schema/.

[RFC-3066]
RFC 3066 - Tags for the Identification of Languages, H. Alvestrand, IETF, January 2001. This document is at http://www.isi.edu/in-notes/rfc3066.txt.

[RFC-3987]
RFC 3987 - Internationalized Resource Identifiers (IRIs), M. Duerst and M. Suignard, IETF, January 2005. This document is at http://www.ietf.org/rfc/rfc3987.txt.

[XDM]
XQuery 1.0 and XPath 2.0 Data Model (XDM), W3C Recommendation, World Wide Web Consortium, 23 January 2007. This version is http://www.w3.org/TR/2007/REC-xpath-datamodel-20070123/.

[XML-SCHEMA2]
XML Schema Part 2: Datatypes, W3C Recommendation, World Wide Web Consortium, 2 May 2001. This version is http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/.

6 Appendix: Schemas for Externally Defined Terms

This section is an edited copy of a section from RIF Framework for Logic Dialects. It is reproduced here for convenience of the reader of the RIF-BLD document who might not be familiar with RIF-FLD.

This section defines external schemas, which serve as templates for externally defined terms. These schemas determine which externally defined terms are acceptable in a RIF dialect. Externally defined terms include RIF built-ins, but are more general. They are designed to also accommodate the ideas of procedural attachments and querying of external data sources. Because of the need to accommodate many difference possibilities, the RIF logical framework supports a very general notion of an externally defined term. Such a term is not necessarily a function or a predicate -- it can be a frame, a classification term, and so on.

Definition (Schema for external term). An external schema is a statement of the form (?X1 ... ?Xn; τ) where

  • τ is a term with the exception that it is not permitted to be a variable or an externally defined term.
  • ?X1 ... ?Xn is a list of all distinct variables that occur in τ

The names of the variables in an external schema are immaterial, but their order is important. For instance, (?X ?Y;  ?X[foo->?Y]) and (?V ?W;  ?V[foo->?W]) are considered to be the same schema, but (?X ?Y;  ?X[foo->?Y]) and (?Y ?X;  ?X[foo->?Y]) are viewed as different schemas.

A term t is an instance of an external schema (?X1 ... ?Xn; τ) iff t can be obtained from τ by a simultaneous substitution ?X1/s1 ... ?Xn/sn of the variables ?X1 ... ?Xn with terms s1 ... sn, respectively. Some of the terms si can be variables themselves. For example, ?Z[foo->f(a ?P)] is an instance of (?X ?Y; ?X[foo->?Y]) by the substitution ?X/?Z  ?Y/f(a ?P).    ☐

Observe that a variable cannot be an instance of an external schema, since τ in the above definition cannot be a variable. It will be seen later that this implies that a term of the form External(?X) is not well-formed in RIF.

The intuition behind the notion of an external schema, such as (?X ?Y;  ?X["foo"^^xsd:string->?Y]) or (?V;  "pred:isTime"^^rif:iri(?V)), is that ?X["foo"^^xsd:string->?Y] or "pred:isTime"^^rif:iri(?V) are invocation patterns for querying external sources, and instances of those schemas correspond to concrete invocations. Thus, External("http://foo.bar.com"^^rif:iri["foo"^^xsd:string->"123"^^xsd:integer]) and External("pred:isTime"^^rif:iri("22:33:44"^^xsd:time) are examples of invocations of external terms -- one querying an external source and another invoking a built-in.


Definition (Coherent set of external schemas). A set of external schemas is coherent if there can be no term, t, that is an instance of two distinct schemas.    ☐

The intuition behind this notion is to ensure that any use of an external term is associated with at most one external schema. This assumption is relied upon in the definition of the semantics of externally defined terms. Note that the coherence condition is easy to verify syntactically and that it implies that schemas like (?X ?Y;  ?X[foo->?Y]) and (?Y ?X;  ?X[foo->?Y]), which differ only in the order of their variables, cannot be in the same coherent set.

It important to understand that external schemas are not part of the language in RIF, since they do not appear anywhere in RIF statements. Instead, they are best thought of as part of the grammar of the language.