summaryrefslogtreecommitdiff
path: root/docs/reference/libtracker-sparql/sparql-functions.md
blob: be8a48a8c50edb261a6fb5e8845bcdffacc5a03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
Title: Builtin SPARQL functions
slug: sparql-functions

Besides the functions built in the SPARQL 1.1 syntax, type casts
and functional properties, Tracker supports a number of SPARQL
functions. Some of these functions have correspondences in
[XPath](https://www.w3.org/TR/xpath-31/).

# String functions

## `fn:lower-case`

```SPARQL
fn:lower-case (?string)
```

Converts a string to lowercase, equivalent to `LCASE`.

## `fn:upper-case`

```SPARQL
fn:upper-case (?string)
```

Converts a string to uppercase, equivalent to `UCASE`.

## `fn:contains`

```SPARQL
fn:contains (?haystack, ?needle)
```

Returns a boolean indicating whether `?needle` is
found in `?haystack`. Equivalent to `CONTAINS`.

## `fn:starts-with`

```SPARQL
fn:starts-with (?string, ?prefix)
```

Returns a boolean indicating whether `?string`
starts with `?prefix`. Equivalent to `STRSTARTS`.

## `fn:ends-with`

```SPARQL
fn:ends-with (?string, ?suffix)
```

Returns a boolean indicating whether `?string`
ends with `?suffix`. Equivalent to `STRENDS`.

## `fn:substring`

```SPARQL
fn:substring (?string, ?startLoc)
fn:substring (?string, ?startLoc, ?endLoc)
```

Returns a substring delimited by the integer
`?startLoc` and `?endLoc` arguments. If `?endLoc`
is omitted, the end of the string is used.

## `fn:concat`

```SPARQL
fn:concat (?string1, ?string2, ..., ?stringN)
```

Takes a variable number of arguments and returns a string concatenation
of all its returned values. Equivalent to `CONCAT`.

## `fn:string-join`

```SPARQL
fn:string-join ((?string1, ?string2, ...), ?separator)
```

Takes a variable number of arguments and returns a string concatenation
using `?separator` to join all elements.

## `fn:replace`

```SPARQL
fn:replace (?string, ?regex, ?replacement)
fn:replace (?string, ?regex, ?replacement, ?flags)
```

Performs string replacement on `?string`. All
matches of `?regex` are replaced by `?replacement` in
the returned string. This function is similar to `REPLACE`.

The `?flags` argument is optional, a case search
is performed if not provided.

If `?flags` contains the character `“s”`, a dot metacharacter (".") in
`?regex` matches all characters, including newlines. Without it,
newlines are excluded.

If `?flags` contains the character `“m”`, the “start of line”
(`^`) and “end of line” (`$`) constructs match immediately following or
immediately before any newline in the string. If not set these constructs
will respectively match the start and end of the full string.

If `?flags` contains the character `“i”`, search is caseless.

If `?flags` contains the character `“x”`, `?regex` is
interpreted to be an extended regular expression.

## `tracker:case-fold`

```SPARQL
tracker:case-fold (?string)
```

Converts a string into a form that is independent of case.

## `tracker:title-order`

```SPARQL
tracker:title-order (?string)
```

Manipulates a string to remove leading articles for sorting
purposes, e.g. “Wall, The”. Best used in `ORDER BY` clauses.

## `tracker:ascii-lower-case`

```SPARQL
tracker:ascii-lower-case (?string)
```

Converts an ASCII string to lowercase, equivalent to `LCASE`.

## `tracker:normalize`

```SPARQL
tracker:normalize (?string, ?option)
```

Normalizes `?string`. The `?option` string must be one of
`nfc`, `nfd`, `nfkc` or `nfkd`.

## `tracker:unaccent`

```SPARQL
tracker:unaccent (?string)
```

Removes accents from a string.

## `tracker:coalesce`

```SPARQL
tracker:coalesce (?value1, ?value2, ..., ?valueN)
```

Picks the first non-null value. Equivalent to `COALESCE`.

## `tracker:strip-punctuation`

``` SPARQL
tracker:strip-punctuation (?string)
```

Removes any Unicode character which has the General
Category value of P (Punctuation) from the string.

# DateTime functions

## `fn:year-from-dateTime`

```SPARQL
fn:year-from-dateTime (?date)
```

Returns the year from a `xsd:date` type, a `xsd:dateTime`
type, or a ISO8601 date string. This function is equivalent
to `YEAR`.

## `fn:month-from-dateTime`

```SPARQL
fn:month-from-dateTime (?date)
```

Returns the month from a `xsd:date` type, a `xsd:dateTime`
type, or a ISO8601 date string. This function is equivalent to `MONTH`.

## `fn:day-from-dateTime`

```SPARQL
fn:day-from-dateTime (?date)
```

Returns the day from a `xsd:date` type, a `xsd:dateTime`
type, or a ISO8601 date string. This function is equivalent to `DAY`.

## `fn:hours-from-dateTime`

```SPARQL
fn:hours-from-dateTime (?date)
```

Returns the hours from a `xsd:dateTime` type or a ISO8601
datetime string. This function is equivalent to `HOURS`.

## `fn:minutes-from-dateTime`

```SPARQL
fn:minutes-from-dateTime (?date)
```

Returns the minutes from a `xsd:dateTime` type
or a ISO8601 datetime string. This function is equivalent to
`MINUTES`.

## `fn:seconds-from-dateTime`

```SPARQL
fn:seconds-from-dateTime (?date)
```

Returns the seconds from a `xsd:dateTime` type
or a ISO8601 datetime string. This function is equivalent to
`SECONDS`.

## `fn:timezone-from-dateTime`

```SPARQL
fn:timezone-from-dateTime (?date)
```

Returns the timezone offset in minutes. This function is similar, but
not equivalent to `TIMEZONE` or `TZ`.

## Full-text search functions

## `fts:rank`

```SPARQL
fts:rank (?match)
```

Returns the rank of a full-text search match. Must be
used in conjunction with `fts:match`.

## `fts:offsets`

```SPARQL
fts:offsets (?match)
```

Returns a string describing the offsets of a full-text search
match. Must be used in conjunction with `fts:match`. The returned
string has the format:

```
prefix:property:offset prefix:property:offset prefix:property:offset
```

## `fts:snippet`

```SPARQL
fts:snippet (?match)
fts:snippet (?match, ?delimStart, ?delimEnd)
fts:snippet (?match, ?delimStart, ?delimEnd, ?ellipsis)
fts:snippet (?match, ?delimStart, ?delimEnd, ?ellipsis, ?numTokens)
```

Returns a snippet string in accordance to the full-text search string.
Must be used in conjunction with `fts:match`.

The `?delimStart` and `?delimEnd` parameters allow specifying the
delimiters of the match strings inside the snippet.

The `?ellipsis` parameter allows specifying
the string used to separate distant matches in the snippet string.

The `?numTokens` parameter specifies the number
of tokens the returned string should containt at most.

# URI functions

## `tracker:uri-is-parent`

```SPARQL
tracker:uri-is-parent (?parent, ?uri)
```

Returns a boolean value expressing whether
`?parent` is a parent of `?uri`.

## `tracker:uri-is-descendant`

```SPARQL
tracker:uri-is-descendant (?uri1, ?uri2, ..., ?uriN, ?child)
```

Returns a boolean value expressing whether one of the
given URIs are a parent (direct or indirect) of
`?child`.

## `tracker:string-from-filename`

```SPARQL
tracker:string-from-filename (?filename)
```

Returns a UTF-8 string from a filename.

# Geolocation functions

## `tracker:cartesian-distance`

```SPARQL
tracker:cartesian-distance (?lat1, ?lat2, ?lon1, ?lon2)
```

Calculates the cartesian distance between 2 points expressed
by `?lat1 / ?lon1` and `?lat2 / ?lon2`.

## `tracker:haversine-distance`

```SPARQL
tracker:haversine-distance (?lat1, ?lat2, ?lon1, ?lon2)
```

Calculates the haversine distance between 2 points expressed
by `?lat1 / ?lon1` and `?lat2 / ?lon2`.

# Identification functions

## `tracker:id`

```SPARQL
tracker:id (?urn)
```

Returns the internal ID corresponding to a URN.
Its inverse operation is `tracker:uri`.

## `tracker:uri`

```SPARQL
tracker:uri (?id)
```

Returns the URN that corresponds to an ID.
Its inverse operation is `tracker:id`