Re: [basex-talk] Looking for something that may not exist...

2014-08-18 Thread Marc van Grootel
Hi France,

I'm wondering what you mean with tracking. Is it to gather diagnostics during 
development? Is it for adding logging or is it part of running production code? 
Do you want to add this to every function or only a few specific ones?

Maybe some kind tracing/profiling mechanism could provide this without altering 
your running code. But I'm not sure if that's what you are after.

If this tracking is a real feature of your code then it's different. I hope 
your request is not because your functions have a lot of arguments. That would 
be an indication that your code needs some refactoring :)

Could you tell us what you mean with tracking capabilities?

--Marc

> On 18 aug. 2014, at 21:39, Andy Bunce  wrote:
> 
> Hi France,
> 
> I think this is not possible, but I think it would be a good thing!
> I think it is related to Marc's query about 
> call an anonymous function with a variable argument list [1]
> 
> XQuery provides no access to the stack. 
> But..I can see that one could implement a new function maybe in the BaseX 
> profiling module [2] that returns a map.
> The keys would be the argument names of the function being executed and the 
> values those of the current arguments.
> 
> All that is required is to implement it :-)
> 
> /Andy
> 
> [1] 
> http://www.mail-archive.com/basex-talk%40mailman.uni-konstanz.de/msg04539.html
> [2] http://docs.basex.org/wiki/Profiling_Module
> 
> 
> 
>> On 18 August 2014 18:14, France Baril  wrote:
>> Hi, 
>> 
>> I'm working on improving our tracking capabilities. I was hoping to find a 
>> function that would do the equivalent of what the code bellow does, but for 
>> internal functions that are not called through the rest interface.
>> 
>> string-join(for $name in request:parameter-names() 
>>  return $name || ': '
>>   || string-join(request:parameter($name), 
>> '; '), 
>>  '
') 
>> 
>> In short, I was wondering if there is way I can read the function's 
>> parameters and their values without listing each one explicitly.
>> 
>> I searched the documentation without success. 
>> 
>> -- 
>> France Baril
>> Architecte documentaire / Documentation architect
>> france.ba...@architextus.com
> 


Re: [basex-talk] Looking for something that may not exist...

2014-08-18 Thread Andy Bunce
Hi France,

I think this is not possible, but I think it would be a good thing!
I think it is related to Marc's query about
call an anonymous function with a variable argument list [1]

XQuery provides no access to the stack.
But..I can see that one could implement a new function maybe in the BaseX
profiling module [2] that returns a map.
The keys would be the argument names of the function being executed and the
values those of the current arguments.

All that is required is to implement it :-)

/Andy

[1]
http://www.mail-archive.com/basex-talk%40mailman.uni-konstanz.de/msg04539.html
[2] http://docs.basex.org/wiki/Profiling_Module



On 18 August 2014 18:14, France Baril  wrote:

