Previous topic  Top  Next topic  Print this Topic
 

Data Types

 

Primitive data types are represented by constants of special form: _datatypeName"literal". The underscore _ and the quotes are part of the syntax. datatypeName is the name of the data type and literal is the value-part of the constant. The data type names and their attributes are listed below. The supported data types closely correspond to XML Schema data types.

Note that the form of the data type constants makes no assumption about the actual internal representation of these constants. A variety of options is possible. The compiler can translate such constants to function terms or to external calls to Java or C programs. For instance, a constant of the time data type such as "12:33:44"^^_time can be compiled into a term like $#%&time(12,33,44) or into $#%&time(12,33,44,45224) (45224 is the number of seconds in the time literal and can be used for comparison with other literals) or into Time#@!([49,50,51,51,52,52]) (here the numbers in the list are the ASCII codes of the digits in the date).

We also define syntax for variables that can be bound only to constants of the corresponding data types. The syntax is ?variableName^^datatypeName, where ^^ and ? are part of the syntax, while datatypeName is the name of a data type. For instance, ?Y^^_time.

Some data types, like time, dateTime, etc., are exact analogues of the corresponding XML Schema types. In this case, their names will be denoted using strings that have the form of a IRI. For instance, 'http://www.w3.org/2001/XMLSchema#time'. However, for convenience, all type names will have one or more F-logic specific abbreviated forms, such as _time or _t. These abbreviated forms are case-insensitive. So, _time and _TiMe are assumed to be equivalent. In addition, when the type names have the form of an IRI, the compact prefix representation is supported. For instance, if xsd is a prefix name for 'http://www.w3.org/2001/XMLSchema#' then "12:33:55"^^<http://www.w3.org/2001/XMLSchema#time> can be written as "12:33:55"^^xsd#time'.

The methods that are applicable to each particular primitive type vary from type to type. However, certain methods are more or less common:

_toString, which applies to a data type constant and returns its printable representation. For instance, if ?Y is bound to "12:44:23"^^_time then ?Y[_toString->'12:44:23'] will be true.
_toType( parameters ), which applies to the any class corresponding to a primitive data type (for instance, _time). Most types will have two versions of this method. One will apply to arguments that represent the components of a data type. For instance, _time[_toType(12,23,45)->"12:23:45"^^_time]. The other will apply to the string representation of the data type. For instance, _time[_toType('12:23:45')->"12:23:45"^^_time].
_isTypeOf( constant ), which applies to every data type class (e.g., _time) and determines whether constant has the given primitive type (_time in this example).
_equal( constant ), which tells when the given datatype constant equals some other term.
_lessThan( constant ), which tells when one constant is less than some other terms. For integers, floats, time, dates, durations, and strings, this method corresponds to the natural order on these types. For other types this method returns false.
_typeName, which tells the type name (and thus also class) of the given data type.

 

We now list the supported data types:

_dateTime

Explanation: XML Schema dateTime type.
Normal form:

"ZYYYY-MM-DDTHH:MM:SS.sZHH:MM"^^_dateTime.
The symbols -, :, T, and . are part of the syntax. The leftmost Z is optional sign (-). The part that starts with the second Z is optional and represents the time zone (the second Z is a sign, which can be either + or -; note that the first Z can be only the minus sign or nothing). The part that starts with T is also optional; it represents the time of the specified day. The part of the time component of the form .s represents fractions of the second. Here s can be any positive integer.

 
Class: _dateTime
Synonyms: _dt, <http://www.w3.org/2001/XMLSchema#dateTime>.

Class methods:

_dateTime[_toType(_integer,_integer,_integer,_integer,_integer,_integer,_decimal,_integer,_integer,_integer) => _dateTime]
_dateTime[_toType(_integer,_integer,_integer,_integer,_integer,_decimal,_integer,_integer) => _dateTime]
The meaning of the arguments is as follows (in that order): date sign, year, month, day, hour, minute, second, zone sign,, zone hour, zone minute.
All arguments, except date sign and zone sign, are assumed to be positive integers, while date sign and zone sign can be either 1 or -1. For negative time zones both values have to be negative, for dates the same. Date sign and zone sign are not available.
_dateTime[_toType(_string) => _dateTime]
_dateTime[=> _isTypeOf(_object)] Tells if object belongs to the primitive type _dateTime

