All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dropchop.quarkus.snakejar.example.LanguageDetectionService Maven / Gradle / Ivy

Go to download

Quarkus extension that integrates SnakeJar Java library with embedded CPython to Quarkus. This extension enables calling Python native code from Quarkus REST services.

The newest version!
package com.dropchop.quarkus.snakejar.example;

import com.dropchop.snakejar.Invocation;
import com.dropchop.snakejar.InvokeClass;
import com.dropchop.snakejar.Invoker;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.HashMap;
import java.util.Map;

/**
 * LanguageDetectionService
 *
 * @author Nikola Ivačič  on 15. 11. 21.
 */
@ApplicationScoped
public class LanguageDetectionService {

  public static class InvokeLangIdClass extends InvokeClass> {
    @SuppressWarnings("unchecked")
    public InvokeLangIdClass() {
      super("lang_detect", "lang_id", "LanguageDetect", (Class>)(Class)HashMap.class);
    }
  }

  public static final Invocation> LANG_ID_CLASS = new InvokeLangIdClass();

  @Inject
  Invoker invoker;

  public Map detectLanguage(String text, int numRet) throws Exception {
    Map result = invoker.apply(LANG_ID_CLASS,
      () -> new Object[]{
        text,
        numRet
      }).get();
    return result;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy