java binding passing variables
Tuesday, 11 April 2023 · 4 messages · last reply 12 Apr 2023
BQ
Burkhard Quessel11 Apr 2023 14:15 #
*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/bdrc/ewtsconverter/EwtsConverter.java
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
AB
Andy Bunce11 Apr 2023 20:54 #
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
Quoted text · Burkhard Quessel · 58 lines
On Tue, 11 Apr 2023 at 13:16, Burkhard Quessel <bquessel at 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/bdrc/ewtsconverter/EwtsConverter.java > > > > 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 > > >
BQ
Burkhard Quessel12 Apr 2023 10:41 #
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 for Windows
Quoted text · Andy Bunce · 47 lines
From: Andy Bunce Sent: 11 April 2023 19:54 To: Burkhard Quessel Cc: basex-talk at 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 at 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/bdrc/ewtsconverter/EwtsConverter.java > > 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
AB
Andy Bunce12 Apr 2023 11:38 #
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/bdrc/ewtsconverter/EwtsConverter.java#L1539 [2] https://docs.basex.org/wiki/Java_Bindings
Quoted text · Burkhard Quessel · 139 lines
On Wed, 12 Apr 2023 at 09:41, Burkhard Quessel <bquessel at 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 at gmail.com> > *Sent: *11 April 2023 19:54 > *To: *Burkhard Quessel <bquessel at gmail.com> > *Cc: *basex-talk at 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 at 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/bdrc/ewtsconverter/EwtsConverter.java > > > > 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 > > > > > >
Written for BaseX 10.5. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery