1

I'm constructing an application in Google App Engine (using Eclipse) that uses WEKA [1] in one of its parts. This app needs to load ARFF bases, but that's allright. The directory in which these bases are is in project's root directory. Following lines are responsible for loading bases:

1. DataSource source;
2. source = new DataSource("bases/iris.arff");
3. Instances trainInstances = source.getDataSet();
4. trainInstances.setClassIndex(trainInstances.numAttributes() - 1);

Above lines are part of the code that is called in a servlet responsible for execution of the application. Servlet runs ok, but 'source' variable doesn't get to read arff file and, so, i get the following exception at line 3:

"java.io.IOException: No source has been specified at weka.core.converters.ArffLoader.getDataSet(ArffLoader.java:1003)"

According to [2],

It is possible to read from a file which is uploaded as part of your application provided that it is in the following locations: war/WEB-INF // in a location matching the pattern in appengine-web.xml (which by default includes everything)

I've followed this two points, but with no sucess. To the second one, my configuration was the following:

<resource-files>
    <include path="/bases/**.arff" />
</resource-files>

Given this long history, I ask to you: Is there anyway to put "bases" directory in some place, or configuring something on GAE xml files, or on Eclipse, that make possible ARFF bases be loaded?


References

[1] www.cs.waikato.ac.nz/ml/weka/

[2] https://developers.google.com/appengine/kb/java#readfile

1 Answers1

0

Your problem is more about loading resources in web application environment. Some additional resources in stackoverflow about loading resources in web application environment.

Put your arff file in your source-src directory. When you compile your application, files under this directory copied to web-inf/classes directory.

See Project Explorer

You can see where they are copied if you create a war file. See (Export - War)

After you make sure that your arff file is included in your web archive file (war file). You can use appropriate path to it. Like below. You need to use InputStream constructor not String one.

InputStream stream = getServletContext().getResourceAsStream("WEB-INF/classes/iris.arff");
DataSource source = new DataSource(stream);

I have tried this with simple web application project, it works. My code is as below.

deneme.jsp

<%
InputStream stream = getServletContext().getResourceAsStream("WEB-INF/classes/iris.arff");
String summary = LoadArffFile.loadArffFileAndFindSummary(stream );

out.println(summary);

%>

LoadArffFile.java

public static String loadArffFileAndFindSummary( InputStream stream)
{

     DataSource source = new  DataSource(stream);
     String summary = null;
    try {
        summary = source.getStructure().toSummaryString();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     return summary;
}

Output in tomcat.

Relation Name: iris Num Instances: 0 Num Attributes: 5 Name Type Nom Int Real Missing Unique Dist 1 sepallength Num 0% 0% 0% 0 / 0% 0 / 0% 0 2 sepalwidth Num 0% 0% 0% 0 / 0% 0 / 0% 0 3 petallength Num 0% 0% 0% 0 / 0% 0 / 0% 0 4 petalwidth Num 0% 0% 0% 0 / 0% 0 / 0% 0 5 class Nom 0% 0% 0% 0 / 0% 0 / 0% 0 
Community
  • 1
  • 1
Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • Thank you so much for the answer, Atilla. I'll follow here your clues and, later, I'm gonna post results. – Inácio Medeiros Jul 05 '12 at 13:12
  • So, Atilla, I've put the directory in src, but the error persisted. I've also put in war/WEB-INF/, and configured "appengine-web.xml" in the following way: but the error persisted. Do you also have any idea? – Inácio Medeiros Jul 07 '12 at 23:13
  • I have added more code examples. I did not try with google app but simple tomcat application with only one jsp. It should work. If you want, I can send you example project. – Atilla Ozgur Jul 08 '12 at 11:51
  • Also you should not do followings. "I've also put in war/WEB-INF/." Your war file is your project. You create a war file before uploading to app server. Google App Engine may hide this fact. – Atilla Ozgur Jul 08 '12 at 11:53