Hello again,

I've also tried a variation with the parameter's type declared in the way 
described in the Java Bindings wiki page. Here is the code:

declare namespace Builder = 
"java:com.github.pemistahl.lingua.api.LanguageDetectorBuilder";
declare namespace Language = "java:com.github.pemistahl.lingua.api.Language";

Builder:fromLanguages*com.github.pemistahl.lingua.api.Language...(
  (
      Language:ENGLISH(),
      Language:DUTCH(),
      Language:GERMAN(),
      Language:SPANISH(),
      Language:FRENCH()
  )
)

But this still produces an error message:

[XPTY0004] 
com.github.pemistahl.lingua.api.LanguageDetectorBuilder:fromLanguages(com.github.pemistahl.lingua.api.Language[])
 expected, (List) found.

How should the parameter's list of values be written?

Thanks,
Vincent

_____________________________________________
Vincent M. Lizzi
Head of Information Standards | Taylor & Francis Group
vincent.li...@taylorandfrancis.com<mailto:vincent.li...@taylorandfrancis.com>



Information Classification: General
From: Lizzi, Vincent
Sent: Thursday, June 29, 2023 7:55 PM
To: BaseX <basex-talk@mailman.uni-konstanz.de>
Subject: Calling a Java function with varargs parameter from XQuery

Hello BaseX people,

The Java language bindings in BaseX look like a very good way to use Java 
libraries from XQuery. I'm currently trying to use Lingua 
(https://github.com/pemistahl/lingua) with BaseX, and mostly have it working, 
but I've not been able to figure out how to call a Java function that takes a 
vararg (variable arguments) parameter.

Here is a bit of XQuery code that shows the problem. I'm using BaseX version 
10.6 and the jar for Lingua version 1.2.2 has been added to the classpath. This 
query should return a LanguageDetectorBuilder object.


declare namespace Builder = 
"java:com.github.pemistahl.lingua.api.LanguageDetectorBuilder";
declare namespace Detector = 
"java:com.github.pemistahl.lingua.api.LanguageDetector";
declare namespace Language = "java:com.github.pemistahl.lingua.api.Language";

let $builder :=
  Builder:fromLanguages(
    [
      Language:ENGLISH(),
      Language:DUTCH(),
      Language:GERMAN(),
      Language:SPANISH(),
      Language:FRENCH()
    ]
  )
return $builder

The above code produces this error message in the BaseX GUI:

[XPTY0004] 
com.github.pemistahl.lingua.api.LanguageDetectorBuilder:fromLanguages(com.github.pemistahl.lingua.api.Language[])
 expected, (CArray) found.

If I try making the parameter a sequence instead of an array, replacing () 
parenthesis for the [] brackets, then this is the error message:

[XPTY0004] 
com.github.pemistahl.lingua.api.LanguageDetectorBuilder:fromLanguages(com.github.pemistahl.lingua.api.Language[])
 expected, (List) found.

I've read through the Java Bindings page in the wiki and tried to rewrite the 
parameter in different ways, but so far have only gotten different error 
messages.

The signature for the fromLanguages function can be seen at 
https://github.com/pemistahl/lingua/blob/main/src/main/kotlin/com/github/pemistahl/lingua/api/LanguageDetectorBuilder.kt#L165


Is there a way to make this work?

Thanks,
Vincent

______________________________________________
Vincent M. Lizzi
Head of Information Standards | Taylor & Francis Group
530 Walnut St., Suite 850, Philadelphia, PA 19106
E-Mail: 
vincent.li...@taylorandfrancis.com<mailto:vincent.li...@taylorandfrancis.com>
Web: www.tandfonline.com<http://www.tandfonline.com>

Taylor & Francis is a trading name of Informa UK Limited,
registered in England under no. 1072954

"Everything should be made as simple as possible, but not simpler."

Reply via email to