> Hi,
>
> I'm working on improving our tracking capabilities. I was hoping to find a
> function that would do the equivalent of what the code bellow does, but for
> internal functions that are not called through the rest interface.
>
> *string-join*(*for **$name* *in **request:parameter-names*()
>  *return **$name* || ': '
>   || *string-join*(*request:parameter*(*$name*),
> '; '),
>  '
')
>
> In short, I was wondering if there is way I can read the function's
> parameters and their values without listing each one explicitly.
>
> I searched the documentation without success.
>
> --
> France Baril
> Architecte documentaire / Documentation architect
> france.ba...@architextus.com
>


[basex-talk] Looking for something that may not exist...

2014-08-18 Thread France Baril
Hi,

I'm working on improving our tracking capabilities. I was hoping to find a
function that would do the equivalent of what the code bellow does, but for
internal functions that are not called through the rest interface.

*string-join*(*for **$name* *in **request:parameter-names*()
 *return **$name* || ': '
  || *string-join*(*request:parameter*(*$name*),
'; '),
 '
')

In short, I was wondering if there is way I can read the function's
parameters and their values without listing each one explicitly.

I searched the documentation without success.

-- 
France Baril
Architecte documentaire / Documentation architect
france.ba...@architextus.com


Re: [basex-talk] random:integer vs. random:seeded-integer

2014-08-18 Thread Dirk Kirsten
Hello Amanda,

I agree, this behaviour is inconsistent. I am not quite sure what is the
best way to go here. Raising no error and simply returning 0 (as it is
currently done for random:integer() if max is out of range) seems pretty
dangerous to me, considering that randomness is often used for security
and an unexpected 0 might be hazardous.
Raising a Java error is maybe not the most elegant thing, maybe an
XQuery error would be more elegant (like FOAR0001, see
https://docs.basex.org/wiki/XQuery_Errors).

I created a small pull request, which also throws an error for
random:integer() if max is out of range, see
https://github.com/BaseXdb/basex/pull/985.

Cheers,
Dirk

On 18/08/14 15:56, Amanda Galtman wrote:
> Hi,
> 
> Is it intentional that random:integer lets you use zero or a negative value 
> for $max, but random:seeded-integer errors out in those cases? I know these 
> are edge cases. I'm only flagging them because of the inconsistency between 
> the two similar functions.
> 
> (: Returns (0,0). :)
> (random:integer(0),random:integer(-5))
> 
> (: Errors out :)
> random:seeded-integer(31,1,0)
> 
> (: Errors out :)
> random:seeded-integer(31,1,-5)
> 
> 
> Here is the error information from the last command above.
> 
> Error:
> Improper use? Potential bug? Your feedback is welcome:
> Contact: basex-talk@mailman.uni-konstanz.de
> Version: BaseX 7.9
> Java: Oracle Corporation, 1.7.0_25
> OS: Windows 7, amd64
> Stack Trace: 
> java.lang.IllegalArgumentException: n must be positive
>   at java.util.Random.nextInt(Unknown Source)
>   at org.basex.query.func.FNRandom$1.next(FNRandom.java:85)
>   at org.basex.query.MainModule$1.next(MainModule.java:98)
>   at org.basex.query.QueryContext.execute(QueryContext.java:598)
>   at org.basex.query.QueryProcessor.execute(QueryProcessor.java:101)
>   at org.basex.core.cmd.AQuery.query(AQuery.java:82)
>   at org.basex.core.cmd.XQuery.run(XQuery.java:22)
>   at org.basex.core.Command.run(Command.java:329)
>   at org.basex.core.Command.execute(Command.java:94)
>   at org.basex.gui.GUI.exec(GUI.java:417)
>   at org.basex.gui.GUI.access$500(GUI.java:41)
>   at org.basex.gui.GUI$8.run(GUI.java:361)
> 
> 
> Cheers,
> Amanda
> 

-- 
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
|   Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle
`-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22


[basex-talk] random:integer vs. random:seeded-integer

2014-08-18 Thread Amanda Galtman
Hi,

Is it intentional that random:integer lets you use zero or a negative value for 
$max, but random:seeded-integer errors out in those cases? I know these are 
edge cases. I'm only flagging them because of the inconsistency between the two 
similar functions.

(: Returns (0,0). :)
(random:integer(0),random:integer(-5))

(: Errors out :)
random:seeded-integer(31,1,0)

(: Errors out :)
random:seeded-integer(31,1,-5)


Here is the error information from the last command above.

Error:
Improper use? Potential bug? Your feedback is welcome:
Contact: basex-talk@mailman.uni-konstanz.de
Version: BaseX 7.9
Java: Oracle Corporation, 1.7.0_25
OS: Windows 7, amd64
Stack Trace: 
java.lang.IllegalArgumentException: n must be positive
at java.util.Random.nextInt(Unknown Source)
at org.basex.query.func.FNRandom$1.next(FNRandom.java:85)
at org.basex.query.MainModule$1.next(MainModule.java:98)
at org.basex.query.QueryContext.execute(QueryContext.java:598)
at org.basex.query.QueryProcessor.execute(QueryProcessor.java:101)
at org.basex.core.cmd.AQuery.query(AQuery.java:82)
at org.basex.core.cmd.XQuery.run(XQuery.java:22)
at org.basex.core.Command.run(Command.java:329)
at org.basex.core.Command.execute(Command.java:94)
at org.basex.gui.GUI.exec(GUI.java:417)
at org.basex.gui.GUI.access$500(GUI.java:41)
at org.basex.gui.GUI$8.run(GUI.java:361)


Cheers,
Amanda


Re: [basex-talk] Extra signature for fn:filter shown on wiki page

2014-08-18 Thread Amanda Galtman
Thanks for repyling, Dirk. I will delete the gray syntax from that wiki page.

Cheers,
Amanda

> Date: Sun, 17 Aug 2014 07:44:16 +0200
> From: Dirk Kirsten 
> To: basex-talk@mailman.uni-konstanz.de
> Subject: Re: [basex-talk] Extra signature for fn:filter shown on wiki
>   page
> Message-ID: <53f04130.80...@basex.org>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hello Amanda,
> 
> you are invited to delete that. I am pretty sure that is left from a change to
> the spec (and accordingly the change in our function signatures). Some time
> ago, the argument order for the HOF functions in the spec was changed,
> moving the sequence items to the first argument position.
> So the gray version is actually outdated and as we didn't keep in the the
> other function signatures I think it is safe to delete it.
> 
> Cheers,
> Dirk
> 
> On 17/08/14 03:19, Amanda Galtman wrote:
> > Hi,
> >
> > The documentation page
> > http://docs.basex.org/wiki/Higher-Order_Functions#fn:filter
> > shows two signatures for the fn:filter function, the second of which is in
> gray. Does it belong? It doesn't seem to work or match the spec, but I'm
> hesitant to delete it from the wiki in case I am wrong.
> >
> > fn:filter($seq as item()*, $pred as function(item()) as xs:boolean))
> > as item()* fn:filter($pred as function(item()) as xs:boolean, $seq as
> > item()*) as item()*
> >
> > Thanks,
> > Amanda
> >
> 
> --
> Dirk Kirsten, BaseX GmbH, http://basex.org
> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
> |-- Registergericht Freiburg, HRB: 708285, Gesch?ftsf?hrer:
> |   Dr. Christian Gr?n, Dr. Alexander Holupirek, Michael Seiferle
> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
> 
> 
> End of BaseX-Talk Digest, Vol 56, Issue 33
> **


Re: [basex-talk] Paged results

2014-08-18 Thread Michael Seiferle

Hi Paul,

thanks for this snippet!
Have you already seen the built-in min/max functions?

max((1,2,3)), min((1,2,3))
Might save both, some bytes and milliseconds, neglectable but 
nevertheless. :-)



Best from Konstanz

Michael
On 15 Aug 2014, at 22:02, Paul Swennenhuis wrote:


Hi all,

Triggered by a thread in this forum I decided to make a paged() 
function that adds paging information to a node-set.
It does so by wrapping the node-set in an root element - with a name 
of your choice - with attributes for total number of nodes, 
start-index  requested page-size, actual page-size and end-index.
The last function argument lets you select whether or not to output a 
paged node-set or just wrap the node-set in a root element.


It's not very spectacular but it may be of use if you want to use 
BaseX for paged results or endless scrolling.

Comments are appreciated.

The module with the paged() function:
-
module namespace lib = "My Library";

(:
lib:paged adds paging information to a node-set
in order to enable paged results for a web-app
Will return a node with the name as specified in $nodeName
along with total number of nodes ($total), start-index ($start), 
requested page-size ($num), actual page-size ($displayed)
and end-index ($end) as attributes, followed by the subsequence of the 
node-set


Collection MUST be a node-set (i.e. must NOT have a root element)

If $doPaged argument is false(), only the root node with the original 
collection is returned
The parameter makes it easier to do a non-conditional call of the 
function on a node-set


:)

declare function lib:paged ($collection, $nodeName, $start, $pageSize, 
$doPaged) {

let $total := count($collection)
let $min := lib:max(lib:min($pageSize,lib:min($total,$total - $start + 
1)),0)

return
 element {$nodeName} {
   if ($doPaged) then (
attribute total {$total},
attribute start {$start},
attribute pageSize {$pageSize},
attribute actualPageSize {$min},
attribute end {$start + $min - 1},
subsequence($collection, $start, $pageSize)
 )
   else
$collection
 }

};

(: Return smallest of two numbers :)

declare function lib:min($a,$b) {
if ($a < $b) then $a else $b
};

(: Return largest of two numbers :)

declare function lib:max($a,$b) {
if ($a > $b) then $a else $b
};




Usage example:

---

import module namespace lib="My Library" at "library.xqy";

lib:paged(collection("Facts")//city, 'cities', 500, 300, true())



Paul