11xquery version "3.1" ;
22
3- module namespace ll = "http://exist-db.org/xquery /stanford-nlp/load-language " ;
3+ import module namespace config = "http://exist-db.org/apps /stanford-nlp/config " ;
44
55import module namespace http = "http://expath.org/ns/http-client" ;
66import module namespace compression = "http://exist-db.org/xquery/compression" ;
7- import module namespace console = "http://exist-db.org/xquery/console" ;
87import module namespace functx = "http://www.functx.com" ;
98import module namespace util = "http://exist-db.org/xquery/util" ;
109import module namespace map = "http://www.w3.org/2005/xpath-functions/map" ;
1110import module namespace xmldb = "http://exist-db.org/xquery/xmldb" ;
1211
13- declare function ll:mkcol-recursive ($collection, $components) {
12+
13+ declare variable $local:language external ;
14+
15+
16+ declare function local:mkcol-recursive ($collection, $components) {
1417 if (exists ($components)) then
1518 let $newColl := concat ($collection, "/" , $components[1 ])
1619 return (
17- if (xmldb:collection-available ($newColl))
18- then ()
20+ if (xmldb:collection-available ($newColl))
21+ then ()
1922 else xmldb:create-collection ($collection, $components[1 ]),
20- ll :mkcol-recursive ($newColl, subsequence ($components, 2 ))
23+ local :mkcol-recursive ($newColl, subsequence ($components, 2 ))
2124 )
2225 else
2326 ()
2427};
2528
26- declare function ll :mkcol ($collection, $path) {
27- ll :mkcol-recursive ($collection, tokenize ($path, "/" ))
29+ declare function local :mkcol ($collection, $path) {
30+ local :mkcol-recursive ($collection, tokenize ($path, "/" ))
2831};
2932
3033
31- declare function ll :entry-data ($path as xs:anyURI, $type as xs:string, $data as item ()?, $param as item ()*) as item ()?
34+ declare function local :entry-data ($path as xs:anyURI, $type as xs:string, $data as item ()?, $param as item ()*) as item ()?
3235{
3336 let $path-before := functx:substring-before-last ($path, "/" )
3437 let $resource-name := functx:substring-after-last ($path, "/" )
35- let $coll := ll :mkcol ("/db/apps/stanford-nlp/data" , $path-before)
38+ let $coll := local :mkcol ("/db/apps/stanford-nlp/data" , $path-before)
3639 let $decided :=
37- if (fn:ends-with ($resource-name, ".properties" ))
38- then
40+ if (fn:ends-with ($resource-name, ".properties" ))
41+ then
3942 let $nl := " "
4043 let $lines := fn:tokenize (util:binary-to-string ($data, "UTF-8" ), $nl)
4144 let $content := map:merge (
@@ -62,34 +65,51 @@ declare function ll:entry-data($path as xs:anyURI, $type as xs:string, $data as
6265 else ()
6366 )
6467 return xmldb:store (
65- "/db/apps/stanford-nlp/data/" || $path-before,
66- fn:replace ($resource-name, ".properties" , ".json" ),
68+ "/db/apps/stanford-nlp/data/" || $path-before,
69+ fn:replace ($resource-name, ".properties" , ".json" ),
6770 fn:serialize ($content, map { "method" : "json" , "indent" : true () })
68- )
71+ )
6972 else ()
7073 let $stored := xmldb:store-as-binary ("/db/apps/stanford-nlp/data/" || $path-before, $resource-name, $data)
71- let $log := console :log ("item path=[" || $path || "] type=[" || $type || "]" )
74+ let $log := local :log ("item path=[" || $path || "] type=[" || $type || "]" )
7275 return ()
73- };
76+ };
7477
75- declare function ll :entry-filter ($path as xs:anyURI, $type as xs:string, $param as item ()*) as xs:boolean
78+ declare function local :entry-filter ($path as xs:anyURI, $type as xs:string, $param as item ()*) as xs:boolean
7679{
7780 $type = "resource"
7881};
7982
80- declare function ll:process ($path as xs:string) {
81- let $log0 := console:log ($path)
82-
83+ declare function local:log ($message as xs:string)
84+ {
85+ update insert
86+ element { 'log' } {
87+ attribute { 'timestamp' } { util:system-dateTime () },
88+ attribute { 'language' } { $local:language },
89+ $message
90+ }
91+ into
92+ fn:doc ("/db/apps/stanford-nlp/data/log.xml" )//logs
93+ };
94+
95+ declare function local:process ($path as xs:string) {
96+ let $log0 := local:log ($path)
97+
8398 let $req := <http:request href = "{$path} " method = "get" />
84-
99+
85100 let $zip := http:send-request ($req)[2 ]
86- let $log := console :log (functx:atomic-type ($zip))
87-
101+ let $log := local :log (functx:atomic-type ($zip))
102+
88103 return compression:unzip (
89- $zip,
90- util:function (xs:QName ("ll :entry-filter" ), 3 ),
91- (),
92- util:function (xs:QName ("ll :entry-data" ), 4 ),
104+ $zip,
105+ util:function (xs:QName ("local :entry-filter" ), 3 ),
106+ (),
107+ util:function (xs:QName ("local :entry-data" ), 4 ),
93108 ()
94109 )
95110};
111+
112+ (local:log ("start" ),
113+ local:process ($config:corenlp-model-url || $local:language || ".jar" ),
114+ local:log ("end" )
115+ )
0 commit comments