Beginner question: integration of Java API

Hi there,

I would like to use the Java API for lemmatisation and PoS tagging in German. However, it’s been a while since I have written code in Java the last time. Could someone, please, give me a pointer on how to correctly import the necessary packages and load the necessary classes?

Best,
a

Hi,
Have you tried this page?
LanguageTool Java API

Hi Robert,

yes, of course, I have :slight_smile: My use case is:

  1. Read in German or English data, one word per line, ignoring existing markup (XML header, sentence tags, etc.).
  2. Lemmatise.
  3. Pos tag.
  4. Print to output file.
    As said before, I haven’t done Java in a while, so I do need a bit of instruction on how to setup the classpath, indicate the right packages, import the right classes … I didn’t really find this documented anywhere.

Any hint will be appreciated.

Cheers,
anne
(I’m ready to provide some documentation of this once I get it wo work^^)

If you’re not experienced with Java you may want to try to do this in Groovy (it supports Java syntax but adds a lot of convenience and is a scripting language so it’s easier to write small tools with).
Here’s a file that allows simple lemmatization and tagging of the input: https://github.com/arysin/nlp_uk/blob/master/src/org/nlp_uk/tools/TagText.groovy
It manages dependency in a script itself so it’s very easy to use:

  1. get the file and replace Ukrainian with German (and uk with de)
  2. install java and groovy
  3. run the script: groovy TagText.groovy -i <input_file> -o <output_file>

Hi, thanks for the suggestions. I actually just tried to launch a kind of Hello world script:

import org.languagetool.*
import org.languagetool.language.*

public class Test
{
public static void main(String[] args)
{
JLanguageTool langTool = new JLanguageTool(new GermanyGerman());
}
}

This compiles, but I still cannot run the script: Main class not found or could not be loaded. Sorry for asking about such basic stuff, but I would really like to get this to work. Any help appreciated!

Cheers,
a

How do you compile and run this script?

Privet, Andriy,

first of all, thanks for caring. I actually forgot some ; in my example code …
Anyway, I did the following:
javac -cp path_to_languagetool-commandline.jar script.java
java -classpath path_to_languagetool-commandline.jar script
Actually, I didn’t find any good docu on how to do that, so this might well be wrong.
Спасибо за помощь!
a

First: you need to decide whether you want to use java or groovy - although they have a lot in common they are run quite differently. I looks like you’re trying to use java but you don’t have import finished with semicolon (which is allowed in Groovy but not in Java).
If you use java you’d have to provide classpath yourself and path_to_languagetool-commandline.jar is not enough (you may take a look at classpath in this example languagetool/testrules.sh at master · languagetool-org/languagetool · GitHub).
During the development it’s better to manage dependencies and classpath via dev tools (maven, gradle or IDE).
If you use groovy script (like in the nlp_uk project I provided link above) it’ll manage all the dependencies and classpath by itself, all you have to do is to type “groovy my_lt_script.groovy”

P.S. although I understand Russian it’s not my native language :slight_smile: