Libretto Language: Built-in Functions

1 Sequence function

2 String function

3 Date/Time Function

4 Input/output function

5 Ontobox model function

6 Map Function

7 Meta function

8 XML Function


1 Sequence function

complement/1

description:
Subtracts from the context sequence the elements of the sequence in the 1st argument (set subtraction).
format:
any* complement($sub any*) any*
type:
Collection-wise

complement/2

description:
Subtracts from the sequence in the 2nd argument the elements of the 1st argument.
format:
void complement($seq1 any*, $seq2 any*) any*
type:
Static

count/0

description:
Counts the number of elements in the collection
format:
any* count() integer
type:
Collection-wise

difference/1

description:
Finds those elements of the two sequences, which do not belong to both (symmetric difference).
format:
any* difference($seq any*) any*
type:
Collection-wise

difference/2

description:
Finds those elements of the two sequences, which do not belong to both (symmetric difference).
format:
void difference($seq1 any*, $seq2 any*) any*
type:
Static

distinct/0

description:
Removes the repetitions of values in the collection
format:
any* distinct() any*
type:
Collection-wise

enum/2

description:
Lazily generates the sequence of integers between $start and $end with step 1.
format:
void enum($start int, $end int) int
type:
Iterator
examples:
enum(1, 100)enum(4, -2) # = (4,3,2,1,0.-1,-2)

enum/3

description:
Lazily generates the sequence of integers between 'start' and 'end' with step 'stetp'. The step can be negative.
format:
void enum($start int, $end int, $step int) int
type:
Static

head/0

description:
Returns the head of the context sequence
format:
any* head() any
type:
Collection-wise

i/1

description:
Returns $indx'th element of the collection. If $indx < 0, it counts the element from the end of the sequence, that is, takes (size() + $indx)'th element (for the last element $indx = -1). i/1 is a collection-wise version of the 'at' operation.
format:
any+ i($indx int) any
type:
Collection-wise
examples:
(1,2,3)/v:i(0); # = (1)(1, 2, 3) / v:i(-1); # = (3)

in/1

description:
Checks if the element belongs to the sequence. Actually $elem/in($set) has about the same semantics as $elem = $set, but performs much more efficiently.
format:
any in($set any+) any+
type:
Element-wise

in/2

description:
A static version of in/1. As a syntactic sugar, in (as well as ∈) can be used as the infix operation, like in 1 in (1,2,3).
format:
void in($elem any, $set any+) any+
type:
Static

intersection/1

description:
Intersects the two sequences as multisets.
format:
any* intersection($seq any*) any*
type:
Collection-wise

intersection/2

description:
Intersects the two sequences as multisets.
format:
void intersection($seq1 any*, $seq2 any*) any*
type:
Static

iter/1

description:
Creates an iterator and returns the first value of the collection. In calculations an iterator is equal to its current value (hidden). To get the next value the built-in next/1 is used.
format:
void iter($col any*) any
type:
Static
examples:
function int sum($x int) {
    if ($x) $x + sum( next($x) )
    else 0    
};

sum( iter((1,2,3,4,5)) );

last/0

description:
Returns the last element of the context sequence
format:
any* last() any
type:
Collection-wise

next/1

description:
Returns the next value of the iteratation hidden in val
format:
fn:next(val as IteratedValue)
type:
Static

reduceLeft/1

description:
Reduces the context sequence by iterating over it pair by pair and applying a binary function (in the argument).
format:
any+ reduceLeft($binaryfun expr) any
type:
Collection-wise
examples:
(1,2,3,4,5) / v:reduceLeft(_($x, $y) {$x * $y});   # = 120

def plus($x, $y) {$x + $y};
(1,2,3,4,5) / v:reduceLeft(%plus^2);    # = 15

reverse/0

description:
Reverses the order of elements in the context sequence.
format:
any* reverse() any*
type:
Collection-wise
examples:
(1, 2, 3) / reverse(); # = (3, 2, 1)

slice/2

description:
Returns the sub-sequence of the context sequence starting at the position start (the first position number is 0) and having length length. If length < 0, the function collects all elements from the start position to the end of the sequence. If start < 0, the function counts down the starting position from the end of the collection (the last element has number -1).
format:
any* slice($start int, $length int) any*
type:
Collection-wise
examples:
(1,2,3,4,5,6,7)/slice(2, 3) # = (3,4,5)(1,2,3,4,5,6,7)/slice(3, -1) # = (4,5,6,7)(1,2,3,4,5,6,7)/slice(-2, 2) # = (5,6)(1,2,3,4,5,6,7)/slice(-2, -1) # = (1,2,3,4,5,6)

splitSequence/1

description:
Splits the context collection by portions of $lng elements. Each portion is formed as a map object with two properties: @key contains the number of the starting element in the initial collection; @value contains the sequence of elements in the portion.
format:
any* splitSequence($lng int) map:Map*
type:
Collection-wise
examples:
(1,2,3,4,5,6,7)/splitSequence(3)/("[{@key}] {@value/join(\"-\")}"!); # = ("[0] 1-2-3", "[3] 4-5-6", "[6] 7")

splitSequence/2

description:
Splits the context collection by the condition defined as an anonymous function $checkpath. The result is a sequence of temporary anomymous objects having property $keyname of which contain the portion of elements from the context collection.
format:
any* splitSequence(checkpath, keyname as xsd:string) map:Map*
type:
Collection-wise

splitSequence/3

description:
Splits the context sequence by portions depending on the splitting $type: Each portion is represented by a temporary map element
&&{key := eval($keypath), value := <the portion of elements>}  

$chkpath is a quoted expression. If it is true, then the current input value is the split point.

$keypath is a quoted expression determining @key of the next portion of the sequence.

The possible values of $type are
"different" - the initial collection is splitted between two neighbor elements, if the value of $chkpath on them is different
"starts" - the element starts new portion if $chkpath on it is true (non-empty)
"ends" - the next portion starts immediately after the elements, on which $chkpath is true (non-empty) $chkpath selects elements determining splitting $key
"between" - the elements, on which $chkpath is true (non-empty) split the sequence
format:
any* splitSequence($chkpath token, $keypath token, $type string) map:Map*
type:
Collection-wise
examples:
(1,2,3,4,5) / v:splitSequence(_{. mod 2 = 0}, _{.}, "starts");

splitSequence/5

description:
The same as splitSequence/3 but the user can determine his/her own property names of map objects:
&&{<$keyname> := eval(<$keypath>), <$valuename> := <the portion of elements>}
format:
any* splitSequence($chkpath token, $keypath token, $type string, $keyname string, $valuename string) map:Map*
type:
Collection-wise

subtraction/1

description:
Subtracts from the context sequence the elements of the sequence in the 1st argument (set subtraction).
format:
any* subtraction($sub any*) any*
type:
Collection-wise

subtraction/2

format:
void subtraction($seq1 any*, $seq2 any*) any*
type:
Static

tail/0

description:
Returns the tail (all elements except the first) of the context sequence.
format:
any* tail() any*
type:
Collection-wise

union/1

description:
Unifies the two sequences as multisets.
format:
any* union($seq any*) any*
type:
Collection-wise

union/2

description:
Unifies the two sequences as multisets.
format:
void union($seq1 any*, $seq2 any*) any*
type:
Static


2 String function

binBase64Hex/0

description:
Converts the context string in the Base64 format to the string in the hexadecimal format
format:
string(base64) binBase64Hex() string(hex)
type:
Element-wise
examples:
("R0lGODlhAQABAIAAAAB9QwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==") / binBase64Hex() # = ("47494638396101000100800000007d4300000021f90400000000002c00000000010001000002024401003b")

binHexBase64/0

description:
Converts a binary in the hexadecimal string format to string Base64 formt
format:
string(hex) binHexBase64() string(base64)
type:
Element-wise
examples:
("47494638396101000100800000007d4300000021f90400000000002c00000000010001000002024401003b") / fn:hexToBin(); # = ("R0lGODlhAQABAIAAAAB9QwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")

charAt/1

description:
Returns the unicode number of the character at $position.
format:
string* charAt($position int) int*
type:
Element-wise

codesString/0

description:
Returns the string obtained from the ordered collection of integers.
format:
int* codesString() string
type:
Collection-wise
examples:
(100, 101, 102)/codesString(); # = ("def")(100, 101, 102)[codesString()="def"]; # = (100, 101, 102)(100, 101, 102)[codesString()="efg"]; # = ()

codesStrings/1

description:
Returns the collection of strings obtained from the ordered collection of integers. $separator is an integer, which separates strings.
format:
int* codesStrings($separator int) string*
type:
Collection-wise
examples:
(101, 100, 102, 100, 103) / codesStrings(100); # = ("e", "f", "g")(101, 100, 102, 100, 103)[codesStrings(100) = "f"]; # = (101, 100, 102, 100, 103)(101, 100, 102, 100, 103)[codesStrings(100) = "h"]; # = ()

compare/1

description:
Returns -1, 0, 1 if the context string is less than, equal to or greater than $str, respectively. If the context object or the argument is not a string, nothing is returned.
format:
string compare($str string)
type:
Element-wise
examples:
("a", "b", "c")/compare("b"); # = (-1, 0, 1)("a", "b", "c")[compare("b")<=0]; # = ("a", "b")

contains/1

description:
Lets the context string through if and only if it contains $str as a substring
format:
string contains($str string) string
type:
Element-wise

endsWith/1

description:
lets through the context string value, which ends with the string $str, nothing otherwise.
format:
string endsWith($str string) string
type:
Element-wise
examples:
("john", "paul", "james", "tom", "jan")[endsWith("n")]; # = ("john", "jan")

group/1

description:
Returns the value of i-th group after the application of matches/3 in regexp. Depricated! It is recommended to use special variables $_m0, ..., $_m9 instead.
format:
group($gr integer) string
type:
Element-wise

join/0

description:
is equivalent to join/1("").
format:
string* join() string
type:
Collection-wise

join/1

description:
Joins the collection of strngs with optional separator. If no separator needed, use $separator = "".
format:
string* join($separator string) string
type:
Collection-wise
examples:
("a", "b", "c")/join(" - "); # = ("a - b - c")("a", "b", "c")[join(" - ") = "a - b - c"]; # = ("a", "b", "c")("a", "b", "c")[join(" = ") = "a - b - c"]; # = ()

join/3

description:

Splits the input sequence of strings into a number of groups with further merging of these groups into single strings.

$condition - the quoted expression desribing the condition of splitting the input sequence into the groups. If the condition is satisfied on an input element, the next group of strings starts.

$type - the type of handling splitting elements. If

    $type = "starts"
then the splitting element starts the new group. If
    $type = "ends"
then the splitting element terminates the previous group. If
    $type = "ends"
then the splitting element is excluded.
format:
string* join($condition expr, $type string("starts", "ends", "between"), $separator string) string
type:
Collection-wise
examples:
("abc", "def", "a12", "a34", "yy", "zz") / v:join(_{v:char-at(0) = 97}, "starts", "-");   # = ("", "abc-def", "a12",  "a34-yy-zz")
("abc", "def", "a12", "a34", "yy", "zz") / v:join(_{v:char-at(0) = 97}, "ends", "-");    # = ("abc", "def-a12", "a34" "yy-zz")
("abc", "def", "a12", "a34", "yy", "zz") / v:join(_{v:char-at(0) = 97}, "between", "-");    # = ("", "def", "", "yy-zz")

length/0

description:
Returns the length of the context string
format:
string length() int
type:
Element-wise
examples:
("1", "12", "123", "1234")/length(); # = (1, 2, 3, 4)("1", "12", "123", "1234")[length() > 2]; # = ("123", "1234")

lower/0

description:
Returns the modified input string, in which each upper-case letter is replaced with its lower-case counterpart. All the other characters stay in their original form.
format:
string lower() string
type:
Element-wise
examples:
("AaBbCc", "12Aab")/lower(); # = ("aabbcc", "12aab")

matchAll/2

description:
This iterator finds all substrings of the context string, which match the $pattern. $flags are the same as for match/2.
format:
string matchAll($pattern string, $flags string) string +
type:
Iterator
examples:
"11a222"/v:matchAll(«\d+», "")
    # = ("11", "222")

"11a222"/v:matchAll(«(\d)\d*», "")/"{.} / {$_m1}"!;
    # = ("11 / 1", "222 / 2")

match/2

description:
The function returns true if $input matches the regular expression supplied as $pattern; otherwise, it returns false.
Unless the metacharacters ^ and $ are used as anchors, the string is considered to match the pattern if any substring matches the pattern. But if anchors are used, the anchors must match the start/end of the string (in string mode), or the start/end of a line (in multiline mode). Special variables $0, $1,..., $9 are assigned substrings of the input string matching the segments of $pattern encloded in (...), as usual. Variables $0, $1... are global in the context of Libretto.
Flags: - m: If present, the match operates in multiline mode. Otherwise, the match operates in string mode. - i: If present, the match operates in case-insensitive mode. Otherwise, the match operates in case-sensitive mode. In case-sensitive mode, a character in the input string matches a character specified by the pattern only if the Unicode code-points match. In case-insensitive mode, a character in the input string matches a character specified by the pattern if there is a canonical caseless match between the two characters as defined in section 2.5 of Unicode Case Mappings.
format:
string match($pattern string, $flags string) string
type:
Element-wise
examples:
("Aaaaab")/match("(a*)(b)", "i"); # = ("Aaaaab")

nl/0

description:
Returns a new line string (Java's System.getProperty("line.separator"))
format:
void nl() string
type:
Static

readChars/0

description:
The iterator producing the sequence of characters in the order of their occurence in the context string. Returns the character unicode numbers.
format:
string readChars() int*
type:
Element-wise
examples:
"12345"/v:readChars(); # = (49, 50, 51, 52, 53)

readLines/0

description:
The iterator lazily generating the sequence of lines of the context string.
format:
string readLines() string*
type:
Element-wise
examples:
"1\n2\n3"/v:readLines() # = ("1", "2", "3")

replace/3

description:
The function returns a string that is obtained by replacing all non-overlapping substrings of the context string, that match the given $pattern with the instantiated $replacement string.
If two overlapping substrings of the context string both match the $pattern, then only the first one (that is, the one whose first character comes first in the $input string) is replaced. Within the $replacement string, the variables $1 to $9 may be used to refer to the substring captured by each of the first nine parenthesized sub-expressions in the regular expression. A literal $ symbol must be written as \$. For each match of the pattern, these variables are assigned the value of the content of the relevant captured sub-expression, and the modified replacement string is then substituted for the characters in $input that matched the pattern.
Flags are the same as for matches/2
format:
string replace($pattern string, $replacement string, $flags string) string
type:
Element-wise
examples:
("...012...a1b...", " D1d ")/replace("(.)1(.)", "$21$1", ""); # = ("...210...b1a...", " d1D ")("012", "D1d")[replace("(.)1(.)", "$21$1", "")/contains("2")]; # = ("012")

sha/1

description:
Generates the hash number for the string in the 1st argument.
format:
void sha($str string) string (hash number)
type:
Static

split/2

description:
Splits the context string into a collection of strings, treating any substring which matches $pattern as a separator. Flags are interpreted as in matches/2
format:
string split($pattern string, $flags string) string*
type:
Element-wise
examples:
("...012...a1b", "-D1d-")/split("\d", ""); # = ("...", "", "", "...a", "b", "-D", "d-")("...012...a1b", "-D1d-")[split("\d", "")/length() = 1]; # = ("...012...a1b") # the split collection of the first string contains "b".

startsWith/1

description:
Lets through the context string value, if it starts with $str.
format:
string startsWith($str string) string
type:
Element-wise
examples:
("john", "paul", "james", "tom", "jan")/startsWith("j"); # = ("john", "james", "jan")

stringCodes/0

description:
Returns the ordered collection of integers obtained by decoding the strings of the context string
format:
string stringCodes() int*
type:
Element-wise
examples:
("abc", "def")/stringCodes(); # = (97, 98, 99, 100, 101, 102)("abc", 1, "def")/stringCodes(); # = (97, 98, 99, 100, 101, 102) # integer is ignored("abc", "def")[stringCodes()=100]; # = ("def") # 100 is the code for 'd'. Strings encoded separately in the predicate, because the function is element-wise.

stringPad/1

description:
Returns a string consisting of $counter copies of the context string concatenated together without any separators. Returns the zero-length string if $counter = 0.
format:
string stringPad($counter int) string
type:
Element-wise
examples:
("a", "bc")/stringPad(5); # = ("aaaaa", "bcbcbcbcbc")("a", "bc")[stringPad(5)/length() = 5]; # = ("a")

stringsCodes/1

description:
Returns the ordered collection of integers by decoding the strings of the input collection and separating them with $separator.
format:
string* stringsCodes($separator int) int*
type:
Collection-wise
examples:
("abc", "def")/stringsCodes(0); # = (97, 98, 99, 0, 100, 101, 102)("", 1, "")/stringsCodes(115); # = (115) # integer is ignored("abc", "def")[stringsCodes(0) > 100]; # = ("abc", "def") # checks the whole("abc", "def")/stringsCodes(0)[. > 100]; # = (101, 102)

substring/2

description:
Returns a substring of the input string starting at $location and continuing for $length characters. If the location and length are floats, then those chars are selected, whose position $p obeys
round($location) <= $p < round($location) + round($length) 
The first character starts at position 1. If $location < 0 then the substring starts from the end of the string. If $length < 0 then the substring continues till the end (the beginning if $location < 0) of the string.
format:
string substring($location {int, long, float}, $length {int, long, float}) string
type:
Element-wise
examples:
("123456789")/substring(3, 2); # = ("34")("123456789")/substring(3.2, 2.7); # = ("345")("123456789")/substring(-3, 2); # = ("67")("123456789")/substring(3, -1); # = ("3456789")("123456789")/substring(-3, -1); # = ("1234567")("123456789", "abscde")/substring(-3, 3); # = ("567", "bsc")("123456789", "abscde")[substring(-3, 3)="bsc"]; # = ("abscde")("123456789", "abscde", "a", 2)/substring(-3, 3); # = ("567", "bsc") # string "a" is too short, thus ignored. Integer is also ignored.

trim/0

description:
Returns a copy of the string, with leading and trailing whitespace omitted.
format:
string trim() string
type:
Element-wise
examples:
(" 123 ")/trim(); # = ("123")(" ", " 123 ")[trim()=""]; # = (" ")

upper/0

description:
Returns the modified context string, in which each lower-case letter is replaced with its upper-case counterpart. The other characters stay in their original form.
format:
string upper() string
type:
Element-wise
examples:
("AaBbCc", "12Aab")/upper(); # = ("AABBCC", "12AAB")


3 Date/Time Function

dateAddTimezone/11

description:
Defines the time zone in the system with the specified daylight offset. Times are measured in miliseconds.
format:
dateAddTimezone($tz-id string, $offset int, $daylight-start-month string, $daylignt-start-date, $daylight-start-day string, $daylight-start-time int, $daylight-end-month string, $daylignt-end-date, $daylight-end-day string, $daylight-end-time int, $summer-offset int)
type:
Static
examples:
dateAddTimezone("asia/irkutsk", 3600000*8, "mar", "last", "sun", 3600000*2, "oct", "last", "sun", 3600000*2, 3600000*1); # 380:: = ("asia/irkutsk") ; new time zone with daylight time

dateAddTimezone/2

description:
Defines the new time zone in the system with the specified shift from the UTC time. Time is in milliseconds.
format:
dateAddTimezone($zone-name string, $time-shift int) string
type:
Static
examples:
dateAddTimezone("europe/moscow", 3600000*3); # = ("europe/moscow") ; new time zone without daylight time

dateAfter/1

description:
Lets through context dates, which are chronologically after the date/time in the 1st argument.
format:
date dateAfter($d date) date
type:
Element-wise
examples:
("1980-01-01T00:20:34.567Z")/dateAfter("1970-01-01T00:20:34.567Z"); # = ("1980-01-01T00:20:34.567Z")

dateBefore/1

description:
Lets through context dates, which are chronologically before the date/time in the 1st argument.
format:
date dateBefore($d date) date
type:
Element-wise
examples:
("1970-10-10", "2003-10-12", "2002-10-12T10:15:00.000Z") / dateBefore("2002-10-12T11:00"); # = ("1970-10-10") ; the 3rd is after, if default time is less than UTC-1

dateConvert/2

description:
Converts the context date/time value from one time zone (1st argument) to the other (2nd argument)
format:
date dateConvert($tz1 string, $tz2 string)
type:
Element-wise
examples:
("2009-10-25T01:12:34.567") / dateConvert("asia/irkutsk", "default"); # = ("2009-10-24T17:12:34.567") from irkutsk to UTC, if it is default

dateDayMonth/0

description:
Returns the number of the day in the date's month.
format:
date dateDayMonth() integer
type:
Element-wise
examples:
("2009-10-25T01:12:34.567"/v:toDate()/v:dateDayMonth() # = 25

dateDayWeek/0

description:
Returns the number of the day in the current week in the context date.
format:
date dateDayWeek() int
type:
Element-wise
examples:
"2009-10-25T01:12:34.567"/v:toDate()/v:dateDayWeek(); # = 1 (Sun)

dateDayYear/0

description:
Gets the day number in the year of the context date value.
format:
date dateDayYear() int
type:
Element-wise
examples:
"2009-12-31T01:12:34.567"/v:toDate()/v:dateDayYear(); # = 365

dateDefinedTimezones/0

description:
Returns the names of time zones currently defined in the system. Time zones are defined by builtin functions fn:setTz/2 and fn:setTz/11. UTC is the only predefined zone.
format:
dateDefinedDimezones() string
type:
Element-wise
examples:
definedTimezones(); # = ("utc"); - if UTC is the defined time zone

dateFormat/1

description:
Sets output format for date/time presentation. 1st argument contains the format string. The context values are date values, which must be represented in the specified format.
format:
date dateFormat($format string)
type:
Element-wise
examples:
"2009-10-25T01:12:34.567"/v:toDate()/v:dateDormat("yy-mm-dd"); # = "09-12-25"

dateHours/0

description:
Returns the current hour of the context date.
format:
date dateHours() int
type:
Element-wise
examples:
"2009-10-25T01:12:34.567"/v:toDate()/v:dateHours(); # = 1

dateMinutes/0

description:
Get the minutes value of the context date.
format:
date dateMinutes() int
type:
Element-wise
examples:
"2009-10-25T01:12:34.567"/v:toDate()/v:dateMinutes(); # = 12

dateMonth/0

description:
Returns the month number in the current year in the context date.
format:
date dateMonth() int
type:
Element-wise
examples:
("1987-06-12")/dateMonth(); # = (5) ; starting with 0 (Jan)

dateSeconds/0

description:
Get seconds value of the context date/time.
format:
date dateSeconds() int
type:
Element-wise
examples:
("2009-09-15 03:21:34.567Z", "1970-10-10T03:02") / dateSeconds(); # = (34, 0)

dateSetDefaultTimezone/1

description:
Sets the default time zone.
format:
dateSetDefaultTimezone($default string) string
type:
Static
examples:
dateSetDefaultTimezone("africa/tunis"); # = ("africa/tunis") ; now we are in Tunis

dateTimezones/0

description:
gets the sequence of the available time zone names as strings.
format:
dateTimezones() string*
type:
Static
examples:
dateTimezones()<<.>>/fn:lowerCase(); # = ("act", "aet", "agt", "art", "ast", "africa/abidjan", "africa/accra", "africa/addis_ababa", "africa/algiers", "africa/asmara", "africa/asmera", "africa/bamako", "africa/bangui", "africa/banjul", "africa/bissau", "africa/blantyre", "africa/brazzaville", "africa/bujumbura", "africa/cairo", "africa/casablanca", "africa/ceuta", "africa/conakry", "africa/dakar", "africa/dar_es_salaam", "africa/djibouti", "africa/douala", "africa/el_aaiun", "africa/freetown", "africa/gaborone", "africa/harare", "africa/johannesburg", "africa/kampala", "africa/khartoum", "africa/kigali", "africa/kinshasa", "africa/lagos", "africa/libreville", "africa/lome", "africa/luanda", "africa/lubumbashi", "africa/lusaka", "africa/malabo", "africa/maputo", "africa/maseru", "africa/mbabane", "africa/mogadishu", "africa/monrovia", "africa/nairobi", "africa/ndjamena", "africa/niamey", "africa/nouakchott", "africa/ouagadougou", "africa/porto-novo", "africa/sao_tome", "africa/timbuktu", "africa/tripoli", "africa/tunis", "africa/windhoek", "america/adak", "america/anchorage", "america/anguilla", "america/antigua", "america/araguaina", "america/argentina/buenos_aires", "america/argentina/catamarca", "america/argentina/comodrivadavia", "america/argentina/cordoba", "america/argentina/jujuy", "america/argentina/la_rioja", "america/argentina/mendoza", "america/argentina/rio_gallegos", "america/argentina/salta", "america/argentina/san_juan", "america/argentina/san_luis", "america/argentina/tucuman", "america/argentina/ushuaia", "america/aruba", "america/asuncion", "america/atikokan", "america/atka", "america/bahia", "america/barbados", "america/belem", "america/belize", "america/blanc-sablon", "america/boa_vista", "america/bogota", "america/boise", "america/buenos_aires", "america/cambridge_bay", "america/campo_grande", "america/cancun", "america/caracas", "america/catamarca", "america/cayenne", "america/cayman", "america/chicago", "america/chihuahua", "america/coral_harbour", "america/cordoba", "america/costa_rica", "america/cuiaba", "america/curacao", "america/danmarkshavn", "america/dawson", "america/dawson_creek", "america/denver", "america/detroit", "america/dominica", "america/edmonton", "america/eirunepe", "america/el_salvador", "america/ensenada", "america/fort_wayne", "america/fortaleza", "america/glace_bay", "america/godthab", "america/goose_bay", "america/grand_turk", "america/grenada", "america/guadeloupe", "america/guatemala", "america/guayaquil", "america/guyana", "america/halifax", "america/havana", "america/hermosillo", "america/indiana/indianapolis", "america/indiana/knox", "america/indiana/marengo", "america/indiana/petersburg", "america/indiana/tell_city", "america/indiana/vevay", "america/indiana/vincennes", "america/indiana/winamac", "america/indianapolis", "america/inuvik", "america/iqaluit", "america/jamaica", "america/jujuy", "america/juneau", "america/kentucky/louisville", "america/kentucky/monticello", "america/knox_in", "america/la_paz", "america/lima", "america/los_angeles", "america/louisville", "america/maceio", "america/managua", "america/manaus", "america/marigot", "america/martinique", "america/mazatlan", "america/mendoza", "america/menominee", "america/merida", "america/mexico_city", "america/miquelon", "america/moncton", "america/monterrey", "america/montevideo", "america/montreal", "america/montserrat", "america/nassau", "america/new_york", "america/nipigon", "america/nome", "america/noronha", "america/north_dakota/center", "america/north_dakota/new_salem", "america/panama", "america/pangnirtung", "america/paramaribo", "america/phoenix", "america/port-au-prince", "america/port_of_spain", "america/porto_acre", "america/porto_velho", "america/puerto_rico", "america/rainy_river", "america/rankin_inlet", "america/recife", "america/regina", "america/resolute", "america/rio_branco", "america/rosario", "america/santarem", "america/santiago", "america/santo_domingo", "america/sao_paulo", "america/scoresbysund", "america/shiprock", "america/st_barthelemy", "america/st_johns", "america/st_kitts", "america/st_lucia", "america/st_thomas", "america/st_vincent", "america/swift_current", "america/tegucigalpa", "america/thule", "america/thunder_bay", "america/tijuana", "america/toronto", "america/tortola", "america/vancouver", "america/virgin", "america/whitehorse", "america/winnipeg", "america/yakutat", "america/yellowknife", "antarctica/casey", "antarctica/davis", "antarctica/dumontdurville", "antarctica/mawson", "antarctica/mcmurdo", "antarctica/palmer", "antarctica/rothera", "antarctica/south_pole", "antarctica/syowa", "antarctica/vostok", "arctic/longyearbyen", "asia/aden", "asia/almaty", "asia/amman", "asia/anadyr", "asia/aqtau", "asia/aqtobe", "asia/ashgabat", "asia/ashkhabad", "asia/baghdad", "asia/bahrain", "asia/baku", "asia/bangkok", "asia/beirut", "asia/bishkek", "asia/brunei", "asia/calcutta", "asia/choibalsan", "asia/chongqing", "asia/chungking", "asia/colombo", "asia/dacca", "asia/damascus", "asia/dhaka", "asia/dili", "asia/dubai", "asia/dushanbe", "asia/gaza", "asia/harbin", "asia/ho_chi_minh", "asia/hong_kong", "asia/hovd", "asia/irkutsk", "asia/istanbul", "asia/jakarta", "asia/jayapura", "asia/jerusalem", "asia/kabul", "asia/kamchatka", "asia/karachi", "asia/kashgar", "asia/kathmandu", "asia/katmandu", "asia/kolkata", "asia/krasnoyarsk", "asia/kuala_lumpur", "asia/kuching", "asia/kuwait", "asia/macao", "asia/macau", "asia/magadan", "asia/makassar", "asia/manila", "asia/muscat", "asia/nicosia", "asia/novosibirsk", "asia/omsk", "asia/oral", "asia/phnom_penh", "asia/pontianak", "asia/pyongyang", "asia/qatar", "asia/qyzylorda", "asia/rangoon", "asia/riyadh", "asia/riyadh87", "asia/riyadh88", "asia/riyadh89", "asia/saigon", "asia/sakhalin", "asia/samarkand", "asia/seoul", "asia/shanghai", "asia/singapore", "asia/taipei", "asia/tashkent", "asia/tbilisi", "asia/tehran", "asia/tel_aviv", "asia/thimbu", "asia/thimphu", "asia/tokyo", "asia/ujung_pandang", "asia/ulaanbaatar", "asia/ulan_bator", "asia/urumqi", "asia/vientiane", "asia/vladivostok", "asia/yakutsk", "asia/yekaterinburg", "asia/yerevan", "atlantic/azores", "atlantic/bermuda", "atlantic/canary", "atlantic/cape_verde", "atlantic/faeroe", "atlantic/faroe", "atlantic/jan_mayen", "atlantic/madeira", "atlantic/reykjavik", "atlantic/south_georgia", "atlantic/st_helena", "atlantic/stanley", "australia/act", "australia/adelaide", "australia/brisbane", "australia/broken_hill", "australia/canberra", "australia/currie", "australia/darwin", "australia/eucla", "australia/hobart", "australia/lhi", "australia/lindeman", "australia/lord_howe", "australia/melbourne", "australia/nsw", "australia/north", "australia/perth", "australia/queensland", "australia/south", "australia/sydney", "australia/tasmania", "australia/victoria", "australia/west", "australia/yancowinna", "bet", "bst", "brazil/acre", "brazil/denoronha", "brazil/east", "brazil/west", "cat", "cet", "cnt", "cst", "cst6cdt", "ctt", "canada/atlantic", "canada/central", "canada/east-saskatchewan", "canada/eastern", "canada/mountain", "canada/newfoundland", "canada/pacific", "canada/saskatchewan", "canada/yukon", "chile/continental", "chile/easterisland", "cuba", "eat", "ect", "eet", "est", "est5edt", "egypt", "eire", "etc/gmt", "etc/gmt+0", "etc/gmt+1", "etc/gmt+10", "etc/gmt+11", "etc/gmt+12", "etc/gmt+2", "etc/gmt+3", "etc/gmt+4", "etc/gmt+5", "etc/gmt+6", "etc/gmt+7", "etc/gmt+8", "etc/gmt+9", "etc/gmt-0", "etc/gmt-1", "etc/gmt-10", "etc/gmt-11", "etc/gmt-12", "etc/gmt-13", "etc/gmt-14", "etc/gmt-2", "etc/gmt-3", "etc/gmt-4", "etc/gmt-5", "etc/gmt-6", "etc/gmt-7", "etc/gmt-8", "etc/gmt-9", "etc/gmt0", "etc/greenwich", "etc/uct", "etc/utc", "etc/universal", "etc/zulu", "europe/amsterdam", "europe/andorra", "europe/athens", "europe/belfast", "europe/belgrade", "europe/berlin", "europe/bratislava", "europe/brussels", "europe/bucharest", "europe/budapest", "europe/chisinau", "europe/copenhagen", "europe/dublin", "europe/gibraltar", "europe/guernsey", "europe/helsinki", "europe/isle_of_man", "europe/istanbul", "europe/jersey", "europe/kaliningrad", "europe/kiev", "europe/lisbon", "europe/ljubljana", "europe/london", "europe/luxembourg", "europe/madrid", "europe/malta", "europe/mariehamn", "europe/minsk", "europe/monaco", "europe/moscow", "europe/nicosia", "europe/oslo", "europe/paris", "europe/podgorica", "europe/prague", "europe/riga", "europe/rome", "europe/samara", "europe/san_marino", "europe/sarajevo", "europe/simferopol", "europe/skopje", "europe/sofia", "europe/stockholm", "europe/tallinn", "europe/tirane", "europe/tiraspol", "europe/uzhgorod", "europe/vaduz", "europe/vatican", "europe/vienna", "europe/vilnius", "europe/volgograd", "europe/warsaw", "europe/zagreb", "europe/zaporozhye", "europe/zurich", "gb", "gb-eire", "gmt", "gmt0", "greenwich", "hst", "hongkong", "iet", "ist", "iceland", "indian/antananarivo", "indian/chagos", "indian/christmas", "indian/cocos", "indian/comoro", "indian/kerguelen", "indian/mahe", "indian/maldives", "indian/mauritius", "indian/mayotte", "indian/reunion", "iran", "israel", "jst", "jamaica", "japan", "kwajalein", "libya", "met", "mit", "mst", "mst7mdt", "mexico/bajanorte", "mexico/bajasur", "mexico/general", "mideast/riyadh87", "mideast/riyadh88", "mideast/riyadh89", "net", "nst", "nz", "nz-chat", "navajo", "plt", "pnt", "prc", "prt", "pst", "pst8pdt", "pacific/apia", "pacific/auckland", "pacific/chatham", "pacific/easter", "pacific/efate", "pacific/enderbury", "pacific/fakaofo", "pacific/fiji", "pacific/funafuti", "pacific/galapagos", "pacific/gambier", "pacific/guadalcanal", "pacific/guam", "pacific/honolulu", "pacific/johnston", "pacific/kiritimati", "pacific/kosrae", "pacific/kwajalein", "pacific/majuro", "pacific/marquesas", "pacific/midway", "pacific/nauru", "pacific/niue", "pacific/norfolk", "pacific/noumea", "pacific/pago_pago", "pacific/palau", "pacific/pitcairn", "pacific/ponape", "pacific/port_moresby", "pacific/rarotonga", "pacific/saipan", "pacific/samoa", "pacific/tahiti", "pacific/tarawa", "pacific/tongatapu", "pacific/truk", "pacific/wake", "pacific/wallis", "pacific/yap", "poland", "portugal", "rok", "sst", "singapore", "systemv/ast4", "systemv/ast4adt", "systemv/cst6", "systemv/cst6cdt", "systemv/est5", "systemv/est5edt", "systemv/hst10", "systemv/mst7", "systemv/mst7mdt", "systemv/pst8", "systemv/pst8pdt", "systemv/yst9", "systemv/yst9ydt", "turkey", "uct", "us/alaska", "us/aleutian", "us/arizona", "us/central", "us/east-indiana", "us/eastern", "us/hawaii", "us/indiana-starke", "us/michigan", "us/mountain", "us/pacific", "us/pacific-new", "us/samoa", "utc", "universal", "vst", "w-su", "wet", "zulu")

dateYear/0

description:
Returns the number of the year in the context date/time.
format:
date dateYear() int
type:
Element-wise
examples:
("2009-09-15T03:21:34.567Z", "1970-10-10T03:02", "70-10-01")/dateYear(); # = (2009, 1970, 70)

date/0

description:
Generates the current date,
format:
date() date
type:
Static


4 Input/output function

binAdd/3

description:
Insterts the binary contents of the source indicated by url (URL or a file name) represented in the Base64 format as the idx-th value of object's dmap/string property prop,
format:
object binAdd($prop tproperty(dmap), $idx int, $url string)
type:
Element-wise
examples:
&libretto / fn:binAdd(`image, 0, "http://ontobox.org/images/libretto.gif")

binExport/1

description:
Exports the context string interpreted as a base64 to the binary file.
format:
string(base64) binExport($filename string) string(base64)
type:
Element-wise

binExport/3

description:
Efficiently (without memory usage) exports the base64binary string from idx-th element of dmap/string t-property of object to new binary file with name $filename
format:
object binExport($prop property(dmap), $idx int, $filename string) string(base64)
type:
Element-wise
examples:
&picture / binExport(`image, 0, "pic.gif")

binSet/3

description:
Efficiently replaces (without memory usage) in the object the idx-th value of dmap/string property by the binary contents of the source $url (URL or a file name) in the Base64 format,
format:
object binSet($prop tproperty(dmap), $idx int, $url string) object
type:
Element-wise
examples:
&libretto / fn:binSet(`image, 0, "http://ontobox.org/images/libretto.gif")

box2libretto/0

description:
Translates the contents of the ontobase to a code in Libretto. Returns the result as a string.
format:
box2libretto() string(libretto code)
type:
Static

box2mvx/1

description:
Saves the current state of the ontobase in the binary (zipped XML) MVX format in the file $filename.
format:
box2mvx($filename string)
type:
Static

box2repo/1

description:
Generates a single-ontology mvx file for publishing in an OntoBox repository. The exported ontology is indicated in the 1st argument of box2repo/1.
format:
void box2repo($onto string|entity) entity
type:
Static

mvx2box/1

description:
Loads the contents of the MVX archive (the box dump) in the box.
format:
void mvx2box($mvx-file string) void
type:
Static

print/0

description:
Prints the context value in stdout stream. Returns the input value.
format:
any print() any
type:
Element-wise

println/0

description:
Prints the context value in stdout stream with finishing new line. Returns the input value.
format:
any println() any
type:
Element-wise

readLines/1

description:
The iterator lazily generating the sequence of strings from a textual source indicated by its URL or filename (parameter url) with encoding utf-8.
format:
readLines($url string(filename/URL) string*
type:
Static
examples:
readLines("http://www.cnn.com") / count(); # = (1320) counts the number of lines in cnn.com

readLines/2

description:
The same as readLine/1 but with explicit encoding parameter $encd. Its possible values are "utf-8", "windows-1251" etc.
format:
readLines($url string(filename/URL), $encd string) string*
type:
Static
examples:
readLines("http://rbc.ru", "windows-1251")

read/1

description:
Reads a string from the file or URL in UTF-8 encoding,
format:
read($source {string(filename/url)}) string
type:
Static

read/2

description:
Reads the file $source with encoding $enc.
format:
read($source string(filename/url), $enc string) string
type:
Static

txtAdd/3

description:
Adds a new value to the dmap/string property $prop at position $idx. The value is the content of source $url read in the default encoding UTF-8.
format:
object txtAdd($prop tproperty(dmap), $idx int, $url string)
type:
Element-wise
examples:
&a / txtAdd(`text, -2, "uj.txt")

txtAdd/4

description:
Adds a new value of the dmap/string property $prop at position $idx. The value is the content of source $url read in encoding $encd.
format:
object txtAdd($prop tproprety(dmap), $idx int, $url string, $encd string) void
type:
Element-wise
examples:
&a / fn:textAdd(`text, -2, "wi.txt", "windows-1251");

txtExport/3

description:
Exports the $idx-th value of the property $prop to the file $url in the default text encoding format UTF-8.
format:
object txtExport($prop tproperty(dmap), $idx int, $url string)
type:
Element-wise
examples:
&a / fn:txtExport(`text, 0, "tmp.txt");

txtExport/4

description:
Exports the $idx-th value of the property $prop to the file url in the text encoding format $encd.
format:
object txtExport($prop tproperty(dmap), $idx int, $url string, $encd string)
type:
Element-wise
examples:
&a / fn:txtExport(`text, 0, "tmp.txt", "windows-1251");

txtSet/3

description:
Replaces the $idx-th value of the dmap/string property $prop by the content of source $url read in the default encoding.
format:
object txtSet($prop tproperty(dmap), $idx int, $url string)
type:
Element-wise
examples:
&a / fn:txtSet(`text, 0, "ui.txt");

txtSet/4

description:
Replaces the $idx-th value of the dmap/string property prop by the content of source $url read in the encoding $encd.
format:
object txtSet($prop tproprety(dmap), $idx int, $url string, $encd string) void
type:
Element-wise
examples:
&a / fn:txtSet(`text, 0, "ui.txt", "windows-1251");

write/2

description:
Writes $output to the new file with encoding utf-8.
format:
void write($filename string, $output any)
type:
Static

write/3

description:
Writes $output to the new file with encoding $enc,
format:
void write($filename string, $output any, $enc string)
type:
Static

x:readHtml/1

description:
Converts an html document from the context string to a set of XML entity objects stored in the XML heap ontology.
format:
string readHtml() xml:Root
type:
Element-wise

x:readHtml/2

description:
Reads an html document from the file or URL filename with the specified character encoding into the XML heap ontology.
format:
readHtml($source {string(filename), string(url)}, $charset string) x:Document
type:
Static
examples:
readHtml("http://ontobox.org", "w", "utf-8")

x:readXml/0

description:
Imports the XML document from the context string to the set of xml-objects stored in the XML heap ontology,
format:
string readXml() xml:Root
type:
Element-wise

x:readXml/1

description:
Reads an XML document from a file/URL. $xmlfilename is the name of the loaded file or URL. The document is saved in the XML heap ontology,
format:
readXml($source {string(filename), string(url)})
type:
Static

x:writeXml/0

description:
Converts the XML document with the root in the context into a string.
format:
x:Element/x:Document (root) writeXml() string
type:
Element-wise

x:writeXml/2

description:
Saves the XML document stored in the ontobase with the root $root-object to the file named xmlfilename
format:
writeXml($xmlfile string, $root-object {xml:Root, xml:Element}) string
type:
Static


5 Ontobox model function

addFunction/1

description:
Adds a new user-defined function. For instance,
addFunction("def add1() {. + 1}");
introduces function add1/0. Returns the internal function number.
format:
void addFunction($funcode string) int (internal function number)
type:
Static

addObjectClass/1

description:
Adds the context object to the class (1st argument).
format:
object addObjectClass($cls class) object
type:
Element-wise

addSubclass/1

description:
Declares the class (1st argument) as the subclass of the context class.
format:
class(sup) addSubclass($sub class)
type:
Element-wise

addValues/2

description:
Adds values to the property $prop of the context object. This function behaves like +=.
format:
object addValues($prop entity (property), $values object+) object
type:
Element-wise

addValues/3

description:
Inserts new values to the values of the property $prop at position $index of the context object.
format:
object addValues($prop entity (property), $values object+, $index int) object
type:
Element-wise

annames/0

description:
Returns all annotation keys linked to the context value as an annotated entity,
format:
{entity, string} annames() string
type:
Element-wise

anno/1

description:
Returns the value of the annotation $key assigned to the context object.
format:
{string, entity} anno($key string) string
type:
Element-wise

annotate/2

description:
Sets annotation named $key and valued $value to the current context object. If $key and $value are collections, then it sets as annotations the pairs $key[i]/$value[i]. Returns the annotated entity itself.
format:
{entity, string} annotate($key string*, $value string*) {entity, string}
type:
Element-wise

classesDirect/0

description:
Returns direct superclasses of the class (i.e. those from which the current class directly inherits), direct classes of objects, or 'senior' classes of the ontologies.
format:
{ontology, class, object} classesDirect() class
type:
Element-wise

classes/0

description:
Gets all classes for the entity (ontology, class or object).
format:
{ontology, class, object} classes() class
type:
Element-wise

clone/1

description:
Copies the context object into the other ontology $onto (creates a new anonymous element with the same parameters). The links to the input object are not moved.
format:
object clone($onto ontology) object(new)
type:
Element-wise

deleteForced/0

description:
Deletes the context object with removing all property links to the deleted object.
format:
object deleteForced()
type:
Element-wise

delete/0

description:
Removes the context entity from the box. This operation succeeds only if no other entity from the box depends on the deleted entity.
format:
entity delete()
type:
Element-wise

domain/0

description:
Gets the domain class of the property.
format:
{tproperty, oproperty} domain() class
type:
Element-wise

entity/0

description:
Returns the entity in the box corresponding to the full name (URI) from the context. Returns nothing if such entity does not exist.
format:
string entity() entity
type:
Element-wise

entity/1

description:
Returns the entity with the local name in the context belonging to the ontology $ont. Returns nothing otherwise.
format:
string entity($ont ontology) entity

generatePrefixes/0

description:
Automatically assigns prefixes to unprefixed ontologies in the box. Returns the list of prefixes as strings.
format:
void generatePrefixes() string*
type:
Static

get/1

description:
Returns the value of the key (annotation) $keyname of the context object (entity).
format:
object|entity get($keyname string) string +
type:
Element-wise

instanceof/1

description:
Lets the object through if it is the instance of the class in the function argument.
format:
object instanceof($cls class) object
type:
Element-wise

keys/0

description:
Returns the names of object's keys, if the context value is an object; returns the names of entities, if the context value is an entity.
format:
object|entity keys() string +
type:
Element-wise

local/0

description:
Returns the local name of the context entity in the ontology. The entity can be represented by its URI or as an entity value.
format:
entity local() string
type:
Element-wise
examples:
`a:A / local(); # = (A)

maxCard/0

description:
Gets max cardinality of the property - the maximum allowed number of values (default value: infinity denoted by -1).
format:
property maxCard() int
type:
Element-wise

minCard/0

description:
Gets min cardinality of the property - the minimum allowed number of values (default value: 0).
format:
property minCard() int
type:
Element-wise

move/1

description:
Moves the context object into the other ontology $onto (creates a new anonymous element with the same parameters). All links to the old object from other objects through o-properties are also moved.
format:
object move($onto ontology) object(new)
type:
Element-wise

name/0

description:
Gets the full name (URI) of the entity represented by the context value.
format:
entity name() string
type:
Element-wise

newClass/1

description:
Creates a new class in the ontology represented by the context value. The argument name is the short name of the new class within the ontology.
format:
ontology newClass($name string) class
type:
Element-wise

newDate/0

description:
Creates a new date value with the current date and time.
format:
v:newDate() v:date
type:
Static

newName/0

description:
Generate a new (unused in the ontology) surrogate full name. This name does not correspond to any ontology's entity.
format:
ontology newName() string
type:
Element-wise

newName/1

description:
Generates a new URI string made of the context ontology's URI and local name in the argument. The state of the name is not checked.
format:
ontology newName($local string) string
type:
Element-wise

newObject/1

description:
Creates an anomymous object in the ontology indicated in the 1st argument. To give the object a name, use rename/1.
format:
ontology newObject() object
type:
Static

newOntology/1

description:
Creates a new ontology and assigns the prefix to it. If an ontology with the name exists, the function only assigns the prefix.
format:
string newOntology($prefix string) ontology
type:
Static
examples:
"http://hehe" / newOntology("he"); # = (`he:*)

newOprop/1

description:
Creates in the context ontology a new o-property named $oprop-name. Returns the new o-proprety.
format:
ontology newOprop($oprop-name sting) oproperty
type:
Element-wise

newTprop/1

description:
Creates a new t-property named $tprop-name in the context ontology. Returns the new o-proprety.
format:
ontology newTprop($tprop-name sting) tproperty
type:
Element-wise

newType/1

description:
Creates a new data type in the context ontology.
format:
ontology newType($type-local string) type
type:
Element-wise

objectsDirect/0

description:
Gets all direct objects of the quoted class in the context (i.e. those explicitly defined in the class).
format:
class objectsDirect() object*
type:
Element-wise

objects/0

description:
For objects: collects the values of all o-properties of the current context object; for ontology: collects all objects of the ontology; for oproperty: collects all existing values of the oproperty.
format:
{ontology, oproperty, object} objects() object*
type:
Element-wise

ontologies/0

description:
returns the sequence of the ontologies stored in the box.
format:
ontologies() ontology*
type:
Static
examples:
ontologies(); # = (`x:*, `xml:*, `map:*)

ontology/0

description:
Gets the ontology, in which the context entity is defined. Also gets the ontology by its prefix / uri.
format:
{entity, string(prefix), string(uri)} ontology() ontology
type:
Element-wise

opropsDirect/0

description:
Gets direct o-properties of the class (i.e. for which the class is declared as their domain).
format:
{ontology, class, object} opropsDirect() oproperty*
type:
Element-wise

oprops/0

description:
Gets all o-properties of the ontology, class or object from the context.
format:
{ontology, class, object} oprops() oproperty*
type:
Element-wise

ownersProps/0

description:
Returns objects containing triples owner-oproperty-index
&_ {@o := [owner]; @p := [oproperty]; @i := [index] }
listing the objects @o, for which the context object or value is a value of the oproperty @p at position @i.
format:
any ownersProps() object*
type:
Element-wise

owners/0

description:
Returns objects having the context element (either object or data value) as their property value.
format:
any owners() object*
type:
Element-wise

owners/1

description:
Finds all owners of the context object (through o-properties) or data value (through t-properties). Equivalent to taking inverse property value: ~prop.
format:
{object, value} owners($prop entity (oproperty, tproperty)) object*
type:
Element-wise

prefix/0

description:
Returns the prefix of the ontology (the context value). The ontology can be represented as an entity (quoted expression) or by the URI. If the prefix does not exist nothing is returned.
format:
{ontology, string(uri)} / prefix() string
type:
Element-wise
examples:
"http://ontobox.org/" / prefix(); # = ("v")

prefix/1

description:
Assigns the prefix to the existing ontology.
format:
{string(prefix), string(uri), ontology} prefix($new-prefix string) ontology
type:
Static
examples:
"http://hehe" / prefix("he"); # = (`he:*)

prefixes/0

description:
Returns the mapping from ontology prefixes to ontology URIs as a sequence of map-objects with keys "prefix" and "name", e.g.
&_{@prefix := "map", @name := "http://ontobox.org/map"}
format:
void prefixes() map:Map
type:
Static
examples:
prefixes()/'"{@prefix}" -> {@name}'!; # = ("v" -> http://ontobox.org/ "p" -> http://a "map" -> http://ontobox.org/map, "x" -> http://xml.ontobox.org/)

props/0

description:
Returns all properties relevant to the context entity or ontology
format:
{ontology, class, object} props() property*
type:
Element-wise

put/2

description:
Sets new values to the key of the context object, removing previous values (if there any).
format:
object put($key string, $value any) string
type:
Element-wise
examples:
$object := &_ / v:put("num", 1);

$object / @num; # = (1)

range/0

description:
Returns the range of the property (a class in case of o-properties and datatype in case of t-properties).
format:
{oproperty, tproperty} range() {class, type}
type:
Element-wise

removeKey/1

description:
Removes the key with its values from the context map element
format:
map:Map removeKey($key string) map:Map
type:
Element-wise

removeObjectClass/1

description:
Removes the context object from the class.
format:
object removeObjectClass($cls class) object
type:
Element-wise

removeSubclass/1

description:
Removes subclass (1st argument) from the superclass from the context (change class hierarchy). Returns the context superclass.
format:
class(sup) removeSubclass($subclass class) class(sup)
type:
Element-wise

removeValue/2

description:
Removes value with specified index.
format:
object removeValue($prop property, $idx int) object
type:
Element-wise

removeValues/0

description:
Removes in object all values of all properties.
format:
object removeValues() object
type:
Element-wise

removeValues/1

description:
Removes all values of the property.
format:
object removeValues($prop property) object
type:
Element-wise

remove-values/2

description:
Removes those values of the property $prop of the context object, for which the condition ./$cond! is true (not empty).
format:
object removeValues($prop property, $cond expr) object
type:
Element-wise
examples:
class C(v C);
C &c, &c1, &c2, &c3, &c4;
&c {v := (&c1, &c2, &c3, &c4)};
&c / v:removeValues(%v, _{. = &c3 or . = &c1});

&c / v;     # = (&c2, &c4)

rename/1

description:
Sets the new local name of the context entity, including ontologies.
format:
entity rename($local string) entity
type:
Element-wise

replaceValues/3

description:
Substitutes in the context object the values of property $prop by the values obtained by ./$newval!. This expression is evaluated with the replaced value as the context element.
format:
object replaceValues($prop property, $cond expr, $newval expr) object
type:
Element-wise
examples:
class C(n v:int);
C &c {n := (1,2,3,4,5)};

&c / v:replaceValues(%n, _{. mod 2 = 0}, _{(., . * .)});

&c / n;                    # = (1, 2, 4, 3, 4, 16, 5)

setDomain/1

format:
{tproperty, oproperty} setDomain($cls class) {tproperty, oproperty}
type:
Element-wise

setRange/1

description:
Determines the range of the property.
format:
{oproperty, tproperty} setRange($cls {class, type}) {oproperty, tproperty}
type:
Element-wise

setValues/2

description:
Sets new values to the property $prop of the context object. The old values are removed.
format:
object setValues($prop entity (property), $values any+) object
type:
Element-wise

short/0

description:
returns a short name (prefix + ':' + local) of the context entity.
format:
entity short() string
type:
Element-wise

string/0

description:
Returns the string representation of the entity or data
format:
any string() string
type:
Element-wise
examples:
(1, "1", 1.2)[string()/contains(".")]; # = (1.2)

subclassesDirect/0

description:
Returns the direct superclasses of the class from the context (i.e. those for which the current class is explicitly declared as their superclass).
format:
class subclassesDirect() class*
type:
Element-wise

subclasses/0

description:
Get all subclasses (direct and indirect) of the class from the context.
format:
class subclasses() class*
type:
Element-wise

subclassof/1

description:
Lets the context class through if it is a subclass of the function argument.
format:
class subclassof($sup class) int
type:
Element-wise

tbox2libretto/0

description:
Translates the terminological data of the ontobase (without objects) into a Libretto program. Returns a string with the Libretto code.
format:
void tbox2libretto() void
type:
Static

toBoolean/1

description:
Creates a new boolean constant represented by the input string.
format:
void toBoolean($bool-string string) boolean
type:
Static

toClass/0

description:
Creates a new class entity for the existing class by the full name in the context string.
format:
string (classname) toClass() class
type:
Element-wise

toClass/1

description:
Creates a new class constant for the existing class represented in the input string.
format:
void toClass($class-string string) class
type:
Static

toDate/0

description:
Creates a new date entity represented by the context string.
format:
string (date) toDate() date
type:
Element-wise

toDate/1

description:
Creates a new date entity represented by the string in the 1st argument.
format:
void toDate($date-string string) date
type:
Static

toExpr/0

description:
Creates a new Libretto expression entity represented by the context string.
format:
string (expr) toExpr() expr
type:
Element-wise

toExpr/1

description:
Creates a new Libretto expression entity represented by the string in the 1st argument.
format:
void toExpr($expr-string string) expr
type:
Static

toFloat/0

description:
Creates a new float constant by the context string.
format:
string (float) toFloat() expr
type:
Element-wise

toFloat/1

description:
Creates a new float constant by the string in the 1st argument.
format:
void toFloat($float-string string) expr
type:
Static

toFunction/0

description:
The same as function/1 but with the input from the context.
format:
string (function decl) toFunction() function
type:
Element-wise

toFunction/1

description:
Creates a new function constant from the input string representation, The string in $func-string must be a Libretto function definition, like
"function f($x) { $x + 1 }"
newFunction/1 translates this string in the current context of the box (with existing ontologies, class definitions, etc.) The result of this translation is the value of the datatype function. This value can be handled as values of other types, e.g. assigned to a tproperty. To male such an object a working function, the built-in eval/1 can be used, for instance:
class Libfunc {
    fun function
};
Libfunc &myfunc {
    fun := toFunction("function add1($x) { $x + 1 }")
};
# now load this function in the box:
eval(&myfunc/fun);

The functions declared in the box also can be used as function data values, For this, use the quote symbol "`":
function add1($x) { $x + 1 };

&myfunc {fun:= `add1};

format:
void toFunction($func-string string) function
type:
Static

toInt/0

description:
Creates a new integer constant by the context string.
format:
string (int) toInt() int
type:
Element-wise

toInt/1

description:
Creates a new integer constant by the string in the 1st argument.
format:
void toInt($int-string string) int
type:
Static

toLong/0

description:
Creates a new long integer constant by the context string.
format:
string (long) toLong() long
type:
Element-wise

toLong/1

description:
Creates a new long integer constant by the string in the 1st argument.
format:
void toLong($long-string string) long
type:
Static

toOntology/0

description:
Creates a new ontology constant for the existing ontology by the context string.
format:
string (ontology name) toOntology() ontology
type:
Element-wise

toOntology/1

description:
Creates a new ontology constant for the existing ontology by the string in the 1st argument.
format:
void toOntology($onto-string string) ontology
type:
Static

toOproperty/0

description:
Creates a new oproperty entitiy for the existing oproperty by the context string.
format:
string (oprop name) toOproperty() oproperty
type:
Element-wise

toOproperty/1

description:
Creates a new oproperty entitiy for the existing oproperty by the string in the 1st argument.
format:
void toOproperty($oprop-string string) oproperty
type:
Static

toString/0

description:
Converts the context string into a string.
format:
any toString() string
type:
Element-wise

toString/1

description:
Converts its argument into a string.
format:
void toString($entity any) string
type:
Static

toTproperty/0

description:
Creates a new tproperty entity for the existing tproperty named by the context string.
format:
string (tprop name) toTproperty() tproperty
type:
Element-wise

toTproperty/1

description:
Creates a new tproperty entity for the existing tproperty by the string in the 1st argument.
format:
void toTproperty($tprop-string string) tproperty
type:
Static

toType/0

description:
Creates a new type entity for an existing data type named by the context string.
format:
string (type name) toType() type
type:
Element-wise

toType/1

description:
Creates a new type entity for an existing data type named by the string in the 1st argument.
format:
void toType($type-string string) type
type:
Static

tpropsDirect/0

description:
Get direct t-properties of the class (i.e. for which the class is declared as their domain).
format:
class tpropsDirect() tproperty*
type:
Element-wise

tprops/0

description:
Gets all t-properties of the ontology, class or object from the context.
format:
{ontology, class, object} tprops() tproperty*
type:
Element-wise

type/0

description:
This function returns the type of the context value. If the context value is an object, the function returns the direct classes it belongs to.
format:
any type() entity
type:
Element-wise

types/0

description:
Returns all data types of the ontology.
format:
ontology types() type*
type:
Element-wise

values/0

description:
Collects all data values of the context tproperty or object.
format:
{tproperty, object} values() datavalue
type:
Element-wise

values/1

description:
Gets the property/key value of the object/map.
format:
object values($propkey {property, string(mapkey)}) any*
type:
Element-wise


6 Map Function


7 Meta function

collect/1

description:
Collects the whole context collection and assigns it to the variable in the 1st argument.
format:
any + collect($var exp) any*
type:
Collection-wise
examples:
(1,2,3)/v:collect(_{$x}) / {. + $x/v:last()};  # = (4,5,6)

error/1

description:
Interrupts the query/program evaluation and throws an exception (the Java's RuntimeException). $message contains the message/diognostics.
format:
void error($message string) void
type:
Static

eval/0

description:
Evaluates an (absolute) quoted expression from the context.
format:
token eval() any*
type:
Element-wise
examples:
(``1+2) / eval(); # = (3)

eval/1

description:

In Libretto it is possible to forbid the evaluation of a block {...} by putting underscore "_" before it: _{...}. Such a suspended expression becomes an ordinary data value. For evaluation of the suspended expression, the function eval/1 is used. To evaluate exp in the context of Ctx, we write Ctx / eval(exp).

eval/1 is also used for evaluation parametrized strings: it evaluates values in curly brackets while leaving other parts of the parametrized string untouched:

(1,2,3)/v:eval("1 + {.} = {1 + .}")      # = ("1 + 1 = 2", "1 + 2 = 3", "1 + 3 = 4")

'!' is used as a syntactic sugar for v:eval/1:

_{1+2}!     # = 3
(1,2,3)/"1 + {.} = {1 + .}"!     # = ("1 + 1 = 2", "1 + 2 = 3", "1 + 3 = 4")
format:
any eval($tok {token, string}) any*
type:
Element-wise
examples:
$term := ``. + 1; (1, 2)/eval($term); # = (2, 3)
eval("1+2"); #2 = (3)

eval/2

description:

eval/2 does the same job as eval/1, but it can evaluate anonymuous functions with arguments and provides the application of escapers in case of parametrized strings. For instance, if we assign $f a anonymuous function with one argument:

$f := _($x) {. * $x};

then we can apply this function using eval/2:

(1,2,3) / v:eval($f, (5));              # = (5, 10, 15)

The second argument of eval/2 contains the sequence of actual parameters of the anonymuous functions ((5) in our case).

'!' can be used as a syntactic sugar here:

(1,2,3) / $f!(5);        # = (5, 10, 15)

If eval/2 evaluates parametrized strings, then the 2nd argument contains an escaper for transforming the values of the expressions in curly brackets:

«<a>{«<b/>»}</a>»!;           # = "<a><b/></a>"
«<a>{«<b/>»}</a>»!x:esc;       # = "«<a><b/></a>»"

Here the inner string «<b/>» is modified by the function x:esc/1. Note that using « and » allows us to introduce nested strings. «a{«b»}a» without ! is an ordinary string, but with the indication of whether a quote is opening or closing (like with parentheses). The ascii equivalents of « and » are ^" and "^ respectively.

Any function with one argument can serve as the escaper:

def double($x) {$x + $x};
«A{«b»}a»!double;         # = "Abba"
«a{1+2}a»!double;          # = "a6a"
format:
any eval($tok expr|string, $parm expr|string) any*
type:
Element-wise

execute/0

description:
Executes the libretto program from the context, and produces a temporary map with two keys - 'query' for quoted expression for the query and 'answer' for the result of this query.
&_ {@query := ``1+2;   @answer := 3}
The maps in the output sequence are ordered as queries in the input program.
format:
{token, string} execute() map:Map
type:
Element-wise
examples:
"def f($x) {$x + 1}; f(5)+6;" / v:execute() / "query = {@query} answer = {@answer}"!;  #2 = (query = ``function  f($x)  $x + 1; answer = "", query = ``f(5) + 6; answer = 12)

exit/1

description:
Halts the computation and quits the interpreter with code $code. Note that exit/1 halts the whole JVM, so it must be used with care.
format:
void exit($code int)
type:
Static

indexDelete/1

description:
removes the index determined by the argument from the table of indexes.
format:
indexDelete($indexname string)
type:
Static

indexKeys/1

description:
returns the keys of the index named index-id and generated by set-index/2.
format:
indexKeys($indexname string) *
type:
Static
examples:
fn:getIndexKeys("lines") / fn:Count(); # = (37)

indexRemoveKey/1

description:
removes the key from the index $indexname.
format:
string(key) indexRemoveKey($indexname string)
type:
Element-wise
examples:
("make", "better") / indexRemoveKey("line-index");

indexValues/1

description:
Gets a value of the key in the 'reverse' mapping. E.g. if we want to have fast access from people to their grandparent, we can create the hash table:
index("gps", Person, ``.,  ``child/child);
then to get John's grandparent we write
&John / indexValues("gps");
That is, this function creates reverse mapping from the result values of some query to the values of its initial context sequence. "gps" is the identifier of this index.
format:
any(key)indexValues($index-name string) any(value)+
type:
Element-wise

index/1

description:
Creates a new index with name $index-name.
format:
index($index-name string)
type:
Static

index/3

description:
Adds a new key/value pair to the index. If $keys and/or $values contain more than one value, then each key is linked to each value.
format:
index($index-name string, $keys any, $values any)
type:
Static

index/4

description:
Creates an index (vocabulary) index-name aimed at fast access to a value by its key. E.g. if we want to have fast access from people to their grandparent, we can create the index:
index("gps", Person, _{child/child}, _{.});
Now to get John's grandparent we write
&John / index-values("gps");
The arguments:
  • 1st is the name of the index
  • 2nd is the basic set for indexing
  • 3rd (key) is indexing value corresponding to the basic element
  • 4th (value) is indexed value corresponding to the basic element
In the example above each person &p is indexed by the grandchild
&p/(child/child)
format:
set-index($index-name string, $domain any*, $key any, $value any)
type:
Static

label/3

description:
label/3 sets the return point for deep return. Works together with rollback/1. label/3 is element-wise and tries each element of the context sequence. First, it tries to evaluate $maincode with the current context value, If the calculation is succesfully finished, then the value of label/3 is its result. If rollback/1 with the argument $pointname is envoked during this evaluation, the system returns to the nearest label point with the same point name and evaluates its $returncode,
format:
void label($pointname string, $maincode exp, $returncode exp) any
type:
Element-wise
examples:
def f() {if (. = "a") v:rollback("aaa") else .}; ("a", 1)/v:label("aaa", `{f()}, "aaaaa");   # = (1, "aaaaa")

load/1

description:
Loads (evaluates) a Libretto script from the file or URL $libretto-filename.
format:
load( $librettofilename string)
type:
Static

objects/1

description:
Applies the o-property $prop to the context object.
format:
object objects($prop oproperty) object*
type:
Element-wise

rollback/1

description:
Performs the deep return to the nearest point set by function label/3 with the same $pointname.
format:
void rollback($pointname string) void
type:
Static

sleep/1

description:
Causes the current computation to sleep for the specified number of milliseconds $millis. Returns the current context value.
format:
any sleep($millis long) any
type:
Element-wise

stop/0

description:
Stops in a normal way the execution of a Libretto script.
format:
void stop() void
type:
Static

void/1

description:
Returns its argument.
format:
void void($val any) any
type:
Static


8 XML Function

x:a/0

description:
Returns the sequence of the attributes of the context element.
format:
x:Element x:a() x:Attribute*
type:
Element-wise

x:a/1

description:
Returns the value of the attribute $key of the context element.
format:
x:Element x:a($key string) string
type:
Element-wise

x:add/1

description:
Adds an entity (element, attribute, text) to the context XML node (a node of either x:Element or x:Document). If the argument is not an XML node, it is converted to a string, escaped, and then added as a text node. If the argument is a sequence of elements, then each element is converted to a string, and then these strings are concatenated.
format:
x:Element|x:Document x:add($entity {x:Element, x:Text, x:Attribute}) x:Element
type:
Static

x:attr/2

description:
Creates a new xml attribute object in the XML heap ontology.
format:
void x:attr($name string, $value string, $ontology-id {string(prefix), string(uri), ontology}) x:Attribute
type:
Static

x:doc/0

description:
Creates a new XML document node in the XML heap ontology,
format:
void x:doc() x:Document
type:
Static

x:e/0

description:
Returns the sequence of the direct subelements of the context element in the standard order.
format:
x:Element x:e() x:Element*
type:
Element-wise

x:e/1

description:
Returns the sequence of all direct subelements of the context element with name $name in the standard order.
format:
x:Element x:e($name string) x:Element*
type:
Element-wise

x:ee/0

description:
Returns the sequence of all subelements of the context element (at any depth) in the standard order.
format:
x:Element x:ee() x:Element*
type:
Element-wise

x:ee/1

description:
Returns the sequence of all subelements of the context element with the name $name (at any depth) in the standard order.
format:
x:Element x:ee($name string) x:Element*
type:
Element-wise

x:elem/1

description:
Creates a new XML element node named $name in the XML heap ontology.
format:
void x:elem($name string) x:Element
type:
Static

x:entities/0

description:
Returns the names of all HTML5 named entities (references). See http://www.w3.org/TR/html5/named-character-references.html for details.
format:
void x:entity() string+
type:
Static

x:entity/1

description:
Returns the unicode of the HTML5 named or numeric character reference (the 1st argument). See http://www.w3.org/TR/html5/named-character-references.html for the HTML5 named character references.
format:
void x:entity($reference string) int
type:
Static
examples:
x:entity("lt") / v:codes-string();   # = "<"
x:entity("#x25") / v:codes-string();    # = "%"

x:esc/1

description:
XML-escaping the string in the 1st argument. x:esc/1 can be used with the string evaluator '!'.
format:
void x:esc($text string) string
type:
Static
examples:
x:esc("<a>");    # = "<a>"
«<a>{"<a>"}</a>»!x:esc;   # = "<a><a></a>"

x:getHeap/0

description:
Gets the ontology currently used as the heap for XML entity objects.
format:
void x:getHeap() ontology
type:
Static

x:id/0

description:
Returns the id of the element, if it exists. Otherwise, returns nothing.
format:
x:Element x:id() v:string
type:
Element-wise

x:id/1

description:
Collects in the context the element with ID = $id.
format:
x:Element x:id($id string) x:Element
type:
Element-wise

x:setHeap/1

description:
Creates / assignes an ontology to be used as the heap for xml entity objects.
format:
void x:setHeap($uri string) ontology
type:
Static

x:text/1

description:
Creates a new xml text object in the XML heap ontology.
format:
void x:text($txt string) x:Text
type:
Static

x:tt/0

description:
Returns the text of the context element and all its subelements (at any depth) in the standard order.
format:
x:Element x:tt() string*
type:
Element-wise

x:xpath/1