Tika LanguageDetection gives error 'No language detectors available' - apache-tika

Tika 2.2.3, simple code
public static void main(String[] args) throws IOException {
LanguageDetector detector =LanguageDetector.getDefaultLanguageDetector();
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
detector.addText("This is english");
LanguageResult languageResult=detector.detect();
}
Last line gives error
Exception in thread "main" java.lang.IllegalStateException: No language detectors available
at org.apache.tika.language.detect.LanguageDetector.getDefaultLanguageDetector(LanguageDetector.java:67)
UPDATE maven dependencies
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-langdetect -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-langdetect</artifactId>
<version>2.3.0</version>
<type>pom</type>
</dependency>
I cant find anything useful online to fix this problem... am I missing some model files that I must download, where?
Any tips much appreciated!

I tried your code and reproduced the same issue. After reading the docs, which then led to samples in github and I finally found its pom.xml to have another dependency. Then I successfully got the expected output: en: HIGH (0.999999).
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-langdetect-optimaize</artifactId>
<version>2.3.0</version>
</dependency>
LanguageDetector detector = LanguageDetector.getDefaultLanguageDetector().loadModels();
detector.addText("This is english");
LanguageResult languageResult = detector.detect();
Explanations
LanguageDetector is abstract class, and implementations should be added as dependency.

Related

Apache tika custom parser

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-server-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parser-audiovideo-module</artifactId>
<version>2.3.0</version>
</dependency>
I have my own parser class also meta/services/ ... parser.Parser files
When i NOT use audio module -> i see my custom parser
When i add audio dependency -> i see audio parser, but dont see my custom
I think problem in audio module manifest file, which rewrite my own manifest file
How i can fix it???

Null Pointer while trying to get Principal User with Okta

After logging in on website using Okta for authentication I go to the home page and it gives a null pointer exception when I am trying to grab the logged in User Principal.
Here is my Security Dependencies: (I am using Spring boot 1.5.6)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.okta.spring</groupId>
<artifactId>okta-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
Here is my controller:
#GetMapping("/")
public String home(Model model, Principal principal) {
System.out.println(principal.getName());
return "/home";
}
Any help to point me in the right direction would be great. I have looked at the documentation and it seems I am not doing things incorrectly.

Jersey 1.19 Grizzly 2.3.25 and Umlaute in URL - JUnit tests does not work while browser access does

In a RESTFul Jersey solution I am trying to receive URLs that contain German Umlaut characters e.g.
http://localhost:8085/hello/hello/echo/ÄÖÜßööü
When I enter such URLs with a browser I get correct results.
When I test things with a JUnit test it doesn't work.
org.junit.ComparisonFailure: expected:<[ÄÖÜßäöü]> but was:<[ÃÃÃÃäöü]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.bitplan.rest.test.TestHello.testUmlaute(TestHello.java:43)
the debug output is:
http://localhost:8085/hello/hello/echo/%C3%84%C3%96%C3%9C%C3%9F%C3%A4%C3%B6%C3%BC
http://localhost:8085/hello/hello/echo/ÄÖÜßäöü
GET:hello/echo/ÃÃÃÃäöü
and so it seems the url is not handled correctly by Grizzly/Jersey.
How can I fix this or work around it?
I found: https://github.com/javaee/grizzly/issues/1377 and tried different encodings e.g. as proposed in https://stackoverflow.com/a/9542781/1497139 but that didn't make any difference.
I also set
server.getServerConfiguration().setDefaultQueryEncoding(Charsets.UTF8_CHARSET);
as outlined in https://github.com/javaee/grizzly/issues/1450 but still no luck
JUnit Test
see https://github.com/BITPlan/com.bitplan.simplerest/blob/master/src/test/java/com/bitplan/rest/test/TestHello.java#L42
#Test
public void testUmlaute() throws Exception {
super.startServer();
URI uri=new URI("http://localhost:8085/hello/hello/echo/ÄÖÜßäöü");
System.out.println(uri.toASCIIString());
System.out.println(uri.toString());
WebResource wrs = Client.create().resource(uri);
String result= wrs.accept("text/html; charset=utf-8").get(String.class);
assertEquals("ÄÖÜßäöü",result);
}
"Hello/Echo" Resource
package com.bitplan.hello.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
#Path("/hello")
/**
* Simple Hello Resource
* #author wf
*
*/
public class HelloResource {
#Context
UriInfo uriInfo;
#Context
Request request;
#GET
public String getHello() {
return "Hello";
}
#GET
#Produces("text/html")
#Path("echo/{value}")
public String getEcho(#PathParam("value") String value) {
System.out.println(request.getMethod()+":"+uriInfo.getPath());
return value;
}
}
maven dependencies
<properties>
<!-- jersey version -->
<!-- <jersey.version>2.22.2</jersey.version> -->
<jersey.version>1.19.1</jersey.version>
<!-- http://grizzly.java.net/ -->
<grizzly.version>2.3.25</grizzly.version>
...
</properties>
...
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- Grizzly server -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>${grizzly.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-servlet</artifactId>
<version>${grizzly.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http</artifactId>
<version>${grizzly.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>

Swagger-ui doesn't provide how i pass MediaType.APPLICATION_OCTET_STREAM content

Actually i am facing a problem that Swagger-ui can't show me input for MediaType.APPLICATION_OCTET_STREAM, so lets imagine this next service:
#PUT
#Path("/performAudioQuery")
#Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response performAudioQuery(InputStream audioInputStream){
//Impl of the service
}
and here are the dependencies
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
and i am using wildfly 9.x
So what should i do to make it possible for Swagger-ui working good with this previous service?
The current version of the Swagger/OpenAPI specification (2.0) doesn't deal kindly with file uploads as what's known as body parameter. We've formulated a workable solution that is covered at https://github.com/OAI/OpenAPI-Specification/issues/50 - however that solution is currently not fully supported by swagger-core and not supported at all in swagger-ui.

Portlet preferences

I'm trying to store portlet preferences in a backing bean (JSF) as mentioned in this tutorial
But, I can not understand how they imported Preference class here
Map<String, Preference> mutablePreferenceMap =
(Map<String, Preference>) elResolver.getValue(
facesContext.getELContext(), null, elExpression);
the package javax.portlet.* don't contain faces.preference.Preference
Anyone has an idea about that, specially how to save portlet preferences
thanks in advance
You have to add the Liferay Faces Bridge JAR to your project.
Add the following dependencies:
<dependencies>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-alloy</artifactId>
<version>3.1.0-ga1</version>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-bridge-impl</artifactId>
<version>3.1.0-ga1</version>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-portal</artifactId>
<version>3.1.0-ga1</version>
</dependency>
</dependencies>
and the liferay-faces-bridge-api jar which is a dependency for liferay-faces-bridge-impl has this Preference interface.
More info:
http://www.liferay.com/community/liferay-projects/liferay-faces/download

Resources