r2 - 01 Apr 2006 - 13:17:20 - TonyLindeYou are here: TWiki >  Main Web  >  TonyLinde > TonyOnXQuery
Quick hack of a page to save results of XQuery trials. I want to be able to return a list of unique occurrences of one field alongside a count of how many resources exhibit that field value. I'll reorganise this page later but this is a text file I've been keeping of results. I'm putting it here as I work on this is three different places and I've already lost one set of results by overwriting an older file with a newer one frown

Note: all these were run using the XQuery interface to the AstroGrid registry (stored in eXist XML database) from the ACR

-- on one line:
<stores> { for $x in //vor:Resource where $x/vr:identifier &= 'filemanager'  return <service curator="{$x/vr:curation/vr:contact/vr:name}">{data($x/vr:identifier)}</service> } </stores>

-- or on multiple lines:
<stores>
{
for $x in //vor:Resource where $x/vr:identifier &= 'filemanager' 
return <service curator="{$x/vr:curation/vr:contact/vr:name}">{data($x/vr:identifier)}</service>
}
</stores>

-- returns:
<stores>
        <service curator="Tony Linde">ivo://uk.ac.le.star/filemanager</service>
        <service curator="Matthew Wild">ivo://uk.ac.ral.ukssdc/astrogrid-filemanager</service>
        <service curator="ElizabethAuden">ivo://esdo.mssl.ucl.ac.uk/esdo-filemanager</service>
        <service curator="Sergey Stupnikov">ivo://ipi.ac.ru/filemanager</service>
        <service curator="KMB">ivo://mssl.ucl.ac.uk/filemanager</service>
        <service curator="RVO Development Team">ivo://rvo/filemanager-sai</service>
        <service curator="Pierre Le Sidaner">ivo://obspm.fr/filemanager-vo</service>
</stores>
==========================================

-- Noel's original XQuery example:
<types>
{
for $x in //vor:Resource where $x/vr:identifier &= 'filemanager' 
return <type>{data($x/@xsi:type)}</type>
}
</types>

-- return all distinct resource types in database
<types>
{
for $t in distinct-values(//vor:Resource/@xsi:type)
order by $t
  return <type>{$t}</type>
}
</types>

==>  
<types>
   <type>RdbmsMetadata</type>
   <type>ServiceType</type>
   <type>cea:CeaApplicationType</type>
   <type>cea:CeaHttpApplicationType</type>
   <type>cea:CeaServiceType</type>
   <type>cs:ConeSearch</type>
   <type>jsn:OpenSkyNodeJ</type>
   <type>osn:OpenSkyNode</type>
   <type>q1:Authority</type>
   <type>q1:ConeSearch</type>
   <type>q1:OpenSkyNode</type>
   <type>q1:SimpleImageAccess</type>
   <type>reg:Authority</type>
   <type>sia:SimpleImageAccess</type>
   <type>sn:OpenSkyNode</type>
   <type>ssa:SimpleSpectrumAccess</type>
   <type>tdb:TabularDB</type>
   <type>vg:Authority</type>
   <type>vg:Registry</type>
   <type>vor:TabularSkyService</type>
   <type>vr:Organisation</type>
   <type>vr:Resource</type>
   <type>vr:Service</type>
   <type>vs:DataCollection</type>
   <type>vs:SkyService</type>
   <type>vs:TabularSkyService</type>
</types>

-- get all distinct UCDs
<ucds>
{
for $t in distinct-values(//*:ucd)
order by $t
  return <ucd>{$t}</ucd>
}
</ucds>

==>   
<ucds>
    <ucd>?</ucd>
    <ucd>AT_COLL_EXCIT-RATE</ucd>
    <ucd>AT_COLL_STRENGTH</ucd>
    <ucd>AT_CONFIG</ucd>
    ...  
</ucds> 
==========================================

-- get count of Resources with xsi:type = 'CeaApplicationType'
<ct>
{
  count(//vor:Resource[@xsi:type &= "cea:CeaApplicationType"])
}
</ct>

==>  <ct>94</ct> 

-- get count of CDS resources
<ct>
{
  count(//vor:Resource[./vr:identifier &= 'ivo://CDS/*'])
}
</ct>

==>  <ct>11090</ct>

-- get count of ucds with value of 'POS_EQ_RA'
<ct>
{
  count(//*:ucd[. &= "POS_EQ_RA"])
}
</ct>

==>  <ct>4546</ct>

-- get count of Resources with at least one ucd value of 'POS_EQ_RA'
<ct num="
{
  count(//vor:Resource[.//*:ucd &= "POS_EQ_RA"])
}
"/>

==>  <ct num="4070" />
========================================
and this is where it starts going wrong...

-- *try* to get list of unique UCDs with count of Resources containing at least one such value
<ucds>
{ 
for $t in distinct-values(//*:ucd)
order by $t
  return <ucd count="{ count(//vor:Resource[.//*:ucd &= '{$t}']) }">{$t}</ucd>
}
</ucds>

==> 
<ucds>
    <ucd count="0">?</ucd>
    <ucd count="0">AT_COLL_EXCIT-RATE</ucd>
    <ucd count="0">AT_COLL_STRENGTH</ucd> 
    ...
</ucds>

-- and again:
<ucds>
{ 
for $t in distinct-values(//*:ucd)
order by $t
  return <ucd count="{ count(//vor:Resource[.//*:ucd &= $t]) }">{$t}</ucd>
}
</ucds>

==>  
<ucds>
    <ucd count="0">?</ucd>
    <ucd count="0">AT_COLL_EXCIT-RATE</ucd>
    <ucd count="0">AT_COLL_STRENGTH</ucd>
    <ucd count="0">AT_CONFIG</ucd> 
    ...
</ucds>

-- and again:
<ucds>
{ 
for $t in distinct-values(//*:ucd)
order by $t
  return <ucd count="{ count(//vor:Resource[.//*:ucd/text() &= $t/text()]) }">{$t}</ucd>
}
</ucds>

==> failed

then logged the problem to the eXist-open list: http://sourceforge.net/mailarchive/message.php?msg_id=15071764 http://sourceforge.net/mailarchive/message.php?msg_id=15071768 http://sourceforge.net/mailarchive/message.php?msg_id=15071772 http://sourceforge.net/mailarchive/message.php?msg_id=15071776 http://sourceforge.net/mailarchive/message.php?msg_id=15071780

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
AstroGrid Service Click here for the
AstroGrid Service Web
This is the AstroGrid
Development Wiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback