Kenlm language model scoring with Java on Windows - java

I'm mid-way through a Java project using a '.arpa' file to extract n-gram probabilities.
Ideally I would like to use a '.klm' file (created using the '.arpa' file), similar to:
model = kenlm.LanguageModel('languageModel.klm')
model.score('The dog chased the ball.')
however kenlm for Java isn't supported on windows.
Does anyone know of any alternatives to score sentences?
Thanks.

Resolved by just using a virtual machine to run the project using kenlm

Related

Using a python Project in java

I am using java in order to build a linguistic System for arabic language and i need to use an open source project as a black box inside my System the only problem is that the open source System is in Python so my question how could i use this System in java,
so that i could make this function
String output=applyPythonSystem(String input);
And please don't say Jython (Without explaining How??) i tried to use it but i couldn't find a way to do this function

Create Windows Symbolic Link with Java (equivalent to MKLINK)

Could anyone please tell me how to make a symbolic link (in the same way MKLINK does) and/or remove a symbolic link with Java. I have found solutions that use Java as a wrapper and use a Windows native program to accomplish this, but I really want a pure Java solution. Thank you in advance!
Since Java 7 you can do this easily using the NIO package.
Path target = Paths.get("target");
Path link = Paths.get("link");
Files.createDirectory(target);
Files.createSymbolicLink(link, target);
Do remember that you do need the correct privileges for this. In my unit test I had to run eclipse as an administrator to make it work (same as that I couldn't create a link from a normal cmd.exe)
As far as I know window does not have real symbolic links like Unix-like system do.
However Windows has the following relevant tools:
You can map network drive, i.e. attach drive letter to specified network path. You can definitely do this using WMI. To access WMI from java take a look on tools like JaWin, Jinterop, Jintegra or write WMI script in JScript o VBScript and execute is from Java.
You can use command subst that assigns letter to local file system path. This is the closest approach to Unix soft link.
You can create desktop shortcut. Create one manually and take a look on it. Shortcut is actually regular text file (as far as I remember in INI format). You can easily create one using any language you want including java. This is not soft link but it is clickable.

how to run svm light in java eclipse?

I have downloaded the JNI_SVM-light-6.01-64bit version for running svm in Java. I have tried searching online but did not exactly figure out the steps to run the library using eclipse IDE for java. All I want to do is know how to provide an input training file to train the model, and give a test file so that I get the corresponding results? A step by step instruction to do it using eclipse IDE would be very helpful.
Another way to run SVMLight from Java code in Eclipse is by using ClearTK. This allows for a standardized way to provide data to and get results from not only SVMLight, but also other models such as CRF.
Hey did you check out the test file? I'm trying it out now myself after importing the library by going to build path > Add External Archives.
You can find the test file here:
http://www.mpi-inf.mpg.de/~mtb/svmlight/JNI_SVMLight_Test.java
In the file it creates a random dataset, trains it, calculates the accuracy.. so it's basically giving you the standard operations that you will need.

java classpath error using LibSVM programmatically within Weka

I'm trying to use LibSVM programmatically in Java, via the Weka wrapper written by El-Manzalawy, running on Windows 7. I've added C:\Program Files (x86)\libsvm-3.12\java\libsvm.jar to my CLASSPATH environmental variable. After adding that I can now use LibSVM via the Weka explorer user interface, but it still fails when I'm calling it in code (debugging in eclipse).
I try to create it using Weka.core.Utils.forName. This goes through to LibSVM.java which then calls the java method Class.forName(...), passing CLASS_SVM as the param which is set to "libsvm.svm".
I've used Weka.core.Utils.forName to create others classifiers programmatically without problems.
Anyone have any ideas?
You should be able to glue libsvm and weka in your java program using the answer posted here: How to use LibSVM with Weka in my Java code?
Adding LibSVM is real easy when using Weka 3.7.6, because it allows you to install it via its package manager, either via command line or GUI. So I'd recommend using Weka 3.7.6.

Set write permissions on ProgramData subfolder using JNA

I have a program, written in Java, which originally used its directory in Program Files to write files accessible to all users of this program. This required our users to run as administrator all the time. In an effort to alleviate that, we decided to move files which needed to be written during regular usage to the ProgramData folder using the %ALLUSERSPROFILE% environment variable. Using a subfolder in this directory for our application works great if it is designated as writable during the installation process, which works fine using NSIS.
The problem comes with upgrading existing users. The Java File API provides setWritable but this does not appear to work after testing on development machines. It looks as though the new file API with Java 7 would solve this problem, but with no release date on the horizon I would rather not wait.
It seems the simplest solution would be to use JNA to call the appropriate Windows API call to set this directory writable. Since upgrading the software necessitates admin rights, similar to installing, it should let this change go through fine. However, I'm unsure where to start, having never used JNA before or the Windows API. Suggestions as to which Windows library to load and what functions to call would be appreciated, especially if someone has encountered a similar problem before.
Well, I'm glad you gave some background...You could use JNA, but the easier way would be to execute a call to the command-line utility cacls. It's included by default in Windows XP installations, I believe, so it should do the trick for you. Try Runtime.getRuntime().exec("C:\\Windows\\System32\\cacls.exe"+options)
Check out the documentation here -> http://technet.microsoft.com/en-us/library/bb490872.aspx
I use the follow line:
Runtime.getRuntime().exec( "C:\\Windows\\System32\\icacls.exe \"%ProgramData%\my application" /grant *S-1-5-32-545:(OI)(CI)(W,M)" );
S-1-5-32-545 is the SID for BUILTIN\Users because the name work only on English systems. https://support.microsoft.com/de-de/kb/163846
This give the BUILTIN\Users write access to all files in the given directory independent which user has create it.

Categories

Resources