*Subject:* java binding passing variables
I am trying to use xquery to transform Tibetan which is presented in Roman script to Unicode, i.e. into original Tibetan script. For this I use existing java code from here:
https://github.com/buda-base/ewts-converter/blob/master/src/main/java/io/bdr...
I add the jar of this code ( https://jar-download.com/artifact-search/ewts-converter) to my basex library and import like this:
import module namespace bdrc = "io.bdrc.ewtsconverter.EwtsConverter";
I can then use a java method to convert my Romanised Tibetan text to Unicode Original Tibetan script like so:
let $roman := "bkra shis bde legs"
return
bdrc:toUnicode($roman)
so far it works perfectly:
བཀྲ་ཤིས་བདེ་ལེགས
My problems begin when I try to add additional parameters to the conversion.
The java documentation lists a number of possible parameters:
*toUnicode(String str, List<String> warns, boolean sloppy, boolean lenient)*
(I want the “warns” one) but I am just too stupid to figure out how exactly to include this in in my xquery code. Can anyone help out?
Thanks Burkhard
Hi Burkhard,
The thing about the warn argument is that it can be updated by the Java call. So I think you will need to pass in a suitable Java object. For this case I tried an ArrayList
import module namespace bdrc = "io.bdrc.ewtsconverter.EwtsConverter"; let $warn:=Q{java.util.ArrayList}new() let $roman := "bk ra shise bde legs" let $result:=bdrc:toUnicode($roman,$warn,true(),false()) return map{"result": $result, "warn": Q{java.util.ArrayList}toString($warn) }
Results in map { "warn": "[line 1: ""bk"": Expected vowel after ""k"".]", "result": "བཀ་ར་ཤིསེ་བདེ་ལེགས" }
I don't know if this is right or not. There are better ways to pick apart $warn.
/Andy
On Tue, 11 Apr 2023 at 13:16, Burkhard Quessel bquessel@gmail.com wrote:
*Subject:* java binding passing variables
I am trying to use xquery to transform Tibetan which is presented in Roman script to Unicode, i.e. into original Tibetan script. For this I use existing java code from here:
https://github.com/buda-base/ewts-converter/blob/master/src/main/java/io/bdr...
I add the jar of this code ( https://jar-download.com/artifact-search/ewts-converter) to my basex library and import like this:
import module namespace bdrc = "io.bdrc.ewtsconverter.EwtsConverter";
I can then use a java method to convert my Romanised Tibetan text to Unicode Original Tibetan script like so:
let $roman := "bkra shis bde legs"
return
bdrc:toUnicode($roman)
so far it works perfectly:
བཀྲ་ཤིས་བདེ་ལེགས
My problems begin when I try to add additional parameters to the conversion.
The java documentation lists a number of possible parameters:
*toUnicode(String str, List<String> warns, boolean sloppy, boolean lenient)*
(I want the “warns” one) but I am just too stupid to figure out how exactly to include this in in my xquery code. Can anyone help out?
Thanks Burkhard
Glad it works for you. Regarding the 4 arguments I think this is a version thing. I downloaded v1.6 which can take 1, 3 or 4 arguments [1]
public String https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html?is-external=true toUnicode(String https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html?is-external=true str, List https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html?is-external=true<String https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html?is-external=true> warns, boolean sloppy, boolean lenient)
Below is a slightly cleaner version of the code. The BaseX wiki has a lot of good information on Java bindings [2]
import module namespace bdrc = "java:io.bdrc.ewtsconverter.EwtsConverter"; declare namespace list = "java:java.util.ArrayList";
let $roman := "bk ra shi se bde hh legs"
let $warns:=list:new() let $result:=bdrc:toUnicode($roman,$warns,false()) let $warns:=list:toArray($warns ) return map{"result": $result, "warn": $warns }
/Andy
[1] https://github.com/buda-base/ewts-converter/blob/master/src/main/java/io/bdr... [2] https://docs.basex.org/wiki/Java_Bindings
On Wed, 12 Apr 2023 at 09:41, Burkhard Quessel bquessel@gmail.com wrote:
Hi Andy,
When I tried to run the code, Basex complained about the 3rd argument in bdrc:toUnicode($roman,$warn,true(),false()) “4 arguments supplied, 1 or 3 expected”
With the 3rd argument removed it works a treat and is going to save me a lot of time. I have thousands of records to check and your reply really saved my bacon.
Thank you ever so much,
Burkhard
Sent from Mail https://go.microsoft.com/fwlink/?LinkId=550986 for Windows
*From: *Andy Bunce bunce.andy@gmail.com *Sent: *11 April 2023 19:54 *To: *Burkhard Quessel bquessel@gmail.com *Cc: *basex-talk@mailman.uni-konstanz.de *Subject: *Re: [basex-talk] Fwd: FW: java binding passing variables
Hi Burkhard,
The thing about the warn argument is that it can be updated by the Java call. So I think you will need to pass in a suitable Java object.
For this case I tried an ArrayList
import module namespace bdrc = "io.bdrc.ewtsconverter.EwtsConverter"; let $warn:=Q{java.util.ArrayList}new() let $roman := "bk ra shise bde legs" let $result:=bdrc:toUnicode($roman,$warn,true(),false()) return map{"result": $result, "warn": Q{java.util.ArrayList}toString($warn) }
Results in
map { "warn": "[line 1: ""bk"": Expected vowel after ""k"".]", "result": "བཀ་ར་ཤིསེ་བདེ་ལེགས" }
I don't know if this is right or not. There are better ways to pick apart $warn.
/Andy
On Tue, 11 Apr 2023 at 13:16, Burkhard Quessel bquessel@gmail.com wrote:
*Subject:* java binding passing variables
I am trying to use xquery to transform Tibetan which is presented in Roman script to Unicode, i.e. into original Tibetan script. For this I use existing java code from here:
https://github.com/buda-base/ewts-converter/blob/master/src/main/java/io/bdr...
I add the jar of this code ( https://jar-download.com/artifact-search/ewts-converter) to my basex library and import like this:
import module namespace bdrc = "io.bdrc.ewtsconverter.EwtsConverter";
I can then use a java method to convert my Romanised Tibetan text to Unicode Original Tibetan script like so:
let $roman := "bkra shis bde legs"
return
bdrc:toUnicode($roman)
so far it works perfectly:
བཀྲ་ཤིས་བདེ་ལེགས
My problems begin when I try to add additional parameters to the conversion.
The java documentation lists a number of possible parameters:
*toUnicode(String str, List<String> warns, boolean sloppy, boolean lenient)*
(I want the “warns” one) but I am just too stupid to figure out how exactly to include this in in my xquery code. Can anyone help out?
Thanks Burkhard
basex-talk@mailman.uni-konstanz.de