@@ -2,14 +2,14 @@ xquery version "3.0";
22
33(:~
44 : This modules contains functions to query Simbad through TAP.
5- :
5+ :
66 : It provides helpers to perform target resolutions (by name and by
77 : coordinates) against Simbad's basic table.
8- :
8+ :
99 : TODO handle equinox of the coordinates / epoch
1010 : History:
11- : August 2017 :
12- : - use votable/td for TAP queries (so we parse some tr/td result nodes)
11+ : August 2017 :
12+ : - use votable/td for TAP queries (so we parse some tr/td result nodes)
1313 : - bump to V1.3 namespace
1414 :)
1515module namespace jmmc-simbad="http://exist.jmmc.fr/jmmc-resources/simbad" ;
@@ -26,7 +26,7 @@ declare variable $jmmc-simbad:vot-ns := namespace-uri(element votable:dummy {});
2626(:~
2727 : Execute an ADQL query against a TAP service.
2828 :
29- : Warning: CDS set a query limit for the TAP service of max 6 requests per second.
29+ : Warning: CDS set a query limit for the TAP service of max 6 requests per second.
3030 : 403 error code is returned when limit is encountered.
3131 :
3232 : @param $uri the URI of a TAP sync resource
@@ -38,13 +38,13 @@ declare %private function jmmc-simbad:tap-adql-query($uri as xs:string, $query a
3838 let $uri := $uri || '?' || string-join ((
3939 'REQUEST=doQuery' ,
4040 'LANG=ADQL' ,
41- 'FORMAT=votable/td' ,
41+ 'FORMAT=votable/td' ,
4242 'QUERY=' || encode-for-uri ($query)), '& ' )
4343 let $response := http:send-request (<http:request method = "GET" href = "{$uri} " />)
44- let $response-status := $response[1 ]/@status
45-
44+ let $response-status := $response[1 ]/@status
45+
4646 return if ($response-status != 200 ) then
47- error (xs:QName ('jmmc-simbad:TAP' ), 'Failed to retrieve data (HTTP_STATUS=' || $response-status ||', query=' ||$query||')' , $query)
47+ error (xs:QName ('jmmc-simbad:TAP' ), 'Failed to retrieve data (HTTP_STATUS=' || $response-status ||', query=' ||$query||')' , $query)
4848 else if (count ($response[1 ]/http:body) != 1 ) then
4949 error (xs:QName ('jmmc-simbad:TAP' ), 'Bad content returned' )
5050 else
@@ -54,12 +54,12 @@ declare %private function jmmc-simbad:tap-adql-query($uri as xs:string, $query a
5454
5555(:~
5656 : Return a target description from the VOTable row.
57- :
57+ :
5858 : The description is made from the oid, ra and dec coordinates and the main
5959 : name.
60- :
60+ :
6161 : @param $row a VOTable row
62- : @return a target description as sequence
62+ : @return a target description as sequence
6363 :)
6464declare %private function jmmc-simbad:target ($row as element (votable:TR)) as element (target) {
6565 <target> {
@@ -72,7 +72,7 @@ declare %private function jmmc-simbad:target($row as element(votable:TR)) as ele
7272
7373(:~
7474 : Run a target resolution ADQL query against Simbad TAP service and return the rows of results.
75- :
75+ :
7676 : @param $query the ADQL query to execute
7777 : @return target descriptions if resolution succeeds
7878 : @error not found, off coord hit
@@ -88,7 +88,7 @@ declare %private function jmmc-simbad:resolve($query as xs:string) as node()* {
8888
8989(:~
9090 : Escape a string for ADQL query.
91- :
91+ :
9292 : @param $str the string to escape
9393 : @return the escaped string
9494 :)
@@ -99,7 +99,7 @@ declare %private function jmmc-simbad:escape($str as xs:string) as xs:string {
9999
100100(:~
101101 : Try to identify a target from its name with Simbad.
102- :
102+ :
103103 : @param $identifier the target name
104104 : @return a target identifier if target is found or a falsy if target is unknown
105105 :)
@@ -109,15 +109,15 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string) as item()
109109
110110(:~
111111 : Try to identify a target from its fingerprint with Simbad.
112- :
112+ :
113113 : @param $identifier the target name
114114 : @param $ra the target right ascension in degrees
115115 : @param $dec the target declination in degrees
116116 : @return a target identifier if target is found or a falsy if target is unknown
117117 :)
118118declare function jmmc-simbad:resolve-by-name ($identifier as xs:string, $ra as xs:double?, $dec as xs:double?) as item ()* {
119119 let $do-dist := ($ra and $dec)
120- let $query :=
120+ let $query :=
121121 "SELECT oid AS id, ra, dec, main_id AS name, pmra, pmdec " || (if ($do-dist) then ", DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " else " " ) ||
122122 "FROM basic JOIN ident ON oidref=oid " ||
123123 "WHERE id = '" || jmmc-simbad:escape ($identifier) || "' " ||
@@ -128,15 +128,15 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string, $ra as xs
128128
129129(:~
130130 : Search for targets in the vicinity of given coords.
131- :
131+ :
132132 : @param $ra a right ascension in degrees
133133 : @param $dec a declination in degrees
134134 : @param $radius the search radius in degrees
135135 : @return a sequence of identifiers for targets near the coords (sorted by distance)
136136 :)
137137declare function jmmc-simbad:resolve-by-coords ($ra as xs:double, $dec as xs:double, $radius as xs:double) as item ()* {
138138 jmmc-simbad:resolve (
139- "SELECT oid AS id, ra, dec, main_id AS name, DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist , pmra, pmdec" ||
139+ "SELECT oid AS id, ra, dec, main_id AS name, DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist , pmra, pmdec " ||
140140 "FROM basic " ||
141141 "WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', " || $ra || ", " || $dec || ", " || $radius || " )) = 1 " ||
142142 "ORDER BY dist" )
@@ -147,16 +147,16 @@ declare function jmmc-simbad:resolve-by-coords($ra as xs:double, $dec as xs:doub
147147 : Search for target names that match alias of given name.
148148 : @param $identifier the target name (case insensitive)
149149 : @param $max-items max number of returned elements (optional - default value 10)
150- :
150+ :
151151 : @return a sequence of identifiers for targets which contains given identifier value (NAME part is removed)
152152 :)
153153declare function jmmc-simbad:search-names ($identifier as xs:string, $max-items as xs:integer? ) as item ()* {
154- let $max-items := if ($max-items) then $max-items else 10
154+ let $max-items := if ($max-items) then $max-items else 10
155155 let $query := "SELECT TOP " || $max-items || " id FROM ident AS id1 WHERE uppercase(id1.id) LIKE 'NAME %" || upper-case ($identifier) || "%'"
156156 (: TODO avoid identifier in return :)
157157 let $result := jmmc-simbad:tap-adql-query ($jmmc-simbad:TAP-SYNC, $query)
158158 let $resource := $result//votable:RESOURCE
159159 let $rows := $resource//votable:TR
160160 let $test-ns := if (empty ($rows) and empty ($result//votable:VOTABLE)) then error (xs:QName ('jmmc-simbad:TAP' ), 'Missing VOTABLE in response (namespace is ' || namespace-uri ($result/*)||' and should be ' || $jmmc-simbad:vot-ns ||')' ) else ()
161- return for $r in $rows return substring (normalize-space ($r),6 )
161+ return for $r in $rows return substring (normalize-space ($r),6 )
162162};
0 commit comments