2012-05-03 8 views
-1

私はwekaライブラリからいくつかの関数をインポートする必要があるラッパーを作成しています。しかし、それは私に次のエラーを投げている:java未報告の例外wekaを組み込んだコードのコンパイル時にエラーが発生しました

報告されていない例外java.lang.Exception;私のコード

をキャッチまたはスローされるように宣言する必要があります以下の通りです:

import java.io.*; 
import weka.core.Instances; 
import java.io.BufferedReader; 
import java.io.FileReader; 
import weka.core.converters.ConverterUtils.DataSource; 
import java.lang.Integer; 

public class wrapper 
{ 
public static void main(String[] args) 
{ 

    try 
    { 
     Runtime r = Runtime.getRuntime(); 
     Process p = r.exec("python frequency_counter_two.py nono 400 0"); 
     BufferedReader br = new BufferedReader(new   
     InputStreamReader(p.getInputStream())); 
     p.waitFor(); 
     String line = ""; 
     while (br.ready()) 
      System.out.println(br.readLine()); 

    } 
    catch (Exception e) 
    { 
    String cause = e.getMessage(); 
    if (cause.equals("python: not found")) 
     System.out.println("No python interpreter found."); 
    } 

run_weka(); 


} 



public static int run_weka() 
{ 

DataSource source = new DataSource("features_ten_topics_10_unigrams_0_bigrams.csv"); 
Instances data = source.getDataSet(); 
// setting class attribute if the data format does not provide this information 
// For example, the XRFF format saves the class attribute information as well 
if (data.classIndex() == -1) 
    data.setClassIndex(data.numAttributes() - 1); 

/* 

double percent = 66.0; 
Instances inst = data; // your full training set 
instances.randomize(java.util.Random); 
int trainSize = (int) Math.round(inst.numInstances() * percent/100); 
int testSize = inst.numInstances() - trainSize; 
Instances train = new Instances(inst, 0, trainSize); 
Instances test = new Instances(inst, trainSize, testSize); 

// train classifier 
Classifier cls = new J48(); 
cls.buildClassifier(train); 
// evaluate classifier and print some statistics 
Evaluation eval = new Evaluation(train); 
eval.evaluateModel(cls, test); 
System.out.println(eval.toSummaryString("\nResults\n======\n", false)); 

*/ 
} 

} 

に行くことかもしれないものの任意のアイデア?

+0

あなたはIDEを使用しないでください?私はwekaを知らないが、私はあなたの "run_weka"メソッドが再スローするか、いくつかの例外をキャッチする必要があると確信しています... – home

+0

あなたの質問に答えられた場合、またはそれがもはや有効でない場合は、最も適切な答えは誰もが問題が解決されたことを知っている。ありがとう。 – wattostudios

答えて

0

DataSourceコンストラクタからスローされた例外とrun_weka()のgetDataSet()を処理する必要があります。

あなたがドキュメントをチェックする場合は、それらの両方がjava.lang.Exceptionを投げることがわかります。http://crdd.osdd.net/man/wiki/weka/core/converters/ConverterUtils.DataSource.htmlあなたがにいくつかのコードを書く必要があるので、WEKA方法のいくつかは、例外を投げることができると言っている。基本的

0

この発生を処理する。この場合

、あなたはおそらくこのような何かをするためにあなたの方法を変更します...

public static int run_weka() { 
    Instances data; 

    try { 
     DataSource source = new DataSource("features_ten_topics_10_unigrams_0_bigrams.csv"); 
     data = source.getDataSet(); 
    } 
    catch (Exception e){ 
     System.out.println("An error occurred: " + e); 
     return -1; 
    } 

    // setting class attribute if the data format does not provide this information 
    // For example, the XRFF format saves the class attribute information as well 
    if (data.classIndex() == -1) 
     data.setClassIndex(data.numAttributes() - 1); 
    /* 
    Your commented code... 
    */ 
    } 
} 
関連する問題