Discussion:
[xquery-talk] A walk down Sesame St - counting for simpletons
Ihe Onwuka
2014-04-08 15:23:27 UTC
Permalink
count(colllection('myColl')//elem tells me how many elems there are in
myColl. Fine

So now I want to be told how many elems are in myColl and myColl2.

Put them in a sequence like so

(collection('myColl')//elem,collection('myColl2')//elem) and then
apply the count method to each element of the sequence n'est pas?

(collection('myColl')//elem,collection('myColl2')//elem)/count(.)

2 collections to give me 2 numbers .C'est domage, Mais non. That only
gives me one number - the count of elems in MyColl.

C'est fait rien methinks (or perhaps doesn't think). 3.0 map operator
to the rescue - let's substitute the / for a !.

Sacre bleu

I now have a stream of N 1's where N is the number of elems in
MyColl............

I have gone back to the more prosaic method of counting each
collection with a comma separator to transform the answer to a
sequence.
Andrew Welch
2014-04-08 15:43:33 UTC
Permalink
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.

Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
Ihe Onwuka
2014-04-08 15:50:04 UTC
Permalink
....but that my dear plonker..... does not return a stream of ones......Oops!
Post by Andrew Welch
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.
Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
David Carlisle
2014-04-08 15:59:15 UTC
Permalink
Post by Ihe Onwuka
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
....but that my dear plonker..... does not return a stream of ones......Oops!
It should, unless there is a bug somewhere, count() applied to an
element node is only ever going to return 1.

David
Ihe Onwuka
2014-04-08 16:00:51 UTC
Permalink
Post by Ihe Onwuka
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
....but that my dear plonker..... does not return a stream of
ones......Oops!
It should, unless there is a bug somewhere, count() applied to an element
node is only ever going to return 1.
The answer I got tallies with what Mike Sokolov said I would get.
David Carlisle
2014-04-08 16:05:59 UTC
Permalink
Post by Ihe Onwuka
The answer I got tallies with what Mike Sokolov said I would get.
which system did you use?

count((collection('myColl')//elem,collection('myColl2')//elem))

should be the total

(collection('myColl')//elem,collection('myColl2')//elem))/count(.)


is a sequence of 1's. as you have a sequence of elem elements (however
constructed) followed by /count(.) and count(.) on an element is 1.

David
Andrew Welch
2014-04-08 16:05:45 UTC
Permalink
Happy to be the plonker if I'm wrong but:

($seq)/count(.)

will only ever produce a sequence of 1s (or 0 when $seq is empty)...

If you are saying otherwise please provide small complete runnable
sample so I recreate it. (and please really do provide an actual
sample of runnable code that really does show it)
Post by Ihe Onwuka
....but that my dear plonker..... does not return a stream of ones......Oops!
Post by Andrew Welch
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.
Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
--
Andrew Welch
http://andrewjwelch.com
Ihe Onwuka
2014-04-08 16:17:50 UTC
Permalink
I'm not creating a collection as I've already exceeded my allocated
time for talking about this. However I can oblige with a slightly
edited screen print of query and result. The answer is at the bottom.
The eXist people read the list, it was run on their XQuery processor
so perhaps they may want to comment.

I am finito here.

NewNew XQueryOpenSaveCloseRunCheck

countM.xq*
new-document 1*
new-document 2

1
2
3
xquery version "3.0";
(collection('/db/apps/spark/data/rtUnmatched')//thing,collection('/db/apps/spark/data/rtID')//thing)/count(.)
/db/apps/spark/programs/countMovies.xq

Outline

Live Preview
Showing results 1 to 1 of 1
87567
Post by Andrew Welch
($seq)/count(.)
will only ever produce a sequence of 1s (or 0 when $seq is empty)...
If you are saying otherwise please provide small complete runnable
sample so I recreate it. (and please really do provide an actual
sample of runnable code that really does show it)
Post by Ihe Onwuka
....but that my dear plonker..... does not return a stream of ones......Oops!
Post by Andrew Welch
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.
Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
--
Andrew Welch
http://andrewjwelch.com
Andrew Welch
2014-04-08 16:32:40 UTC
Permalink
Post by Ihe Onwuka
I'm not creating a collection as I've already exceeded my allocated
time for talking about this.
funny that...
Post by Ihe Onwuka
I am finito here.
A small complete runnable example is something like this:

(<thing/>, (<thing/>, <thing/>))/count(.)

If you think about it, the slash operator passes each node on the LHS
to the function on the RHS... so it can only ever produce 1 1 1 etc

This time next year, Rodders...
--
Andrew Welch
http://andrewjwelch.com
Ihe Onwuka
2014-04-08 16:41:26 UTC
Permalink
Post by Andrew Welch
Post by Ihe Onwuka
I'm not creating a collection as I've already exceeded my allocated
time for talking about this.
funny that...
It's a non critical query that from the example posted you can see
only involved 2 collections, but perhaps you have nothing better to
do.
Post by Andrew Welch
Post by Ihe Onwuka
I am finito here.
(<thing/>, (<thing/>, <thing/>))/count(.)
Sorry you seem to have a deluded sense of self-importance. Since when
did I have to comply with your requests?
Andrew Welch
2014-04-08 17:05:26 UTC
Permalink
Post by Ihe Onwuka
Sorry you seem to have a deluded sense of self-importance. Since when
did I have to comply with your requests?
People will question the "seem to" in that sentence.

Is it really necessary to have ask for small complete runnable
samples... isn't that common mailing list etiquette these days?
--
Andrew Welch
http://andrewjwelch.com
Ihe Onwuka
2014-04-08 17:38:14 UTC
Permalink
Post by Andrew Welch
Post by Ihe Onwuka
Sorry you seem to have a deluded sense of self-importance. Since when
did I have to comply with your requests?
People will question the "seem to" in that sentence.
Is it really necessary to have ask for small complete runnable
samples... isn't that common mailing list etiquette these days?
Mailing list etiquette eh.

The pasted screen print of the query and the result it gave - was not
enough? You want me to do more work to satisfy a curiosity that I no
longer have because you still harbour it?

DC gave an illuminating answer and I have clarified that my curiosity
is in seeing a formulation that used the / or ! operators. Did that
part of the conversation pass you by?

OTOH your answer and every thing you have contributed since did
nothing to point towards the correct formulation of the query for the
problem stated. Thats ok, but somehow you find it funny that I don't
wish to waste my time talking about that.

Funny perhaps but you should not find it strange that I don't wish to
carry on engaging. This may sound patronising (where've I heard that
before) but you can generally be relied upon to proffer a
spectacularly insular perspective to a discussion, so invariably I
don't want to stick around responding to everything you want to say.

Why do you keep doing it (that's rhetorical hence no question mark).
Do you see a mailing list as a venue for venting your machismo? Look
there are better ways of getting rid of the excess testosterone. Trust
me on that one.
Andrew Welch
2014-04-08 18:35:40 UTC
Permalink
Post by Ihe Onwuka
Post by Andrew Welch
Is it really necessary to have ask for small complete runnable
samples... isn't that common mailing list etiquette these days?
Mailing list etiquette eh.
The pasted screen print of the query and the result it gave - was not
enough? You want me to do more work to satisfy a curiosity that I no
longer have because you still harbour it?
No it's not enough: it's not a small complete runnable sample so
people can recreate what you are asserting. You make a statement,
people question it, then you never back it up. You try and close the
thread down. I've lost count of the threads you've started that have
ended like this...
Post by Ihe Onwuka
DC gave an illuminating answer and I have clarified that my curiosity
is in seeing a formulation that used the / or ! operators. Did that
part of the conversation pass you by?
No - I was talking about how $seq/count(.) will always produce a
sequence of 1s (or () as was noted to me offlist) Remember you
called me a plonker for saying that?
Post by Ihe Onwuka
OTOH your answer and every thing you have contributed since did
nothing to point towards the correct formulation of the query for the
problem stated. Thats ok, but somehow you find it funny that I don't
wish to waste my time talking about that.
I find all this nonsense funny.
Post by Ihe Onwuka
Funny perhaps but you should not find it strange that I don't wish to
carry on engaging.
Stop engaging then.
Post by Ihe Onwuka
This may sound patronising (where've I heard that
before) but you can generally be relied upon to proffer a
spectacularly insular perspective to a discussion, so invariably I
don't want to stick around responding to everything you want to say.
Don't respond then.
Post by Ihe Onwuka
Why do you keep doing it (that's rhetorical hence no question mark).
Do you see a mailing list as a venue for venting your machismo? Look
there are better ways of getting rid of the excess testosterone. Trust
me on that one.
Er I'm not sure how to read that one... "getting rid of excess
testosterone" sounds like something teenage boys do.

That mark twain quote springs to mind, so I really should stop arguing now.
--
Andrew Welch
http://andrewjwelch.com
Ihe Onwuka
2014-04-08 19:16:31 UTC
Permalink
Post by Andrew Welch
Post by Ihe Onwuka
Why do you keep doing it (that's rhetorical hence no question mark).
Do you see a mailing list as a venue for venting your machismo? Look
there are better ways of getting rid of the excess testosterone. Trust
me on that one.
Er I'm not sure how to read that one... "getting rid of excess
testosterone" sounds like something teenage boys do.
You obviously didn't learn any other way so you keep trying to spend it here.

But you know what. People like you are good. They make a fellow study
hard while they at school so that when they finish and enter the
workforce they know exactly the type of person not to take s**t from.
Ihe Onwuka
2014-04-08 20:29:24 UTC
Permalink
Post by Andrew Welch
Post by Ihe Onwuka
Post by Andrew Welch
Is it really necessary to have ask for small complete runnable
samples... isn't that common mailing list etiquette these days?
Mailing list etiquette eh.
The pasted screen print of the query and the result it gave - was not
enough? You want me to do more work to satisfy a curiosity that I no
longer have because you still harbour it?
Nah let's deal with you once and for all. After all you are on
repeatedly record as enjoying this sort of stuff.
Post by Andrew Welch
it's not a small complete runnable sample so
people can recreate what you are asserting. You make a statement,
people question it, then you never back it up. You try and close the
thread down. I've lost count of the threads you've started that have
ended like this...
Thats because you're like one of those kids in the playground that
think that everybody has to play the game you want to play by the
rules you want to play by and talk about what you want to talk about
in the way you want to talk about it (code not words right! because
Andrew said so).
Post by Andrew Welch
Post by Ihe Onwuka
DC gave an illuminating answer and I have clarified that my curiosity
is in seeing a formulation that used the / or ! operators. Did that
part of the conversation pass you by?
No - I was talking about how $seq/count(.) will always produce a
sequence of 1s (or () as was noted to me offlist) Remember you
called me a plonker for saying that?
I returned the compliment. Everybody on our side of the Atlantic knows
what rodders is a euphemism for.

Mike S and the eXist developers seem to have made the same mistake
(which I'll come back to later) - are they plonkers too?
Post by Andrew Welch
Post by Ihe Onwuka
This may sound patronising (where've I heard that
before) but you can generally be relied upon to proffer a
spectacularly insular perspective to a discussion, so invariably I
don't want to stick around responding to everything you want to say.
Don't respond then.
And when you don't get a response you complain that people make
statements they don't back up. I almost said it was amazing how you
can simultaneously hold both positions in the course of one reply but
actually it's not.

Look if your primary objective was a professional one then the
observation to have made in this thread (which someone else already
did) is that there seems to be a buggy XQuery implementation at play
here. Because if a stream of ones is the correct response and thats
what is returned then what happened to cause that is immediately
apparent.

You on the other hand harbour the pathetically juvenile viewpoint that
the scenario offered an opportunity to come on here and josh d**ks.
Why? Maybe you were the puny kid at school who used smarts at other
peoples expense instead of fists to build self esteem. That stops
working when l you come across a kid who is both bigger and smarter.

While we are on the subject of childhoods, you know all those kids who
say "My mother told me that if you can't say something nice about
someone you shouldn't say anything at all".

Well my mother never told me that.

Keep bringing it fool.
Ronald Bourret
2014-04-08 22:15:44 UTC
Permalink
Ihe,

Up until now, your repeated rudeness and demanding attitude on this list
has been modestly amusing. This post moves well past amusing and into
the patently offensive. Personally, I would suggest that the moderator
(if there is one) either remove you from the list or that other members
simply not answer your questions.

-- Ron
Post by Ihe Onwuka
You on the other hand harbour the pathetically juvenile viewpoint that
the scenario offered an opportunity to come on here and josh d**ks.
Why? Maybe you were the puny kid at school who used smarts at other
peoples expense instead of fists to build self esteem. That stops
working when l you come across a kid who is both bigger and smarter.
While we are on the subject of childhoods, you know all those kids who
say "My mother told me that if you can't say something nice about
someone you shouldn't say anything at all".
Well my mother never told me that.
Keep bringing it fool.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
Ihe Onwuka
2014-04-08 22:24:52 UTC
Permalink
Go ahead. I don't give a toss.
Ihe,
Up until now, your repeated rudeness and demanding attitude on this list has
been modestly amusing. This post moves well past amusing and into the
patently offensive. Personally, I would suggest that the moderator (if there
is one) either remove you from the list or that other members simply not
answer your questions.
-- Ron
Post by Ihe Onwuka
You on the other hand harbour the pathetically juvenile viewpoint that
the scenario offered an opportunity to come on here and josh d**ks.
Why? Maybe you were the puny kid at school who used smarts at other
peoples expense instead of fists to build self esteem. That stops
working when l you come across a kid who is both bigger and smarter.
While we are on the subject of childhoods, you know all those kids who
say "My mother told me that if you can't say something nice about
someone you shouldn't say anything at all".
Well my mother never told me that.
Keep bringing it fool.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-04-08 21:18:18 UTC
Permalink
http://exist.2174344.n4.nabble.com/counting-bug-td4664056.html
Post by Ihe Onwuka
I'm not creating a collection as I've already exceeded my allocated
time for talking about this. However I can oblige with a slightly
edited screen print of query and result. The answer is at the bottom.
The eXist people read the list, it was run on their XQuery processor
so perhaps they may want to comment.
I am finito here.
NewNew XQueryOpenSaveCloseRunCheck
countM.xq*
new-document 1*
new-document 2
1
2
3
xquery version "3.0";
(collection('/db/apps/spark/data/rtUnmatched')//thing,collection('/db/apps/spark/data/rtID')//thing)/count(.)
/db/apps/spark/programs/countMovies.xq
Outline
Live Preview
Showing results 1 to 1 of 1
87567
Post by Andrew Welch
($seq)/count(.)
will only ever produce a sequence of 1s (or 0 when $seq is empty)...
If you are saying otherwise please provide small complete runnable
sample so I recreate it. (and please really do provide an actual
sample of runnable code that really does show it)
Post by Ihe Onwuka
....but that my dear plonker..... does not return a stream of ones......Oops!
Post by Andrew Welch
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.
Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
--
Andrew Welch
http://andrewjwelch.com
Liam R E Quin
2014-04-09 01:06:54 UTC
Permalink
Post by Ihe Onwuka
http://exist.2174344.n4.nabble.com/counting-bug-td4664056.html
I've found it incredibly useful in the past to set things up so I can
run tests against more than one implementation - I use Saxon and BaseX
the most often. I tried MarkLogic once but I wasn't smart enough to work
it :) although years ago I also used Galax and, until a year or so,
qizx.

Actually I still use qizx/open for some things on www.fromoldbooks.org
because it's so fast and I haven't found time to move those queries to
basex.


Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
Another barefoot programmer.
Michael Sokolov
2014-04-08 16:38:14 UTC
Permalink
Yes, that's true - I stand corrected
Post by Andrew Welch
($seq)/count(.)
will only ever produce a sequence of 1s (or 0 when $seq is empty)...
If you are saying otherwise please provide small complete runnable
sample so I recreate it. (and please really do provide an actual
sample of runnable code that really does show it)
Post by Ihe Onwuka
....but that my dear plonker..... does not return a stream of ones......Oops!
Post by Andrew Welch
Post by Ihe Onwuka
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
^^^ that constructs a sequence of <elem>s, and then supplies each one
to the count() function... so it will just a return a load of 1s.
Bonney dee doosh, ala quet de mer, rodders.
--
Andrew Welch
http://andrewjwelch.com
Michael Sokolov
2014-04-08 15:46:46 UTC
Permalink
Post by Ihe Onwuka
count(colllection('myColl')//elem tells me how many elems there are in
myColl. Fine
So now I want to be told how many elems are in myColl and myColl2.
Put them in a sequence like so
(collection('myColl')//elem,collection('myColl2')//elem) and then
apply the count method to each element of the sequence n'est pas?
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
2 collections to give me 2 numbers .C'est domage, Mais non. That only
gives me one number - the count of elems in MyColl.
That should give you the total count of both. You are thinking that you
have a sequence of sequences, but you don't since there is no such thing
in XPath -- only sequences of items (nodes and atomic values).
Post by Ihe Onwuka
C'est fait rien methinks (or perhaps doesn't think). 3.0 map operator
to the rescue - let's substitute the / for a !.
Sacre bleu
I now have a stream of N 1's where N is the number of elems in
MyColl............
I have gone back to the more prosaic method of counting each
collection with a comma separator to transform the answer to a
sequence.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-04-08 15:52:34 UTC
Permalink
On Tue, Apr 8, 2014 at 4:46 PM, Michael Sokolov
Post by Michael Sokolov
Post by Ihe Onwuka
count(colllection('myColl')//elem tells me how many elems there are in
myColl. Fine
So now I want to be told how many elems are in myColl and myColl2.
Put them in a sequence like so
(collection('myColl')//elem,collection('myColl2')//elem) and then
apply the count method to each element of the sequence n'est pas?
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
2 collections to give me 2 numbers .C'est domage, Mais non. That only
gives me one number - the count of elems in MyColl.
That should give you the total count of both. You are thinking that you
have a sequence of sequences, but you don't since there is no such thing in
XPath -- only sequences of items (nodes and atomic values).
Indeed.... that tallies with what I got and was why I reached for the
map operator. Try first and ask later. That's ok for a a non critical
query.
David Carlisle
2014-04-08 15:54:37 UTC
Permalink
Post by Ihe Onwuka
count(colllection('myColl')//elem tells me how many elems there are in
myColl. Fine
So now I want to be told how many elems are in myColl and myColl2.
Put them in a sequence like so
(collection('myColl')//elem,collection('myColl2')//elem) and then
apply the count method to each element of the sequence n'est pas?
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
XPath sequences don't nest ((1,2,3),(4,5,6)) is (1,2,3,4,5,6) so your
issue is nothing to do with count() but rather with the sequence you are
constructing.

for $c in ('myColl','myColl2') return count(collection($c)//elem)
Ihe Onwuka
2014-04-08 16:04:32 UTC
Permalink
yes, for some reason I strenuously avoid using the for version of
Flowr syntax so abandoned my attempt without considering it.

So although I like the minimalistic way you formulated the query
(sequencing over only the collection string) my curiosity is centred
on the challenge of doing it with the just / operator.
Post by Ihe Onwuka
count(colllection('myColl')//elem tells me how many elems there are in
myColl. Fine
So now I want to be told how many elems are in myColl and myColl2.
Put them in a sequence like so
(collection('myColl')//elem,collection('myColl2')//elem) and then
apply the count method to each element of the sequence n'est pas?
(collection('myColl')//elem,collection('myColl2')//elem)/count(.)
XPath sequences don't nest ((1,2,3),(4,5,6)) is (1,2,3,4,5,6) so your issue
is nothing to do with count() but rather with the sequence you are
constructing.
for $c in ('myColl','myColl2') return count(collection($c)//elem)
_______________________________________________
http://x-query.com/mailman/listinfo/talk
David Carlisle
2014-04-08 16:08:16 UTC
Permalink
Post by Ihe Onwuka
yes, for some reason I strenuously avoid using the for version of
Flowr syntax so abandoned my attempt without considering it.
well you could use ! instead, I don't have a version 3 to hand but I
think it would be


('myColl','myColl2')!count(collection(.)//elem)
Andrew Welch
2014-04-08 16:29:14 UTC
Permalink
Post by Ihe Onwuka
yes, for some reason I strenuously avoid using the for version of
Flowr syntax so abandoned my attempt without considering it.
well you could use ! instead, I don't have a version 3 to hand but I think
it would be
('myColl','myColl2')!count(collection(.)//elem)
It's been a while but I think eXist's collection() implementation can
take a sequence:

count( collection(('myColl', 'myColl2'))//elem )

MarkLogic, Saxon etc all take sequences
--
Andrew Welch
http://andrewjwelch.com
Andrew Welch
2014-04-08 16:43:53 UTC
Permalink
Post by Andrew Welch
Post by Ihe Onwuka
yes, for some reason I strenuously avoid using the for version of
Flowr syntax so abandoned my attempt without considering it.
well you could use ! instead, I don't have a version 3 to hand but I think
it would be
('myColl','myColl2')!count(collection(.)//elem)
It's been a while but I think eXist's collection() implementation can
count( collection(('myColl', 'myColl2'))//elem )
MarkLogic, Saxon etc all take sequences
^^^ which is of course different to what DC posted... his provides a
count of per collection, but the latter does the count across
collections.
--
Andrew Welch
http://andrewjwelch.com
Loading...