I am new to boilerpipe. I tried to run sample code given on their website:
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.extractors.DefaultExtractor;
public class TESTURLBOILERPIPE {
public static void main(String[] arges) throws Exception
{
final URL url = new URL(
"http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en");
ArticleExtractor ae = new ArticleExtractor();
System.out.println(ae.INSTANCE.getText(url));
}
}
I have added all the required jar files to the class path, however I get the exception:
Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch
at org.jsoup.helper.Validate.isTrue(Validate.java:45)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:26)
I don't know Boilerpipe, but are you sure you are trying to run the correct Java class? The stack trace looks like you are trying to run HtmlToPlainText (without arguments, thus the exception), but from the code you posted I think you would like to run your TESTURLBOILERPIPE class.
Try using a python wrapper. It takes care of all the dependencies, though you might have to install jpype manually (that source code is on sourceforge).
https://github.com/misja/python-boilerpipe
Related
I'm using algorithmia, a repository of trained ML functions on the Internet. Few weeks ago, an issue showed up, and since then, haven't been able to figure out what's going on. I'm executing this code, which can be found on their official site.
import com.algorithmia.Algorithmia;
import com.algorithmia.AlgorithmiaClient;
import com.algorithmia.algo.AlgoResponse;
import com.algorithmia.algo.Algorithm;
public class Main {
public static void main(String[] args) throws Exception {
String input = "A purely peer-to-peer...";
AlgorithmiaClient client = Algorithmia.client("api_key");
Algorithm algo = client.algo("nlp/Summarizer/0.1.8");
algo.setTimeout(300L, java.util.concurrent.TimeUnit.SECONDS); //optional
AlgoResponse result = algo.pipe(input);
System.out.println(result.asJsonString());
}
}
But this code raises the following exception:
Exception in thread "main" com.algorithmia.APIException: 308 unexpected API response:
at com.algorithmia.algo.Algorithm.pipeRequest(Algorithm.java:145)
at com.algorithmia.algo.Algorithm.pipe(Algorithm.java:96)
at Main.main(Main.java:13)
I want to help out
Create a maven project
Add this maven dependency
<dependency>
<groupId>com.algorithmia</groupId>
<artifactId>algorithmia-client</artifactId>
<version>[,1.1.0)</version>
</dependency>
Paste the code showed above
Further observations and guessings
Issuing a cURL request everything works as expected
Using Python works fine
It may have something to do with HttpClient
The Java code will work with a proxy like Charles
Refer to the opened issue on GitHub
Given the current date, 2nd July 2019, they published version 1.0.16 that fix such error.
I am trying to classify an instance using a .model file which I have created on the Weka GUI. It seems I have successfully classified the test instance, however, I am not sure whether I am able to successfully load my .model file and of the Stub compiler error.
I have tried to remove the extends AppCompatActivity and if that makes any difference in the .model upload. It turns out that to use getAssets(), the code must be in an activity. However, I an still unsure of whether the model has upload and the unusual compiler error. I have followed the basic framework of #davidmascharka's work on GitHub (he's also loading a WEKA model from assets), but mine does not compile.
Here's my code:
package com.example.owner.introductoryapplication;
import android.support.v7.app.AppCompatActivity;
import weka.classifiers.Classifier;
import weka.classifiers.rules.DecisionTable;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
import java.util.ArrayList;
public class Test extends AppCompatActivity {
public static void main(String[] args) {
Test test = new Test();
test.start();
}
public void start() {
//LOADS THE MODEL...------------------------------------------------------
String rootPath = "/assets/";
String fileName = "PGBD_DecisionTableUPD.model";
Classifier cls = null;
try {
//cls = (Classifier) weka.core.SerializationHelper.read(rootPath + fileName);
cls = (DecisionTable) weka.core.SerializationHelper.read(getAssets().open(fileName));
} catch (Exception e) {
e.printStackTrace();
}
}
}
And here's my error output:
Exception in thread "main" java.lang.RuntimeException: Stub!
at android.content.Context.<init>(Context.java:67)
at android.content.ContextWrapper.<init>(ContextWrapper.java:30)
at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java:40)
at android.app.Activity.<init>(Activity.java:643)
at android.support.v4.app.SupportActivity.<init>(ComponentActivity.java:46)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:68)
at android.support.v7.app.AppCompatActivity.<init>(AppCompatActivity.java:62)
at com.example.owner.introductoryapplication.Test.<init>(Test.java:13)
at com.example.owner.introductoryapplication.Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Process finished with exit code 1
I expect the program to at least compile! I have absolutely no clue why it's not. I tried switching the order of my dependencies, hoping that would make a difference, but to no luck.
Any ideas?
Thanks in advance.
This may have been covered before, but weka.jar only allows for Stub implementations. Essentially, you must configure the run setting to "app" instead of a specific file.
If you want to see how a specific file works, then you can use the debug option for your app.
So I am trying to get an OCR working for a bigger project that reads characters from an image and I am following this you tube video: https://www.youtube.com/watch?v=aEMSxiXctPk
I did everything in the video and still cannot get it to work. I looked on this forum about the error I am getting, but it looks like their projects are different so I think they need different jars than I would. I have all of the jars from the video or at least I think I do. Any ways, the issue in java delivered this message.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type org.slf4j.Logger cannot be resolved. It is indirectly referenced from required .class files
org.slf4j.Logger cannot be resolved to a type
LoggerFactory cannot be resolved
The method setDatapath(String) of type Tesseract must override a superclass method
This is my code:
package Tess4j;
import java.io.*;
import net.sourceforge.tess4j.*;
import org.slf4j.*;
public class test {
public static void main(String[] args) throws IOException{
File imageFile = new File("C:\\Users\\Sean\\workspace\\Bigno Tracker\\Images\\eurotext.png");
ITesseract instance=new Tesseract();
instance.setDatapath("C:\\Users\\Sean\\workspace\\Bigno Tracker\\tessdata");
try {
String result=instance.doOCR(imageFile);
System.out.println(result);
}catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
This is an image of my screen that shows the jars I have.
So what am I missing?
Thanks in advance.
Edit:
I don’t really understand your question but, I’ve done some work with OCR Engines in the past.. ABBYY hass a good one that’s really easy to integrate!
P.S Did a little research, check to see if you have all the appropriate dependencies for your OCR engine version
Cheers
I'm working on a project that involves loading up a ResourceBundle. More explicitly, I've created a class that extends ListResourceBundle. The class is called Resources.java. It compiles fine and everything, but the MissingResourceException keeps popping up every time I try to load up the class:
All my source files are in package chapter31. When making this call with or without the "chapter31" in the string, always results in a MissingResourceException. My IDE is Eclipse. I've been playing around with this one problem for two days. I even tried changing the version of Eclipse. I'm at the end of my rope. What can I do in Eclipse to ensure that the getBundle() method can see the class. I don't know how it can miss it. It's in the same package! Please advise.
Alikas
package chapter31;
import java.applet.Applet;
import java.applet.AudioClip;
import java.util.ListResourceBundle;
import java.util.ResourceBundle;
import javax.swing.ImageIcon;
public class Resources extends ListResourceBundle {
Object contents[][];
public Resources() {
AudioClip clip = Applet.newAudioClip(getClass().getResource("/E31_10/audio/us.mid"));
ImageIcon image = new ImageIcon(getClass().getResource("/E31_10/image/us.gif"));
contents = new Object[3][2];
contents[0] = new Object[] {"clip", clip};
contents[1] = new Object[] {"icon", image};
contents[3] = new Object[] {"delay", new Integer(68000)};
}
protected Object[][] getContents() {
return contents;
}
public static void main(String[] args) {
ResourceBundle res = ResourceBundle.getBundle("chapter31.Resources");
}
}
The MissingResourceException is misleading here. Your problem may be caused by two other problems:
The resources in the following two lines cannot be found:
AudioClip clip =
Applet.newAudioClip(getClass().getResource("/E31_10/audio/us.mid"));
ImageIcon image = new ImageIcon(getClass().getResource("/E31_10/image/us.gif"));
If the first one is not the problem, there is a second problem:
You have a wrong array index contents[3] which will cause ArrayIndexOutOfBoundsException and this will also cause the misleading MissingResourceException to be thrown. If you can find this exception in your exception stack trace, your problem is here. Change it to contents[2] will solve the problem.
Note: The reason you are seeing MissingResourceException is ultimately caused by the class loader cannot create an instance of the Resources class due to the problems pointed out above. If you had put the contents array initialization codes in a separate method instead of the constructor, you may not get this exception at the object initialization phase. Of course, other exceptions will pop out later when you try to call getObject method.
Are you trying to load a message properties file called "chapter31.Resources"? If so then in Eclipse you can try the below:
Click on "Debug Configuration..."
Find the launcher you are using to execute the main method for Resources
Click on the Classpath tab
Click on "User Entries" and then Click the "Advanced" button
Select "Add External Folder" and choose the folder the "chapter31.Resources" .
ResourceBundle.getBundle() method is looking for the file in your classpath . if this file is not in your classpath it won't be able to find it.
The steps above adds the folder that "chapter31.Resources" to your classpath.
If this still does not work you can try passing the full path of the file to ResourceBundle.getResource().
I am just trying to get some things to work so I can try some of google app engines java. However I seem to have a problem with something that I can't get a hold of.
The java code looks like this:
import java.net.URL;
import com.google.gdata.client.photos.*;
import com.google.gdata.data.photos.*;
public class TestPicasa {
public static void main(String[] args) {
try {
PicasawebService service = new PicasawebService("Picasa test");
service.setUserCredentials("username#gmail.com", "password");
URL feedURL = new URL("http://picasaweb.google.com/data/feed/api/user/username?kind=album");
UserFeed feed = service.getFeed(feedURL, UserFeed.class);
for (AlbumEntry entry : feed.getAlbumEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have referenced to mail.jar, activation.jar, servlet-api.jar, gdata-client, gdata-client-meta, gdata-core, gdata-media, gdata-photos-2.0.jar and gdata-photos-meta-2.0.jar according to instruction from google.
And I get this error to the console:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:532)
at TestPicasa.main(TestPicasa.java:10)
Any idea on what I have missed?
You also need Google Collections
Verify that you are not loading your google jars twice. Sometimes you would have 2 locations and the one that you are not thinking about would have a missing jar. Then your class file gets missing since the jar it's on is not under 1st classloader. This happens often on Tomcat when you have all your jars in the webapp's WEB-INF/lib but some of the jars in the Tomcat/lib. Alternatively, I only found missing class in google-collect.jar and I don''t think you are listing it