Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic question #79

Open
asdfmoon24 opened this issue Aug 1, 2015 · 2 comments
Open

basic question #79

asdfmoon24 opened this issue Aug 1, 2015 · 2 comments

Comments

@asdfmoon24
Copy link

Thank you for your great work.

I need to use this language-detection library for my project, but got a problem.
I think this is so basic to you, but I'm rather new to Java.

The problem is that I cannot compile it.
The example code you made worked well, but a test code using it (see below) didn't work.
I got this error message:
"test.java:26: error: unreported exception LangDetectException; must be caught or declared to be thrown
LangDetect.init("./profiles");
^
test.java:27: error: unreported exception LangDetectException; must be caught or declared to be thrown
String dd=LangDetect.detect("Hellow world");
^
2 errors."

And here is the test code.

package com.cybozu.labs.langdetect;

import java.util.ArrayList;
import com.cybozu.labs.langdetect.Detector;
import com.cybozu.labs.langdetect.DetectorFactory;
import com.cybozu.labs.langdetect.Language;

class LangDetect{
public static void init(String profileDirectory) throws LangDetectException {
DetectorFactory.loadProfile(profileDirectory);
}
public static String detect(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.detect();
}
public ArrayList detectLangs(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.getProbabilities();
}
}

class testLD{
public static void main(String[] args){
LangDetect.init("./profiles");
String dd=LangDetect.detect("Hellow world");
System.out.println(dd);
}
}

Would you please let me know how to use it?
Thank you.

@odaymard
Copy link

if you solved it please answer

@charlesritchea
Copy link

just wrap the code in main in a try/catch and wrap the caught LangDetectException in a RuntimeException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants