Java 11 API Wrapper for https://linguin.ai
To get the latest release from Maven Central, simply add the following to your pom.xml
:
<dependency>
<groupId>io.imagineobjects.web</groupId>
<artifactId>linguin-ai-java</artifactId>
<version>0.0.1</version>
</dependency>
or download the fat jar.
If you use Gradle, add this to your dependencies:
implementation group: 'io.imagineobjects.web', name: 'linguin-ai-java', version: '0.0.1'
The releases are also available on Github Packages!
For a given text, the library returns an instance of Languages
, representing the possible languages of the given text. Each Language
has a
code
and a confidence
. Call .bestMatch()
to get the most probable Language
.
To detect the Language of a single text:
final LinguinAi linguin = new RestLinguinAi("API-TOKEN-HERE");
final Languages detected = linguin.detect("What language is this?");
System.out.println("Possible languages: ")
for(final Language language : detected) {
System.out.println("Code: " + language.code());
System.out.println("Confidence: " + language.confidence());
}
System.out.println("Most probable language: " + detected.bestMatch().code());
You can detect the possible Languages
of multpile texts at the same time. It will return an instance of
BulkDetection
which is an iterable of Languages
. Each Languages
in the iterable represents the possible languages
of the text given at the same index.
final LinguinAi linguinAi = new RestLinguinAi("API-TOKEN-HERE");
final BulkDetection bulk = linguinAi.bulkDetect(
"What's up??",
"Woher kommst du?",
"Eu vin din Romania.",
"La langue Francaise..."
);
final Iterator<Languages> languages = bulk.iterator();
languages.next().bestMatch().code(); // "en"
languages.next().bestMatch().code(); // "de"
languages.next().bestMatch().code(); // "ro"
languages.next().bestMatch().code(); // "fr"
You can fetch the account Status, containing info about the API limits of your account:
final LinguinAi linguinAi = new RestLinguinAi("API-TOKEN-HERE");
final Status status = linguinAi.status();
status.dailyLimit(); //100
status.detectionsToday(); //5
status.remainingToday(); //95
You can get all the supported languages of the API like this:
final LinguinAi linguinAi = new RestLinguinAi("API-TOKEN-HERE");
final SupportedLanguages supported = linguiAi.languages();
for(final SupportedLanguage language : supported) {
System.out.println("Code: " + language.code());
System.out.println("English names: " + Arrays.toString(language.englishNames()));
System.out.println("Native names: " + Arrays.toString(language.nativeNames()));
}
At the moment the library will throw IllegalStateException
if the API responds with any
status code other than 200 OK
.
If you would like to contribute, just open an issue or a PR.
Make sure the maven build:
$mvn clean install -Pcheckstyle,itcases -Dlinguin-ai-token=<YOUR_API_TOKEN>
passes before making a PR. Checkstyle will make sure you're following our code style and guidlines.