Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Goose in Java Project

Tags:

java

goose

How can i use Goose on a java project? I tested the online version of both boilerpipe and goose, and the last one it's way better but now it's developed in Scala.

I searched for the jar of previous version but can't find it (neither api). The last .jar i tried it's: goose-2.1.22. I imported it in my Ecplise project and tried with this code:

String url = "http://www.cnn.com/2010/POLITICS/08/13/democrats.social.security/index.html";
Goose goose = new Goose(new Configuration());
Article article = goose.extractContent(url);
System.out.println(article.cleanedArticleText());

But i get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at daweb.main(daweb.java:212)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 13 more

Is it possible to use Goose without Scala?

like image 947
Marco Micheli Avatar asked Sep 22 '26 15:09

Marco Micheli


2 Answers

You should add Scala Library to your buildpath

like image 186
Ivan T Avatar answered Sep 25 '26 05:09

Ivan T


There is a link provided in the issues page where you can find a .jar compiled for java use. https://github.com/GravityLabs/goose/issues

import com.gravity.goose.*;


String url = "http://www.straitstimes.com/little-india-riot";
Goose goose = new Goose(new Configuration());
Article article = goose.extractContent(url);
System.out.println(article.cleanedArticleText());

This code works as a start.

like image 36
ctrlsave Avatar answered Sep 25 '26 04:09

ctrlsave