Component methods:

_dateTime[_dateSign *=> _integer]
_dateTime[_year *=> _integer]
_dateTime[_month *=> _integer]
_dateTime[_day *=> _integer]
_dateTime[_hour *=> _integer]
_dateTime[_minute *=> _integer]
_dateTime[_second *=> _integer]
_dateTime[_zoneSign *=> _integer]
_dateTime[_zoneHour *=> _integer]
_dateTime[_zoneMinute *=> _integer]

Other methods:

_dateTime[_toString *=> _string]
_dateTime[*=> _equals(_object)]
_dateTime[*=> _lessThan(_object)]
_dateTime[_typeName *=> _string]
_dateTime[_add(_duration) *=> _dateTime]

Examples:

"2001-11-23T12:33:55.123-02:30"^^_dateTime
"2001-11-23T12:33:55.123-02:30"^^<http://www.w3.org/2001/XMLSchema#dateTime>
"-0237-11-23T12:33:55"^^_dateTime
Note that this date refers to year 238 BCE.
"2001-11-23T10:00:00Z"^^_dateTime[_day -> 23]
"2001-11-23T10:00:00Z"^^_dateTime.[_toString -> '2001-11-23T00:00:00+00:00']
"2001-11-23T18:33:44-02:30"^^_dateTime[_add("-P22Y2M10DT1H2M3S"^^_duration) -> "1979-09-13T17:31:41-02:30"^^_dateTime].

_date

Explanation: XML Schema date type.
Normal form:

"ZYYYY-MM-DDSHH:MM"^^_date.
The symbols - and : are part of the syntax. The symbol S represents the timezone sign (+ or -). The timezone part (beginning with S) is optional. The leftmost Z is optional sign (-). Note that unlike _dateTime, which represents a single time point, _date represents duration of a single day.

 
Class: _date
Synonyms: _d, <http://www.w3.org/2001/XMLSchema#date>.

Class methods:

_date[_toType(_integer,_integer,_integer,_integer,_integer,_integer,_integer) => _date]
_date[_toType(_integer,_integer,_integer,_integer,_integer) => _date]
The meaning of the arguments is as follows (in that order): date sign, year, month, day, zone sign, zone hour, zone minute.
All arguments, except date sign and zone sign, are assumed to be positive integers, while date sign and zone sign can be either 1 or -1. For negative time zones both values have to be negative, for dates the same. Date sign and zone sign are not available.
_date[_toType(_string) => _date]
_date[=> _isTypeOf(_object)] Tells if object belongs to the primitive type _date

Component methods:

_date[_dateSign *=> _integer]
_date[_year *=> _integer]
_date[_month *=> _integer]
_date[_day *=> _integer]
_date[_zoneSign *=> _integer]
_date[_zoneHour *=> _integer]
_date[_zoneMinute *=> _integer]

Other methods:

_date[_toString *=> _string]
_date[*=> _equals(_object)]
_date[*=> _lessThan(_object)]
_date[_typeName *=> _string]
_date[_add(_duration) *=> _date]

Examples:

"2001-11-23-02:30"^^_date
"2001-11-23"^^_date,
"-0237-11-23"^^_date
Note that this date refers to year 238 BCE.
"2001-11-23"^^_date[_day -> 23]
"2001-11-23"^^_date[_toString -> '2001-11-23+00:00']
"2001-11-23-02:30"^^_date[_add("-P2Y2M10DT1H2M"^^_duration) -> "1979-09-13-03:32"^^_dateTime].

_time

Explanation: XML Schema time data type
Normal form:

"HH:MM:SS.sZHH:MM"^^_time
The symbols : and . are part of the syntax. The part .s is optional. It represents fractions of a second. Here s can be any positive integer. The sign Z represents the sign of the timezone (+ or -). The following HH represents time zone hours and MM time zone minutes. The time zone part is optional.

 
Synonyms: _t, <http://www.w3.org/2001/XMLSchema#time>.
Class: _time

Class methods:

_time[_toType(_integer,_integer,_decimal,_integer,_integer,_integer) => _time]
_time[_toType(_integer,_integer,_decimal,_integer,_integer) => _time]
The arguments represent hour, minute, second, time zone sign, time zone hour, and time zone minute.
_time[_toType(_string) => _time]
_time[=> _isTypeOf(_object)] Tells if object belongs to the primitive type _time

