Conversion d'un fichier .txt en fichier .ARFF

cs_ghadouch Messages postés 10 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 11 février 2013 - 7 déc. 2010 à 12:16
Abou.Ossama Messages postés 4 Date d'inscription mardi 28 avril 2015 Statut Membre Dernière intervention 30 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;
}

public static void main(String[] args) {

if (args.length == 1) {
TextDirectoryToArff tdta = new TextDirectoryToArff();
try {
Instances dataset = tdta.createDataset(args[0]);
System.out.println(dataset);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
} else {
System.out.println("Usage: java TextDirectoryToArff <directory name>");
}
}
}

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

j'attends votre réponses avec patience merci

9 réponses

Utilisateur anonyme
8 déc. 2010 à 14:02
Bonjour

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.















0
cs_ghadouch Messages postés 10 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 11 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
0
Utilisateur anonyme
11 déc. 2010 à 12:48
C'est limpide; selon le message d'erreur, il faut passer un répertoire.













0
cs_ghadouch Messages postés 10 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 11 février 2013
11 déc. 2010 à 12:58
oui je sais mon ami mais j'ai passé un répertoire c'est ça le problème et j'ai rien trouvé
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_ghadouch Messages postés 10 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 11 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);
0
cs_diaisma Messages postés 1 Date d'inscription mercredi 20 décembre 2006 Statut Membre Dernière intervention 16 mars 2011
16 mars 2011 à 15:12
merci ghadouch, javais le meme pb et c resolu gràce a to posting
0
victorino26 Messages postés 1 Date d'inscription lundi 23 mai 2011 Statut Membre Dernière intervention 23 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
0
hadjikader481 Messages postés 1 Date d'inscription mercredi 30 novembre 2011 Statut Membre Dernière intervention 22 décembre 2011
22 déc. 2011 à 03:12
salem j'ai besoin d'un code source en netbeans que fait la transformation d'un fichier *.txt et filtrer lesspam . méthode weka
svp aide moi!!!!!?
0
Abou.Ossama Messages postés 4 Date d'inscription mardi 28 avril 2015 Statut Membre Dernière intervention 30 avril 2015
29 avril 2015 à 13:37
j'ai copié votre code mais j'ai eu un probleme m'affichant une erreur dans cette ligne:
data.add(new Instance(1.0, newInst));
0
Rejoignez-nous