synonyms() error in wordnet - java

I want to use synonyms () described in 'Intro to the tm package' for R. It uses the wordnet package. The wordnet package downloaded from CRAN does not have Dict (dictionary) in its directory. I downloaded it from the Princeton site and copied it over to the directory. After using sys.setenv() and setDict() for setting paths, I still get this error:
Error in sort(unique(unlist(lapply(synsets, getWord))))
error in evaluating the argument 'x' in selecting a method for function 'sort': Error in unique(unlist(lapply(synsets, getWord))) :
error in evaluating the argument 'x' in selecting a method for function 'unique': Error in .jcall(synset, "Ljava/util/List;", "getWord") :
java.lang.NumberFormatException: For input string: "t"
when I try synonyms("company", pos = "NOUN") or another English word in place of 'company'. The problem is in getSynonyms() called from synonyms(). Any idea on how to fix this problem?
Different combinations lead to different input string NumberFormatException. My Java is version 1.8. I tried all the online resources. I added two paths to PATH for R's bin and RJava's jri. Discussion on the exception indicates it is a string to numeric conversion issue. I have made sure that Java to R linkage (via rJava) works (URL: https://www.rforge.net/rJava/ ).

Related

Standard Method TEXT is undefined when compiling jasper report

When I package my stand-alone-java-application, that compiles, renders and prints Jasper-Reports, in a fat jar with all dependencies, I get the error that the function TEXT – a function used in the report and defined in the net.sf.jasperreports-functions-library is not found.
The method TEXT(Integer, String) is undefined for the type [...]
value = IF(LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#"))==2,"***",REPT("*",6-LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#")))) //$JR_EXPR_ID=58$
Other functions from the same library work. When I run the application with gradle run, the function is found and the report can be printed. The library is on my classpath.
There are several similar questions on this site and Stackoverflow, but neither provided answers, that worked for me. In the following, I will explain what I tried:
In my build.gradle-File I defined dependencies to the following libraries:
implementation('net.sf.jasperreports:jasperreports:6.18.1')
implementation('net.sf.jasperreports:jasperreports-functions:6.18.1')
In my java-Files, I created a DesignFile and statically imported the functions into it. I tried two methods:
Method 1 as given in an answer in this thread: Unresolved symbols when compiling jasper report
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.MathFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.DateTimeFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.LogicalFunctions.*");
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
Method 2: importing each function on its own
public static String[] textFunctions(){
return new String[]{"BASE", "CHAR", "CLEAN", "CODE", "CONCATENATE", "DOUBLE_VALUE",
"EXACT", "FIND", /*"FIXED", */"FLOAT_VALUE", "INTEGER_VALUE", "LEFT", "LEN", "LONG_VALUE",
"LOWER", "LTRIM", "MID", "PROPER", "REPLACE", "REPT", "RIGHT", "RTRIM", "SEARCH", "SUBSTITUTE",
"T", /*"TEXT",*/ "TRIM", "UPPER"};
}}
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
for (String textFunction : textFunctions()){
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions." + textFunction);
}/* similarly for logical functions, numeric functions and datetime functions*/
}
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
As you can see, the function TEXT is commented out. That’s because the program fails at runtime when run with “gradle run”, when I comment it in:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The import net.sf.jasperreports.functions.standard.TextFunctions.TEXT cannot be resolved
import static net.sf.jasperreports.functions.standard.TextFunctions.TEXT;
The same thing is true with most datetime-functions, in fact, only TIME can be imported to the DesignObject without error at runtime
In addition to that, when I type net.sf.jasperreports.functions.standard.TextFunctions. in my IDE, the content-assist shows a list of available functions, yet TEXT is missing.
I suspected, that the function is simply missing in the library, but it is there. In the .gradle/cache/modules-2/files-2.1/… directory, there is the jar with the TextFunctions.java, that contains the function TEXT:
When building the FatJar with dependencies, I have a TextFunctions.class-File in it, that contains the TEXT-Function as well.
In my jar, there are two jasperreports_extension.properties on the root level:
with the smaller one (from the jasperreport-functions-dependency) containing the following lines:
net.sf.jasperreports.extension.registry.factory.functions=net.sf.jasperreports.functions.FunctionsRegistryFactory
net.sf.jasperreports.extension.functions.datetime=net.sf.jasperreports.functions.standard.DateTimeFunctions
net.sf.jasperreports.extension.functions.math=net.sf.jasperreports.functions.standard.MathFunctions, net.sf.jasperreports.functions.standard.LogicalFunctions
net.sf.jasperreports.extension.functions.text=net.sf.jasperreports.functions.standard.TextFunctions
net.sf.jasperreports.extension.functions.report=net.sf.jasperreports.functions.standard.ReportFunctions
Funnily enough, commenting out TEXT, running it locally with gradle run, it works without problems. But packaging it and running it with java -jar it fails to find this function. And statically importing this function leads to gradle run failing as well.
What is happening and how can I fix this? I want to distribute my FatJar on a server and run it, but this problems makes it impossible for me.

Why is ANTLR not printing set of tokens correctly?

I am testing to see if ANTLR-4.7.1 is working properly by using a sample, provided by my professor, to match these results for the same printed set of tokens:
% java -jar ./antlr-4.7.1-complete.jar HelloExample.g4
% javac -cp antlr-4.7.1-complete.jar HelloExample*.java
% java -cp .:antlr-4.7.1-complete.jar org.antlr.v4.gui.TestRig HelloExample greeting helloworld.greeting -tokens
[#0,0:4='Hello',<1>,1:0]
[#1,6:10='World',<3>,1:6]
[#2,12:12='!',<2>,1:12]
[#3,14:13='<EOF>',<-1>,2:0]
(greeting Hello World !)
However, after getting to the 3rd command, my output was instead:
[#0,0:4='Hello',<'Hello'>,1:0]
[#1,6:10='World',<Name>,1:6]
[#2,12:12='!',<'!'>,1:12]
[#3,13:12='<EOF>',<EOF>,1:13]
In my output, there are no numbers inside < >, which I believe should be defined from the HelloExample.tokens file that contain:
Hello=1
Bang=2
Name=3
WS=4
'Hello'=1
'!'=2
I get no error information and antlr seemed to have generated all the files I needed, so I don't know where I should be looking to resolve this, please help. And I'm not sure if it'll be of use, but my working directory started with helloworld.greeting and HelloExample.g4 and final directory now contains
helloworld.greeting
HelloExample.g4
HelloExample.interp
HelloExample.tokens
HelloExampleBaseListener.class
HelloExampleBaseListener.java
HelloExampleLexer.class
HelloExampleLexer.inerp
HelloExampleLexer.java
HelloExampleLexer.tokens
HelloExampleListener.class
HelloExampleListener.java
HelloExampleParser$GreetingContext.class
HelloExampleParser.class
HelloExampleParser.java
As rici already pointed out in the comments, getting the actual rule names instead of their numbers in the token output is a feature and shouldn't worry you.
In order to get the (greeting Hello World !) output at the end, you'll want to add the -tree flag after -tokens.

Alternative for AnyLogic deprecated method getJComponent()?

I recently updated to AnyLogic PLE 8.4.0 and Java SE 12 on my Windows 10 laptop. And now an AnyLogic model that used to work earlier stops with the error "The method getJComponent() is undefined for the type ShapeTextField." I looked it up in AnyLogic/Help and I notice that getJComponent is identified as "Deprecated" and no alternative is identified. It appears to me that some mismatch happened between AnyLogic and Java updates that resulted in this error. I would appreciate any workarounds to get the model working.
Tried replacing getJComponent() with the following:
by getX() - gave error "cannot cast from double to Jtextfield"
by getPresentable() - gave error "cannot cast from Presentable to Jtextfield"
by getClass() - gave error "Description: Cannot cast from Class to JTextField."
by getComponentGraphics() - gave error "Description: The method getComponentGraphics() is undefined for the type ShapeTextField."
by equals - gave error "Description: The method equals(Object) in the type Object is not applicable for the arguments ()."
The code is:
((JTextField)(editbox.getJComponent())).setHorizontalAlignment(JTextField.LEFT);
This is defined in Simulation - Simulation Experiment / Java Actions/ Initial Experiment Setup field
Expected result: No error message. And the model should proceed to run window.
Thanks to the inputs from #Benjamin and #Felipe the following worked:
I replaced the editbox and buttons with corresponding artifacts from
AL8.4 palette. I copied the code from the earlier artifacts to
corresponding fields in the new artifacts. I deleted the artifacts
that were from AL7.
I commented out the line that was meant to align the editbox since
that capability is not available anymore.
With the above two changes I didn't get the error message about undefined method. The editbox and buttons worked and allowed me to enter XML filename and reading it with an XML parser routine. I have now run into issue with JAXB integration with AL8.4 and haven't been able to get past that yet. I will be posting that as a separate question.

Problems generating '.pas' file with Java2OP and compiling it

I have 2 JAR files coming from an SDK that I have to use.
Generation problem
I succeeded in generating the first .pas file, but Java2OP fails to generate the second .pas I need, with the message
Access violation at address 0042AF4A dans the 'Java2OP.exe' module. Read at address 09D00000
Would this come from a common issue? There's no other hints about what causes the problem in the SDK .jar.
I'm using Java2OP located in C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\converters\java2op, but I had to first use the solutions in Delphi 10.1 Berlin - Java2OP: class or interface expected before generating the 1st file.
Compilation problem
Anyway, I tried to generate a .hpp file from the generated .pas.
I don't know much about Delphi. Does the problem come from the SDK itself, or the generation of the .pas file?
1st issue solved
Java2OP included Androidapi.JNI.Java.Util
and not Androidapi.JNI.JavaUtil. I had to import Androidapi.JNI.JavaUtil myself, though it is present in the /Program Files(x86)/Embarcadero/... folders.
2nd issue
The same 4 compilation errors happen multiple times across the .pas file on parts using the word this.
Do I have to replace every use of this with self?
Errors
E2023 The function require a type of result : Line 4
E2147 The property 'this' doesn't exist in the base class : Line 5
E2029 ',' or ':' awaited but found 'read' identificator : Line 5
E2029 ',' or ':' awaited but found number : Line 5
[JavaSignature('com/hsm/barcode/DecoderConfigValues$SymbologyFlags')]
JDecoderConfigValues_SymbologyFlags = interface(JObject)
['{BCF30FD2-B650-433C-8A4E-8B638A508487}']
function _Getthis$0: JDecoderConfigValues; cdecl;
property this$0: JDecoderConfigValues read _Getthis$0;
end;
[JavaSignature('com/hsm/barcode/ExposureValues$ExposureSettingsMinMax')]
JExposureValues_ExposureSettingsMinMax = interface(JObject)
['{A576F85F-A021-475C-9741-06D92DBC205F}']
function _Getthis$0: JExposureValues; cdecl;
property this$0: JExposureValues read _Getthis$0;
end;

Run an ABCL code that uses cl-cppre

With reference to my previous question,
Executing a lisp function from Java
I was able to call lisp code from Java using ABCL.
But the problem is, the already existing lisp code uses CL-PPCRE package.
I can not compile the code as it says 'CL-PPCRE not found'.
I have tried different approaches to add that package,
including
1) how does one compile a clisp program which uses cl-ppcre?
2)https://groups.google.com/forum/#!topic/cl-ppcre/juSfOhEDa1k
Doesnot work!
Other thing is, that executing (compile-file aima.asd) works perfectly fine although it does also require cl-pprce
(defpackage #:aima-asd
(:use :cl :asdf))
(in-package :aima-asd)
(defsystem aima
:name "aima"
:version "0.1"
:components ((:file "defpackage")
(:file "main" :depends-on ("defpackage")))
:depends-on (:cl-ppcre))
The final java code is
interpreter.eval("(load \"aima/asdf.lisp\")");
interpreter.eval("(compile-file \"aima/aima.asd\")");
interpreter.eval("(compile-file \"aima/defpackage.lisp\")");
interpreter.eval("(in-package :aima)");
interpreter.eval("(load \"aima/aima.lisp\")");
interpreter.eval("(aima-load 'all)");
The error message is
Error loading C:/Users/Administrator.NUIG-1Z7HN12/workspace/aima/probability/domains/edit-nets.lisp at line 376 (offset 16389)
#<THREAD "main" {3A188AF2}>: Debugger invoked on condition of type READER-ERROR
The package "CL-PPCRE" can't be found.
[1] AIMA(1):
Can anyone help me?
You need to load cl-ppcre before you can use it. You can do that by using (asdf:load-system :aima), provided that you put both aima and cl-ppcre into locations that your ASDF searches.
I used QuickLisp to add cl-ppcre (because nothing else worked for me).
Here is what I did
(load \"~/QuickLisp.lisp\")")
(quicklisp-quickstart:install)
(load "~/quicklisp/setup.lisp")
(ql:quickload :cl-ppcre)
First 2 lines are only a one time things. Once quickLisp is installed you can start from line 3.

Categories

Resources