Changeset 691 for MDRepository
- Timestamp:
- 09/14/10 09:22:55 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDRepository/trunk/xquery/cmd-model.xqm
r681 r691 32 32 declare variable $cmd-model:xmlExt as xs:string := ".xml"; 33 33 34 declare variable $cmd-model:valuesLimit as xs:integer := 100; 35 36 37 34 38 declare function cmd-model:elem($collection as xs:string, $path as xs:string, $depth as xs:integer) as element() { 39 cmd-model:elem-r($collection, $path, $depth, $depth) 40 }; 41 42 declare function cmd-model:elem-r($collection as xs:string, $path as xs:string, $max-depth as xs:integer, $depth as xs:integer) as element() { 35 43 let $path-nodes := util:eval(fn:concat("collection('", $collection, "')//", $path)) 36 44 let $path-count := count($path-nodes) … … 43 51 <Term path="{fn:concat("//", $path)}" name="{text:groups($path, "/([^/]+)$")[last()]}" count="{$path-count}" count_text="{$text-count}" count_distinct_text="{$text-count-distinct}">{ 44 52 if ($depth > 0) then 45 for $elname in $subs[. != '']53 (for $elname in $subs[. != ''] 46 54 return 47 cmd-model:elem($collection, concat($path, '/', $elname), $depth - 1) 55 cmd-model:elem-r($collection, concat($path, '/', $elname), $max-depth, $depth - 1), 56 if ($max-depth eq 1) then cmd-model:values($path-nodes) else ()) 48 57 else 'maxdepth' 49 58 }</Term> 59 }; 60 61 declare function cmd-model:values($nodes as node()*) as node()* { 62 let $keys := distinct-values($nodes/text()) 63 for $key at $pos in $keys[if ($cmd-model:valuesLimit eq 0) then () else (1 to $cmd-model:valuesLimit)] 64 let $kcount := count($nodes[. eq $key]) 65 order by lower-case($key) ascending 66 return <v key="{$key}" cnt="{$kcount}" /> 50 67 }; 51 68 … … 78 95 Recurse for collections 79 96 :) 80 declare function cmd-model:recurse-collections($collection as node()+, $ parentas xs:string, $handle as xs:string, $proxy-id as xs:string, $depth as xs:integer) as item()* {97 declare function cmd-model:recurse-collections($collection as node()+, $name as xs:string, $handle as xs:string, $proxy-id as xs:string, $depth as xs:integer) as item()* { 81 98 let $children := if ($depth eq 0) then () else $collection//ResourceProxy[ResourceType = "Metadata"] 82 99 return … … 86 103 let $child-doc := if (empty($child/unresolvable-uri)) then 87 104 cmd-model:get-resource-by-handle-or-collection-path(util:collection-name($child/root()), $child/ResourceRef) else (), 88 $child-name := ($child-doc//Corpus/Name, $child-doc//Session/Name, $child-doc//Collection/GeneralInfo/Name, "UNKNOWN")[1]105 $child-name := if (empty($child-doc)) then concat(util:collection-name($child/root()), ":", $child/ResourceRef) else cmd-model:get-md-collection-name($child-doc) 89 106 return 90 if (empty($child-doc)) then () (:<no-target proxy-id="{$child/@id}">{<proxy>{$child}</proxy>, <in-document>{concat(util:collection-name($child/root()), "/", util:document-name($child/root()))}</in-document>}</no-target> :)107 if (empty($child-doc)) then () 91 108 else 92 109 cmd-model:recurse-collections($child-doc, $child-name, $child-doc//Header/MdSelfLink, $child/@id, $depth - 1) 93 110 return 94 <c n="{$ parent}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="-1" sub-colls="{count($child-results)}" >{$child-results}</c>111 <c n="{$name}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="-1" sub-colls="{count($child-results)}" >{$child-results}</c> 95 112 else 96 <c n="{$parent}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="{count(collection(concat(util:collection-name($collection/CMD[1]/root()), "/../"))//CMD[not(//ResourceType[. = "Metadata"])])}"></c> 113 <c n="{$name}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="{if ($handle eq "") then "-1" else cmd-model:get-resource-count($handle)}"></c> 114 115 }; 116 117 (: 118 :) 119 declare function cmd-model:get-resource-count($handle as xs:string) as xs:string { 120 count(collection($cmd-model:cmdiMirrorPath)//IsPartOf[. eq $handle]/ancestor::CMD[descendant::ResourceType[. = "Resource"]]) 121 }; 122 123 (: 124 :) 125 declare function cmd-model:get-md-collection-name($collection-doc as node()) as xs:string { 126 ($collection-doc//Corpus/Name, $collection-doc//Session/Name, $collection-doc//Collection/GeneralInfo/Name, $collection-doc//Collection/GeneralInfo/Title, "UNKNOWN")[1] 97 127 }; 98 128 … … 171 201 $coll-count := update value $stored-doc/Collections/@count with sum($stored-doc//c[not(c)]/@cnt) 172 202 return 173 for $i in $stored-doc//c[c] 203 for $i in $stored-doc//c[c][@cnt eq "-1"] 174 204 return update value $i/@cnt with sum($i//c[not(c)]/@cnt) 175 205 … … 237 267 :) 238 268 declare function cmd-model:get-resource-by-handle-or-collection-path($id as xs:string, $doc-name as xs:string?) as node()* { 239 if (starts-with($id, "test-") or starts-with($id, "clarin .at") or starts-with($doc-name, "clarin.at")) then269 if (starts-with($id, "test-") or starts-with($id, "clarin-") or starts-with($doc-name, "clarin-")) then 240 270 collection($cmd-model:cmdiMirrorPath)//MdSelfLink[. = xdb:decode(($doc-name, $id)[1])]/ancestor::CMD 271 (: let $key := xdb:decode(($doc-name, $id)[1]) 272 return ft:query(//MdSelfLink, <term>{$key}</term>)[matches(., concat("^", $key, "$"))]/ancestor::CMD :) 241 273 else if (empty($doc-name)) then 242 274 collection($id)//IsPartOf[. = "root"]/ancestor::CMD … … 278 310 return 279 311 for $collection-doc in cmd-model:get-resource-by-handle-or-collection-path($collection-item, ()) return 280 cmd-model:recurse-collections($collection-doc, ($collection-doc//Corpus/Name, $collection-doc//Session/Name, "UNKNOWN")[1], $collection-doc//MdSelfLink, "", $max-depth)312 cmd-model:recurse-collections($collection-doc, cmd-model:get-md-collection-name($collection-doc), $collection-doc//MdSelfLink, "", $max-depth) 281 313 return 282 314 cmd-model:store-collection-data(<Collections count="-1" sub-colls="{count($children)}" root="{$collections}">{$children}</Collections>, $names[1], $names[2])
Note: See TracChangeset
for help on using the changeset viewer.