From 09d8b4cdedc83dcc108d2ab3d2f5c3274e2fc13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Thu, 4 Oct 2018 15:53:21 +0200 Subject: [PATCH 1/4] add function to create aggregation --- modules/textgrid/client.xqm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/textgrid/client.xqm b/modules/textgrid/client.xqm index 7921fcb..7631c2c 100644 --- a/modules/textgrid/client.xqm +++ b/modules/textgrid/client.xqm @@ -19,6 +19,7 @@ declare namespace sparql-results="http://www.w3.org/2005/sparql-results#"; declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010"; declare namespace xhtml="http://www.w3.org/1999/xhtml"; + (: : Queries TextGrid RDF store. Mainly used to get URIs within a collection : @param $query - the SPARQL query as string @@ -92,8 +93,9 @@ declare function tgclient:remove-prefix($tguri as xs:string) as xs:string { : @result the resulting MetadataContainerType :) declare function tgclient:createData($config as map(*), $title, $format, $data) as node() { -let $sessionId := () -let $projectId := () +let $sessionId := $config("sid") +let $projectId := $config("pid") +let $tgcrudURL := $config("tgcrudURL") let $url := $tgcrudURL || "?sessionId=" || $sessionId || "&projectId=" || $projectId @@ -220,3 +222,23 @@ let $soapElement := local:soapElement("tgAssignedProjects", $sid, 0< return local:tgAuth-call($authUrl, $soapHeader, $soapElement) }; + +(:~ + : Creates an aggregation, either empty or filled with the provided textgrid-URIs + : @param $config – a map containing static parameters "pid", "sid" and "tgCrudUrl" + : @param $title – the name of the aggregation + : @param $uris – a sequence of textgrid URIs +:) +declare function tgclient:createAggregation($config as map(*), $title as xs:string, $uris as xs:string+) +as element(tgmd:MetadataContainerType) { +let $data := (: rdf:Description/@rdf:about will be set by the CRUD :) + document { + + + {for $uri in $uris + return } + + } +return + tgclient:createData($config, $title, "text/tg.aggregation+xml", $data) +}; -- GitLab From 4df2bdaccd8cc7314f8366d32350e5c32708db95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Mon, 15 Oct 2018 16:32:09 +0200 Subject: [PATCH 2/4] disable any URL path --- controller.xql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller.xql b/controller.xql index b246d25..34fe5e4 100644 --- a/controller.xql +++ b/controller.xql @@ -24,7 +24,7 @@ else if ($exist:path eq "/") then -else if (ends-with($exist:resource, ".html")) then +else if ( matches($exist:path, "/" || $project || "/" || $exist:resource) ) then (: the html page is run through view.xq to expand templates :) -- GitLab From b8fec199b272b60235ab3e0594a3f31251813c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Thu, 1 Nov 2018 16:08:56 +0100 Subject: [PATCH 3/4] add test, add documentation --- modules/textgrid/client.xqm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/textgrid/client.xqm b/modules/textgrid/client.xqm index 7631c2c..2b1aa98 100644 --- a/modules/textgrid/client.xqm +++ b/modules/textgrid/client.xqm @@ -16,10 +16,10 @@ declare namespace http="http://expath.org/ns/http-client"; declare namespace ore="http://www.openarchives.org/ore/terms/"; declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; declare namespace sparql-results="http://www.w3.org/2005/sparql-results#"; +declare namespace test="http://exist-db.org/xquery/xqsuite"; declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010"; declare namespace xhtml="http://www.w3.org/1999/xhtml"; - (: : Queries TextGrid RDF store. Mainly used to get URIs within a collection : @param $query - the SPARQL query as string @@ -67,10 +67,19 @@ declare function tgclient:getData($id as xs:string, $tgcrud-url as xs:string, $s }; -(:~ Returns a list of TextGrid items within a given aggregation - : @param tguri – the URI of any tg.aggregation :) -declare function tgclient:getAggregatedUris($tguri as xs:string, $rdfstore as xs:string) as item()* { - let $query := concat("PREFIX ore: PREFIX tg: SELECT ?s WHERE { <",$tguri,"> (ore:aggregates/tg:isBaseUriOf|ore:aggregates)* ?s. }") +(:~ Returns a list of TextGrid items within a given aggregation, but only the + latest revision of an object. + : @param tguri – the URI of any tg.aggregation + : @param rdfstore – url to the triple store + : @return sequence of strings (textgrid URIs) or empty sequence + :) +declare + %test:name("sqarql query") + %test:args("textgrid:vvcv.0", "https://textgridlab.org/1.0/triplestore/textgrid-public") + %test:assertXPath("count($result) eq 39") +function tgclient:getAggregatedUris($tguri as xs:string, $rdfstore as xs:string) +as xs:string* { + let $query := concat("PREFIX ore: PREFIX tg: SELECT ?s WHERE { <",$tguri,"> (ore:aggregates/tg:isBaseUriOf|ore:aggregates)* ?s. FILTER not exists { ?s tg:isDeleted true } . }") let $uris := tgclient:sparql($query, $rdfstore) (: let $uris := $uris//sparql-results:uri/string() :) for $uri in distinct-values( $uris//sparql-results:uri/substring-before(.,'.')) -- GitLab From 389373742a9e4e0a8b9257ae85fa6f1f3abfc258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Thu, 1 Nov 2018 16:18:52 +0100 Subject: [PATCH 4/4] improved tests --- modules/textgrid/client.xqm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/textgrid/client.xqm b/modules/textgrid/client.xqm index 2b1aa98..098a99e 100644 --- a/modules/textgrid/client.xqm +++ b/modules/textgrid/client.xqm @@ -75,8 +75,10 @@ declare function tgclient:getData($id as xs:string, $tgcrud-url as xs:string, $s :) declare %test:name("sqarql query") - %test:args("textgrid:vvcv.0", "https://textgridlab.org/1.0/triplestore/textgrid-public") - %test:assertXPath("count($result) eq 39") + %test:args("textgrid:vv6f.0", "https://textgridlab.org/1.0/triplestore/textgrid-public") + %test:assertExists + %test:assertEquals("textgrid:vv6f.0", "textgrid:vv6g.0", "textgrid:vvc3.0") + %test:assertXPath("count($result) eq 3") function tgclient:getAggregatedUris($tguri as xs:string, $rdfstore as xs:string) as xs:string* { let $query := concat("PREFIX ore: PREFIX tg: SELECT ?s WHERE { <",$tguri,"> (ore:aggregates/tg:isBaseUriOf|ore:aggregates)* ?s. FILTER not exists { ?s tg:isDeleted true } . }") -- GitLab