cs_ghadouch
Messages postés10Date d'inscriptionlundi 6 décembre 2010StatutMembreDernière intervention11 février 2013
-
7 déc. 2010 à 12:16
Abou.Ossama
Messages postés4Date d'inscriptionmardi 28 avril 2015StatutMembreDernière intervention30 avril 2015
-
29 avril 2015 à 13:37
j'ai un projet qui consiste à créer un petit programme anti_spam on dois travailler avec weka et avec java ou bien C++
la 1ére étape consiste à générer un fichier ARFF:
je dois copier le contenu des spam que j'ai dans mon mail (minimum 2 spam) dans un fichier .txt pour créer un fichier .arff à partir de ce fichier texte donc pour ce la j'ai commencé à créer mon programme qui assure la conversion d'un fichier texte en fichier arff mais lors de la compilation j'ai trouvé quelque problème s'il vous plais s"il y a quelqu'un qui peut m'aider donc c'est mon code :
import java.io.*;
import weka.core.*;
/**
* Builds an arff dataset from the documents in a given directory.
* Assumes that the file names for the documents end with ".txt".
*
* Usage:
*
* TextDirectoryToArff <directory path>
*
* @author Richard Kirkby (rkirkby at cs.waikato.ac.nz)
* @version 1.0
*/
public class TextDirectoryToArff {
public Instances createDataset(String directoryPath) throws Exception {
FastVector atts = new FastVector(2);
atts.addElement(new Attribute("filename", (FastVector) null));
atts.addElement(new Attribute("contents", (FastVector) null));
Instances data = new Instances("text_files_in_" + directoryPath, atts, 0);
File dir = new File(directoryPath);
String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
if (files[i].endsWith(".txt")) {
try {
double[] newInst = new double[2];
newInst[0] = (double)data.attribute(0).addStringValue(files[i]);
File txt = new File(directoryPath + File.separator + files[i]);
InputStreamReader is;
is = new InputStreamReader(new FileInputStream(txt));
StringBuffer txtStr = new StringBuffer();
int c;
while ((c = is.read()) != -1) {
txtStr.append((char)c);
}
newInst[1] = (double)data.attribute(1).addStringValue(txtStr.toString());
data.add(new Instance(1.0, newInst));
} catch (Exception e) {
//System.err.println("failed to convert file: " + directoryPath + File.separator + files[i]);
}
}
}
return data;
}
j'ai travaillé avec eclipse et je l'ai téléchargé weka.jar
Il m'affiche les erreurs suivantes :
Cannot instantiate the type Instance TextDirectoryToArff.java /projet1/src line 41 Java Problem
FastVector is a raw type. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 20 Java Problem
FastVector is a raw type. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 20 Java Problem
FastVector is a raw type. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 21 Java Problem
FastVector is a raw type. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 22 Java Problem
The constructor FastVector(int) is deprecated TextDirectoryToArff.java /projet1/src line 20 Java Problem
The method addElement(Object) from the type FastVector is deprecated TextDirectoryToArff.java /projet1/src line 21 Java Problem
The method addElement(Object) from the type FastVector is deprecated TextDirectoryToArff.java /projet1/src line 22 Java Problem
The type FastVector<E> is deprecated TextDirectoryToArff.java /projet1/src line 20 Java Problem
The type FastVector<E> is deprecated TextDirectoryToArff.java /projet1/src line 20 Java Problem
The type FastVector<E> is deprecated TextDirectoryToArff.java /projet1/src line 21 Java Problem
The type FastVector<E> is deprecated TextDirectoryToArff.java /projet1/src line 22 Java Problem
Type safety: The expression of type FastVector needs unchecked conversion to conform to ArrayList TextDirectoryToArff.java /projet1/src line 23 Java Problem
Type safety: The expression of type FastVector needs unchecked conversion to conform to List<String> TextDirectoryToArff.java /projet1/src line 21 Java Problem
Type safety: The expression of type FastVector needs unchecked conversion to conform to List<String> TextDirectoryToArff.java /projet1/src line 22 Java Problem
Type safety: The method addElement(Object) belongs to the raw type FastVector. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 21 Java Problem
Type safety: The method addElement(Object) belongs to the raw type FastVector. References to generic type FastVector<E> should be parameterized TextDirectoryToArff.java /projet1/src line 22 Java Problem
Ce sont seulement des warnings et le code que tu utilises est très vieux. Il te suffit d'utiliser FastVector et tu en auras déjà beaucoup moins. Bon courage.
cs_ghadouch
Messages postés10Date d'inscriptionlundi 6 décembre 2010StatutMembreDernière intervention11 février 2013 11 déc. 2010 à 11:54
Merci gouessej j'ai bien résolu mon problème, ce n'est pas un problème de code mais l'erreur c'est que j'ai mal importer weka.jar et weka-src.jar dans eclipse donc ça va mon programme marche avec 0 erreurs Mais j'ai pas arriver à obtenir un fichier .arff à partir d'un fichier .txt
toujour m'affiche le message "Usage: java TextDirectoryToArff <directory name>"
le fichier que je veux le convertir en .arff je l'ai placé sous un répertoire sous c: et j'ai spécifié le chemin dans mon code.
s'il vous plais j'ai besoin de votre aides et merci d'avance
cs_ghadouch
Messages postés10Date d'inscriptionlundi 6 décembre 2010StatutMembreDernière intervention11 février 2013 11 déc. 2010 à 13:11
ok ça c'est une partie de mon code
FastVector atts = new FastVector(2);
atts.addElement(new Attribute("spam.txt", (FastVector) null));
atts.addElement(new Attribute("contents", (FastVector) null));
Instances data = new Instances("c:/exemp/spam.txt" + directoryPath, atts, 0);
victorino26
Messages postés1Date d'inscriptionlundi 23 mai 2011StatutMembreDernière intervention23 mai 2011 23 mai 2011 à 11:13
Bonjour,
je viens d'écrire ce code sur Netbeans et j'ai spécifié le chemin du répertoire comme expliqué au dessus, le code tourne sans erreur, mais je ne sais pas ou aller récupérer le .arff
quelqu'un peut m'orienter svp!?
merci pour votre aide