Component methods:

_time[_hour *=> _integer]
_time[_minute *=> _integer]
_time[_second *=> _integer]
_time[_zoneSign *=> _integer]
_time[_zoneHour *=> _integer]
_time[_zoneMinute *=> _integer]

Other methods:

_time[_toString *=> _string]
_time[*=> _equals(_object)]
_time[*=> _lessThan(_object)]
_time[_typeName *=> _string]
_time[_add(_duration) *=> _time]

Examples:

"11:24:22"^^_time
"11:24:22"^^<http://www.w3.org/2001/XMLSchema#time>
_time[_toType(12,44,55) -> "12:44:55"^^_time]
"12:44:55"^^_time[_minute -> 44]
"12:44:55"^^_time[_toString -> '12:44:55']
"12:44:55"^^_time[_add("P2M3S"^^_duration) -> "12:46:58"^^_time]

_duration

Explanation: XML Schema duration type
Normal form:

"sPnYnMnDTnHnMnS"^^_duration
Here s is optional sign (-), P indicates that this is a duration type, and Y, M, D, H, M, S denote year, month, date, hour, minutes, and seconds. T separates date from time. The symbol n stands for any positive number (for instance, the number of hours can be more than 12 and the number of minutes and seconds can be more than 60. The part that starts with T is optional and some of the elements in the date and the time parts can be omitted.

 
Class: _duration

Synonyms: <http://www.w3.org/2001/XMLSchema#duration>

Class methods:

_duration[_toType(_integer,_integer,_integer,_integer,_integer,_integer) => _duration] The meaning of the arguments (in that order) is: year, month, day, hour, minute, second.
_duration[_toType(_string) => _duration]
_duration[=> _isTypeOf(_object)] Tells if object belongs to the primitive type _duration

Component methods:

_duration[_years *=> _integer]
_duration[_months *=> _integer]
_duration[_days *=> _integer]
_duration[_hours *=> _integer]
_duration[_minutes *=> _integer]
_duration[_seconds *=> _integer]

Other methods:

_duration[_toString *=> _string]
_duration[*=> _equals(_object)]
_duration[*=> _lessThan(_object)]
_duration[_typeName *=> _string]
_duration[_add(_duration) *=> _duration]

Examples:

"P5Y5M10DT11H24M22S"^^_duration
"-P2Y05M10DT11H24M22"^^_duration[_minutes -> 24]

_boolean

Explanation: XML Schema Boolean type
Normal form:

"true"^^_boolean, "false"^^_boolean
or shorter forms: _true, _false

Synonyms: <http://www.w3.org/2001/XMLSchema#boolean>
Class: _boolean

Class methods:

_boolean[_toString => _string]
_boolean[=> _isTypeOf(_object)]

Other methods:

_boolean[_toString *=> _string]
_boolean[*=> _equals(_object)]
_boolean[*=> _lessThan(_object)]
(NOTE: _false[_lessThan(_true)])
_boolean[_typeName *=> _string]

Examples:

"true"^^_Bool, _true, _false

_double

Explanation: XML Schema double type
Normal form:

"value"^^_double
where value is a floating point number of double length that uses the regular decimal point representation with an optional exponent.
Short forms: same representation without "..."^^_double wrapper.

Synonyms: <http://www.w3.org/2001/XMLSchema#double>

Class: _double

Class methods:

_double[_toType(_decimal) => _double] Converts decimals to doubles. Error, if overflow.
_double[_toType(_long) => _double] Converts long integers to doubles.
_double[=> _isTypeOf(_object)]

Other methods:

_double[_floor *=> _integer]
_double[_ceiling *=> _integer]
_double[_round *=> _integer]
_double[_toString *=> _string]
_double[*=> _equals(_object)]
_double[*=> _lessThan(_object)]
_double[_typeName *=> _string]

Examples:

"2.50"^^_double, 2.50, 25E-1

_decimal

Explanation: XML Schema decimal type (arbitrary precision)
Normal form:

"value"^^_decimal
where value is a number that uses the regular decimal point representation. This type is a supertype of _integer.

Synonyms: <http://www.w3.org/2001/XMLSchema#decimal>

Class: _decimal

Class methods:

_decimal[_toType(_string) => _decimal] Converts string to decimal, if string represents a decimal in textual form. If it does not, then the method fails.
_decimal[_toType(_double) => _decimal] Converts doubles to decimals.
_decimal[=> _isTypeOf(_object)]

Other methods:

_decimal[_floor *=> _integer]
_decimal[_ceiling *=> _integer]
_decimal[_round *=> _integer]
_decimal[_toString *=> _string]
_decimal[*=> _equals(_object)]
_decimal[*=> _lessThan(_object)]
_decimal[_toString *=> _string]
_decimal[_typeName *=> _string]

Examples:

"2.50"^^_decimal, "12"^^<http://www.w3.org/2001/XMLSchema#decimal>

_integer

Explanation: XML Schema integers (arbitrary length)
Normal form:

"value"^^_integer
where value is an integer in its regular representation in the decimal system.
_integer is a subtype of _decimal. For instance, "12"^^_integer = "12"^^_decimal = "12.0"^^_decimal, etc.
Note that although XML schema prescribes that _integer must be a supertype of _long, we do not enforce this rule due to the difficulty in implementing it. However, the _equals method is supposed to recognice that _long is a subtype of _integer, i.e., "18"^^_long[_equals("18"^^_int)] must be true and so must be "18"^^_int[_equals("18"^^_long)].

Synonyms:

_int, <http://www.w3.org/2001/XMLSchema#integer>

Class: _integer

Class methods:

_integer[_toType(_string) => _integer] Converts strings to integers, if the string represents an integer in textual form. If it does not then this method fails.
_integer[_toType(_long) => _integer] Converts long to integers.
_integer[=> _isTypeOf(_object)]

Other methods:

_integer[_toString *=> _string] _integer[*=> _equals(_object)]
_integer[*=> _lessThan(_object)]
_integer[_typeName *=> _string]

Examples:

"55"^^_integer, "55"^^_int

_long

Explanation: XML Schema long integers
Normal form:

"value"^^_long
where value is an integer in its regular representation in the decimal system. A shorter form without the "..."^^_long wrapper is also allowed.
Note that although XML schema prescribes that _long must be a subtype of _integer, we do not enforce this rule due to the difficulty in implementing it. However, the _equals method is supposed to recognice that _long is a subtype of _integer, i.e., "18"^^_long[_equals("18"^^_int)] must be true and so must be "18"^^_int[_equals("18"^^_long)].

Synonyms:

<http://www.w3.org/2001/XMLSchema#long>

Class: _long

Class methods:

_long[_toType(_string) => _long] Converts strings to long integers, if the string represents an integer in textual form. If it does not then this method fails.
_long[_toType(_integer) => _long] Converts long integers to arbitrary big integers.
_integer[=> _isTypeOf(_object)]

Other methods:

_long[_toString *=> _string] _long[*=> _equals(_object)]
_long[*=> _lessThan(_object)]
_long[_typeName *=> _string]

Examples:

123, 55, "55"^^_long

_iri

Explanation: IRI as defined by [RFC 2396], as amended by [RFC 2732]
Normal form:

"string IRI representation"^^_iri

Synonyms:

<http://www.w3.org/2007/rif#iri>
<http://www.w3.org/2007/rif#uri>
_"string IRI representation". For instance, "http://foo.bar.com/moo"^^_iri can be written as _"http://foo.bar.com/moo".

 
Class: _iri

Class methods:

_iri[_toType(_string) => _iri]
_iri[=> _isTypeOf(_object)]

Component methods:

_iri[_scheme *=> _string]
_iri[_user *=> _string]
_iri[_host *=> _string]
_iri[_port *=> _string]
_iri[_path *=> _string]
_iri[_query *=> _string]
_iri[_fragment *=> _string]
Note that the exact meaning of the above components depends on the IRI scheme. For http, ftp, file, etc., the meaning the first five components is clear. The query is an optional part of the IRI that follows the ?-sign, and fragment is the last part that follows #. Some components might be optional for some IRI schemes. For instance, for the urn and file schemata, only the path component is defined. For mailto scheme, port, path, query, and fragment are not defined. If a scheme is not recognized then the part of the IRI that follows the scheme goes into the path component unparsed.
_iri[_localName *=> _string]
_iri[_prefix *=> _string]
These two attributes return the local name and prefix of the IRI as defined by RDF best practices. **** Define local names! **** The prefix is the part of the IRI that precedes the local name.

Other methods:

_iri[_toString *=> _string]
_iri[*=> _equals(_object)]
_iri[_typeName *=> _string]

Examples:

_"http://foo.bar.com/abc"
"http://foo.bar.com/abc"^^_iri
_iri[_toType('http://foo.bar.com/abc') -> "http://foo.bar.com/abc"^^_iri]
_"http://foo.bar.com/abc"[_host -> 'foo.bar.com']

_string

Explanation: XML Schema string type

Characters can be Unicode characters, excluding the surrogate blocks FFFE and FFFF.

Synonyms: http://www.w3.org/2001/XMLSchema#string

Normal form:

"value"^^_string
A shorter form 'value' is also allowed.
Single-quoted sequence of characters. Alphanumeric strings that start with a letter do not need to be quoted. In the full representation (with the "..."^^_string wrapper), the double quote symbol and the backslash must be escaped with a backslash. In short representation, the single quote symbol and the backslash must be escaped with a backslash.

Class: _string

Class methods:

_string[=> _isTypeOf(_object)]

Other methods:

_string[*=> _equals(_object)]. Binding: bb.
_string[*=> _lessThan(_object)]. Binding: bb.
_string[_typeName *=> _string]. Bindings: bf, bb.
_string[*=> _contains(_string)]. Binding: bb.
_string[_concat(_string) *=> _string]. Bindings: fbb, bfb, bbf, bbb
_string[_cut(_integer) *=> _string]. Bindings: bbf, bbb. Returns a substring of the string-object truncated by the number of characters specified in the method argument. Truncation takes place on the right.
_string[_fill(_string) *=> _string]. Bindings: bbbf, bbbb. Fills the object-string with a letter from the first method argument up to the length specified in the second method argument. For instance, abc[_fill(D,7) -> abcDDDD].
_string[_match(_string) *=> _list]. Bindings: bbf, bbb. The result of the method is a list of terms of the form match(matchingPosition,matchingSubstring), which represents matches inside the object-string. The match is done against a Perl regular expression given as the method argument. The list is sorted in the ascending order of positions of the matches. The counting of positions in the object string starts with 0.
_string[_indexOf(_string) *=> _int]. Bindings: bbf, bbb. The result of this method is a list of positions at which the string given as argument to the method matches within the object string. The positions in the list are ordered in the ascending order.
_string[_lastIndexOf(_string) *=> _int]. Bindings: bbf, bbb. The result of this method is a list of positions at which the string given as argument to the method matches within the object string. The positions in the list are ordered in the descending order.For this behaviour, use _indexOf together with reverse. This implementation delivers just the last position.
_string[_firstIndexOf(_string) *=> _int]. Bindings: bbf, bbb. This method is added from us. It delivers just the first position.
_string[_replace(_string,_string) *=> _string]. Binding: bbbf, bbbb. Replaces every occurrence of the Perl regular expression inside the object string with the string given in the second argument of the method. The Perl regular expression is given in the first argument.
_string[_split(_string) *=> [_string,_string]]. Binding: bbf, bbb. Splits the object-string by the regular expression given in the method argument. The split occurs at the first character of the first match. The result is a list of two strings obtained by the split. For instance, Eddie[_split(d) -> [E,ddie]].
_string[_reverse *=> _string]. Bindings: bf, fb, bb.
_string[_length *=> _integer]. Binding: bf, bb.
_string[_tokenize(_string) *=> _list]. Bindings: bbf, bbb. Breaks the object-string into a list of tokens at every occurrence of any delimiter character given in the argument to the method (this argument is a string of delimeter characters). The delimiter characters are not retained as part of the tokens. For instance, 'xyzw.foo'[_tokenize('y.') -> [x,zw,foo]].
_string[_toUpper *=> _string]. Bindings: bf, bb. The value of the method is the object string with all characters converted to the upper case.
_string[_toLower *=> _string]. Bindings: bf, bb. The value of the method is the object string with all characters converted to the lower case.
_string[_charAt(_integer) *=> _string]. Bindings: bbf, bbb. The value of the method is the character that occurs in the object string at the position given by the argument to the method. Positions start with 0.
_string[_diffAt(_string) *=> _number_integer]. Bindings: bbf, bbb. The result of the method is the first position where the object string and the method argument differ. Positions start with 0. The the truth value is false if the two strings are equal.
_string[*=> _startsWith(_string)]. Binding: bb.
_string[*=> _endsWith(_string)]. Binding: bb.
_string[_substring(_integer,_integer) *=> _string]. Binding: bbbf.and: bbbb Returns a substring of the object string, where the starting and the ending position of the substring are given by the arguments of the method. -1 in argument 2 means the end of the string.
_string[_trim(_string) *=> _string]. Bindings: bbf, bbb. Deletes from the object string all the leading and trailing characters specified in the argument to the method. For instance, ' .ab c,\n'[_trim('\n\r .,') -> 'ab c'].
_string[_overlappedBy(_string) *=> _integer]. Bindings: bbf, bbb. True if a suffix of the object string is also a prefix of the string given in the method's argument. The result of the method is the number of characters in the maximal overlap.

Examples:

"abc"^^_string
'abc'
"a string\n"^^_String
'a string\n'
'a\tstring\b'
'string with a \'quoted\' substring'

_PlainLiteral

Explanation: XML Schema string type with additional language tag. NOTE: this data type is currently under discussion at W3C, so the specifics might change.

This is like _string, but the same string with different language tags are considered different. _text is a subtype of _string, so all of the methods of _string are applicable to _text. We don't support this subtype property, because we could not decide what type to generate as result. If needed, _text has to be converted to string explicitly. The language tag can be also ISO-639-1 (or ISO-639-2) to specify encodings.

Synonyms: http://www.w3.org/2007/rif#text

Normal form:

"value@language"^^_text
Escaping conventions are the same as for _string.

Class: _text

Class methods: See _string

Other methods:

See _string.
_text[_language *=> _string]. Binding bf, bb. Get the language of the string.
_text[_text *=> _string]. Binding: bf, bb. Gets the text without the language tag.

Examples:

"abc@en"^^_text
"a string\n@en"^^_Text

_list

Explanation: The Prolog type of list.
Normal form:

[elt1, ..., eltn], [elt1,...,eltn|List]
This is the usual type for list terms.

Class: _list

Class methods:

_list[=> _isTypeOf(_object)]
_list[_toType(_object,_list) => _list]
This method is here for completeless only. It defined simply as _list[_toType(obj,list) => [obj|list], for all objects obj and lists list.

Other methods:

_list[_toString *=> _string]
_list[*=> _lessThan(_object)]
_list[*=> _equals(_object)]. Binding: bb.
_list[_typeName *=> _string]
_list[*=> _contains(_list)]. Binding: bb. Tells if a list object contains the method's argument as a sublist.
_list[*=> _member(_object)]. Binding: bb. The method's argument and the list-object may not be fully ground. In this case, the method succeeds, if the argument to the method unifies with a member of the list.
_list[_append(_list) *=> _list]. Bindings: fbb, bfb, bbf, bbb
_list[_indexOf(_object) *=> _long]. Bindings: bbf, bbb. The result of this method is the first position at which the argument-object unifies with the list-object.
_list[_length *=> _long]. Binding: bbbf, bbbb. Computes the length of the list.
_list[_reverse *=> _list]. Bindings: bf, fb, bb.
_list[_sort *=> _list].
_list[_memberAt(_integer) *=> _object]. Bindings: bbf, bbb. The value of the method is the object that occurs in the list object at the position given by the argument to the method. Positions start with 0.
_list[*=> _startsWith(_list)]. Binding: bb.
_list[*=> _endsWith(_list)]. Binding: bb.
_list[ *=> _subset(_list)]. Binding: bb. True if the list object contains the argument list.
_list[_overlappedBy(_list) *=> _integer]. Bindings: bbf, bbb. True if a suffix of the list object is also a prefix of the list given in the method's argument. The result of the method is the number of characters in the maximal overlap.

Examples:

[a,b,c]
[a,b|?X]
[a,b,c|[d,e]]

_XMLLiteral

Explanation: XMLLiteral type of RDF.

An XML literal is a string that contains a well-formed fragment of XML text. _XMLLiteral is a subtype of _string, so all of the methods of _string are applicable to _text. We don't support this subtype property, because we could not decide what type to generate as result. If needed, _XMLLiteral has to be converted to string explicitly.

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

Normal form:

"some fragment of XML"^^_XMLLiteral

Class: _XMLLiteral

Class methods: See _string

Other methods:

See _string.
Should add a path expression method.

Examples:

"<foo>bar</foo>"^^_XMLLiteral

 

map data typ

Mapping between Java objects and ObjectLogic

Example:
BLZ Service of the Deutsche Bundesbank, see
http://www.thomas-bayer.com/axis2/services/BLZService?wsdl
Generating the Java client for this web service results in (simplified here):

 
Java

interface BLZService {

  Details getDetails(String blz);

}

class Details {

  String bezeichnung;

  String bic;

  String ort;

  String plz;

}

 

A web service call from ObjectLogic could look like this:

?- _callWebservice("http://bundesbank/services/BLZService",
 "getDetails", [blz->"66010075"],?Result).

 

Internally the input parameters, here the single parameter “blz” is extracted from the input map and the web service is called via the generated Java client. The result is returned in a Details object. This object is mapped into a map constant term:

?Result = [bezeichnung->"Postbank Karlsruhe",
 bic->"PBNKDEFF",ort->"Karlsruhe",plz->"76127"]

 

Mapping between XML and ObjectLogic

Using both maps and lists, it would become possible to map XML directly into an ObjectLogic constant term without loosing the hierarchical structure and sequence order. This would be very similar to the mapping between XML and JSON.
Example:
XML

  <animals>      

  <dog id="1">

            <name>Rufus</name>

            <breed>labrador</breed>

      </dog>

      <dog id="2">

            <name>Marty</name>

            <breed>whippet</breed>

      </dog>

      <cat name="Matilda"/>

  </animals>

 
ObjectLogic

?X = [animals->[

 [dog->[
         [id->1,name->"Rufus",breed->"labrador"],
         [id->2,name->"Marty",breed->"whippet"]

  ],

  cat->[

         [name->"Matilda"]

  ]

 ]

   ]

 

Options parameter for built-ins

Example:

?- _queryIndex(module,[return(type),return(title),includeAll,stringMetric("Jaro")],
 "searchString",0,10,?OBJ,?TC,?SCORE,?ORDER,?OPT).

 

Using the map data type this becomes more readable to

?- _queryIndex(module,
[return->{type,title},includeAll->true,stringMetric-> "Jaro")],
"searchString",0,10,?OBJ,?TC,?SCORE,?ORDER,?OPT).

 

Result parameter for built-ins with variable content structure

Sometime built-ins need to return variable result sets depending on the options. This has already been needed in the above web service example. Another example is here also the _queryIndex/10 built-in, where the ?OPT variable returns variable a list of functions, which is hard to pass directly in ObjectLogic.

 
For the above example, the ?OPT variable currently returns things like
?OPT = [type("c"),title("Reparaturanleitung")]

Using the map data type, this would be instead
?OPT = [type->"c",title->"Reparaturanleitung"]

Specification Details

The syntax is just an overloading of the list syntax. The square brackets would contain key/value pairs instead of terms. Mixing terms and key/value pairs is forbidden, also the head/tail syntax used for lists.

Assignments

ObjectLogic syntax

Description

?X=[]

Empty list (special constant)

?X=[->]

Empty map (special constant)

?X=[1,2,3]

list

?X=[1|?Y]

List head / tail

?X=[a->1,b->2]

Map

?X=[a->{1,2,3},b->[1,2]]
equivalent to

?X=[a->1,a->2,a->3,b->[1,2]]

Multi-valued map. Note the difference between the values for a and b.

a is multi-valued, but b has a list as value.

?X = [1,a->b]  // invalid

Mixing of list terms and key value pairs is not allowed. ObjectLogic compiler must throw exception

 

Facts

p([a->1,b->2]).

Predicate p/1 with a map term as first argument

 

Rules , Queries, Built-ins

p([?X->?Y]) :- r(?X,?Y).

map in rule head

p(?Z) :- ?Z = [?X->?Y], r(?X,?Y).

same as above

?- ?M = collectmap { ?X,?Y | r(?X,?Y) }.
 
translates into:

?- _aggr_collectmap([],[?X,?Y], ?X, ?Y, ?M), r(?X,?Y)).

Aggregation collectmap to collect key/value pairs in one map
 
 

?- [a->{1,2},b->3][_memberAt(?X)->?Y].
 

returns:
?X = a, ?Y = 1
?X = a, ?Y = 2
?X = b, ?Y = 3

Extended built-in _memberAt/3 to extract keys and/or values from a map

?- [a->{1,2},b->3,c->4][_intersection([a->1, c->5])->?X].
 
returns:

?X = [a->1]

Built-in _intersection/3 to create intersection of two maps

?- [a->{1,2},b->3,c->4][_union([a->1, c->5])->?X].
 
returns:

?X = [a->{1,2},b->3,c->{4,5}]

Built-in _union/3 to create union of two maps

?- [a->{1,2},b->3,c->4] [_difference([a->1, c->5])->?X].
 
returns:

?X = [a->2,b->3,c->4]

Built-in _difference/2 to remove all key/value pairs of argument1 from argurment 0

?- [b->1,a->4,a->2][_normalize->?X].

 

returns:
?X = [a->{2,4}, b->1]

Built-in _normalize/2 to bring map in internal order

?- _map[_toType(a,2)->?X].

 

returns:
?X = [a->2]

Extended built-in _toType/4 to generate singleton map

?- ?M = [a->[b->[1,2], c->3], d->4], _memberByPath(?M,_path(a,b),?V).

 

returns

?V = [1,2]

Built-in _memberByPath/3 to filter with xpath expression

?- ?M = [a->[b->[1,2], c->3], d->4], _map2table(?M,?P,?I,?V).

 

returns

P      I      V

---------------

"a.b"  0      1

"a.b"  1      2

"a.c"  0      3

"d"    0      4

 

 

?- ?M = [a->[b->{1,2}, c->3], d->4], _map2table(?M,?P,?I,?V).

 

returns

P      I      V

---------------

"a.b"  0      1

"a.b"  1      2

"a.c"  0      3

"d"    0      4

Built-in _map2table/4 to convert a map to flat table. Note that list values are converted to flat table too.

?- [a->1,b->2] == [b->2,a->1].

 

returns:

true

_equals/2 should be extended to compare maps independently from the order

 

Side remark: Mapping ObjectLogic instances to and from maps

Interestingly, you can also extract all attribute values of an ObjectLogic instance into a map. It “strips” off the instance and leaves the blank attribute map.

 

Example 1 (flat):

juergen[name->"Jürgen", age->28].

?- ?M = collectmap { ?Z | ?Z=[?X,?Y], juergen[?X->?Y] }.

 
results in:
?M = [name->"Jürgen", age->28]

 

Example 2 (hierarchical):

juergen:Person[name->"Jürgen", age->28, address->ja].

ja:Address[street->"An der RaumFabrik", ort->"Durlach"].

?- ?M = collectmap { ?Z
| ((?Z=[?X,?Y], NOT ?Y:?)

     OR (?M1 = collectmap {?Z1 | ?Z1=[?X1,?Y1], ?Y[?X1->?Y1]}, ?Y:?), ?Z=[?X,?M1]), juergen[?X->?Y] }.

 
results in:
?M = [name->"Jürgen", age->28,
 address->[street->"An der RaumFabrik", ort->"Durlach"]].

Implementation

Maps are stored as functions internally. The function symbol is $m and the arguments are a sequence of key value pairs. This implies that the key value pairs are ordered and that a key can have multiple values.

Therefore [a->b,c->d] does not unify with [c->d,a->b]. If you need to unify maps, use the normalize built-in to bring the key/value pairs in a the same order.

ObjectLogic term

Description

Internal Representation

[]

Empty list (special constant)

[]

[->]

Empty map (special constant)

[->]

[1,2,3]

list

$l(1,$l(2,$l(3,[])))

[1|?Y]

List head / tail

$l(1,?Y)

[a->1,b->2]

Map

$m(a,1,b,2)

[a->{1,2,3},b->[1,2]]

Multi-valued map. Note the difference between the values for a and b. a is multi-valued, but b has a list as value.

$m(a,1,a,2,a,3,b,$l(1,$l(2,[])))

 

from the copyright of the web page http://forum.projects.semwebcentral.org/forum-syntax.html