ComposantsComponents › Fichier › LectureFile › Input
Lit un fichier ARFF (Attribute-Relation File Format), le format de données de l'outil d'apprentissage automatique Weka, et en fait un flux : une ligne par ligne de la section @data, une colonne du schéma par attribut @attribute, dans l'ordre du fichier. C'est le pendant du tFileOutputARFF.
Reads an ARFF file (Attribute-Relation File Format), the data format of the Weka machine learning tool, and turns it into a flow: one row per line of the @data section, one schema column per @attribute, in the order of the file. It is the counterpart of tFileOutputARFF.
Le composant ne peut pas être exécuté aujourd'hui. Il lit le fichier avec la bibliothèque mvn:org.talend.libraries/weka/6.0.0, qui n'est ni sur Maven Central ni sur le dépôt Nexus de Talaxie, ni dans les installations de Talaxie : le job ne compile pas (voir les erreurs). Cette page est écrite d'après les modèles du composant et le code qu'ils génèrent ; un contournement lit les fichiers ARFF simples avec un autre composant.
The component cannot be run today. It reads the file with the mvn:org.talend.libraries/weka/6.0.0 library, which is neither on Maven Central nor on the Talaxie Nexus repository, nor in the Talaxie installations: the job does not compile (see the errors). This page is written from the component templates and the code they generate; a workaround reads simple ARFF files with another component.
EntréeInput
Aucune : il commence son sous-job. Sinon un lien Iterate (un fichier par tour). None: it starts its subjob. Otherwise one Iterate link (one file per turn).
SortieOutput
Main une ligne par instance du fichierone row per instance of the file
Déclencheurs en sortieOutput triggers
On Subjob Ok On Subjob Error On Component Ok On Component Error Run if
Chaque attribut du fichier devient une colonne du schéma, à la même position. Donnez à chaque colonne un type qui convient à son attribut : String pour un attribut nominal ou texte, un type numérique pour un attribut numeric, Date avec un modèle pour un attribut date.
Each attribute of the file becomes a schema column, at the same position. Give each column a type that suits its attribute: String for a nominal or string attribute, a numeric type for a numeric attribute, Date with a pattern for a date attribute.
@attribute du fichier.
Set the File Name, then describe in Edit schema one column per attribute, in the order of the @attribute lines of the file.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Tous les paramètres sont toujours visibles ; la troisième colonne donne leur onglet. Les comportements sont lus dans les modèles du composant, faute de pouvoir l'exécuter. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. All the settings are always shown; the third column gives their tab. The behaviors are read from the component templates, since it cannot be run.
| ParamètreSetting | DéfautDefault | OngletTab | Description |
|---|---|---|---|
| Type de propriétéProperty TypePROPERTY | Built-in | Paramètres simplesBasic settings | Built-in : les réglages sont saisis ici. Référentiel : le nom du fichier et l'encodage viennent d'une métadonnée de fichier délimité du référentiel. Built-in: the settings are typed here. Repository: the file name and the encoding come from a delimited file metadata of the Repository. |
| Nom de fichierFile NameFILENAME | chemin par défaut + /in.arffdefault path + /in.arff |
Paramètres simplesBasic settings |
Le fichier lu, en expression Java : context.folder + "/weather.arff". Il est lu en entier au démarrage du composant, avant la première ligne.
The read file, as a Java expression: context.folder + "/weather.arff". It is read entirely when the component starts, before the first row.
|
| SchémaSchemaSCHEMA | — | Paramètres simplesBasic settings | Une colonne par attribut, par position : la ne colonne reçoit le ne attribut, quel que soit son nom. Le type de la colonne choisit la lecture de la valeur (voir plus bas). One column per attribute, by position: the nth column gets the nth attribute, whatever its name. The column type chooses how the value is read (see below). |
| EncodageEncodingENCODING | "ISO-8859-15" |
Paramètres avancésAdvanced settings |
Sans effet : le modèle ouvre le fichier avec java.io.FileReader, dans l'encodage par défaut de la JVM, et n'emploie jamais ce réglage (voir les conseils).
No effect: the template opens the file with java.io.FileReader, in the default encoding of the JVM, and never uses this setting (see the tips).
|
D'après le code que génèrent les modèles pour chaque type de colonne. Le fichier est chargé par Weka (new weka.core.Instances(reader)), puis chaque instance devient une ligne du flux.
From the code that the templates generate for each column type. The file is loaded by Weka (new weka.core.Instances(reader)), then each instance becomes a row of the flow.
| Type de la colonneColumn type | Code généréGenerated code | AttributAttribute | ValeurValue |
|---|---|---|---|
| String | instance(n).stringValue(i) |
nominal, textenominal, string |
Le texte de la valeur, par exemple sunny.
The text of the value, for example sunny.
|
| Date | new SimpleDateFormat(modèlepattern).parse(stringValue(i)) |
date | Le texte de la valeur, relu avec le modèle de date de la colonne : il doit correspondre au format de l'attribut dans le fichier. The text of the value, read back with the date pattern of the column: it must match the format of the attribute in the file. |
| Integer, Double, Long, Float, Short, ByteInteger, Double, Long, Float, Short, Byte | (int) instance(n).value(i)… |
numeric |
La valeur de Weka, un double, convertie par un transtypage Java : un Integer perd les décimales sans arrondi ((int) 85.9 vaut 85). Sur un attribut nominal, Weka range le rang de la valeur dans sa liste.
The Weka value, a double, converted with a Java cast: an Integer loses the decimals without rounding ((int) 85.9 is 85). On a nominal attribute, Weka stores the rank of the value in its list.
|
| BigDecimal, Boolean…BigDecimal, Boolean… |
Ne compile pas (défaut du modèle, tFileInputARFF_begin.javajet, ligne 66) : le modèle transtype la valeur vers le type primitif de la colonne, qui n'existe pas pour un BigDecimal. Code généré pour une colonne BigDecimal, puis Boolean :
Does not compile (defect of the template, tFileInputARFF_begin.javajet, line 66): the template casts the value to the primitive type of the column, which does not exist for a BigDecimal. Code generated for a BigDecimal column, then a Boolean one:
Le premier arrête la compilation (error: ';' expected, avant même l'absence de weka) ; le second transtype un double en boolean, ce que Java refuse. Lisez ces attributs dans une colonne Double ou String, puis convertissez-les.
The first one stops the compilation (error: ';' expected, even before the missing weka); the second one casts a double to boolean, which Java refuses. Read these attributes into a Double or String column, then convert them.
|
||
NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes envoyées, d'après le modèle. NB_LINE (Integer, available after the component has run): number of rows sent, from the template.
((Integer) globalMap.get("tFileInputARFF_1_NB_LINE"))
Sans la bibliothèque weka, le job ne compile pas : il n'y a pas de sortie à montrer. Voici le fichier lu, le job essayé, et l'extrait du code Java que les modèles génèrent pour lui. Without the weka library, the job does not compile: there is no output to show. Here is the read file, the job we tried, and the excerpt of the Java code that the templates generate for it.
weather.arffThe weather.arff file@relation weather
@attribute outlook {sunny,overcast,rainy}
@attribute temperature numeric
@attribute humidity numeric
@attribute windy {TRUE,FALSE}
@attribute play {yes,no}
@data
sunny,85,85,FALSE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
Nom de fichier context.folder + "/weather.arff". Schéma : outlook String, temperature Double, humidity Integer, windy String, play String.
File Name context.folder + "/weather.arff". Schema: outlook String, temperature Double, humidity Integer, windy String, play String.
Au démarrage : le fichier est ouvert et chargé en entier par Weka. At start: the file is opened and fully loaded by Weka.
String filenametFileInputARFF_1=context.folder + "/weather.arff";
java.io.BufferedReader bufferedReader_tFileInputARFF_1 = null;
try{
bufferedReader_tFileInputARFF_1=new java.io.BufferedReader(new java.io.FileReader(filenametFileInputARFF_1));
weka.core.Instances datatFileInputARFF_1 = new weka.core.Instances(bufferedReader_tFileInputARFF_1);
datatFileInputARFF_1.setClassIndex(datatFileInputARFF_1.numAttributes()-1);
Puis une ligne par instance, une colonne par position : Then one row per instance, one column per position:
for(int lineNo=0;lineNo<datatFileInputARFF_1.numInstances();lineNo++){
row1.outlook = datatFileInputARFF_1.instance(lineNo).stringValue(0);
row1.temperature = (double)datatFileInputARFF_1.instance(lineNo).value(1);
row1.humidity = (int)datatFileInputARFF_1.instance(lineNo).value(2);
row1.windy = datatFileInputARFF_1.instance(lineNo).stringValue(3);
row1.play = datatFileInputARFF_1.instance(lineNo).stringValue(4);
Le job de l'exemple, lancé avec Talaxie le 14 novembre 2026 : la bibliothèque est cherchée dans les dépôts connus, sans succès, puis la compilation échoue. Le nom du job est remplacé par MyJob, le chemin du code est abrégé.
The job of the example, run with Talaxie on November 14, 2026: the library is looked for in the known repositories, without success, then the compilation fails. The job name is replaced with MyJob, the code path is shortened.
Downloading org/talend/libraries/weka/6.0.0/weka-6.0.0.jar Library not found: mvn:org.talend.libraries/weka/6.0.0 The job failed to compile: …\src\demo\myjob_0_1\MyJob.java:1097: error: package weka.core does not exist weka.core.Instances datatFileInputARFF_1 = new weka.core.Instances(bufferedReader_tFileInputARFF_1); ^ …\src\demo\myjob_0_1\MyJob.java:1097: error: package weka.core does not exist weka.core.Instances datatFileInputARFF_1 = new weka.core.Instances(bufferedReader_tFileInputARFF_1); ^ 2 errors
Le jar weka.jar qu'attend le composant n'est publié dans aucun dépôt public, et il n'est pas non plus dans le dépôt Maven local ni dans les dossiers des Studios Talaxie 8.9. Le même jar manque au tFileOutputARFF.
The weka.jar jar that the component expects is published in no public repository, and it is not in the local Maven repository nor in the folders of the Talaxie 8.9 Studios either. The same jar is missing for tFileOutputARFF.
Les données d'un ARFF sont des lignes de valeurs séparées par des virgules, après l'en-tête. Le fichier weather.arff de l'exemple, lu par un tFileInputDelimited : Séparateur de champs ",", En-tête 9 (les neuf lignes jusqu'à @data comprise), même schéma que le job essayé mais windy en Boolean. Sortie réelle d'une exécution :
The data of an ARFF file are lines of comma-separated values, after the header. The weather.arff file of the example, read by a tFileInputDelimited: Field Separator ",", Header 9 (the nine lines up to @data included), same schema as the job we tried but windy as Boolean. Actual output of a run:
.--------+-----------+--------+-----+----. | tLogRow_1 | |=-------+-----------+--------+-----+---=| |outlook |temperature|humidity|windy|play| |=-------+-----------+--------+-----+---=| |sunny |85.0 |85 |false|no | |overcast|83.0 |86 |false|yes | |rainy |70.0 |96 |false|yes | '--------+-----------+--------+-----+----' NB_LINE: 3
Cela suffit pour un fichier sans commentaires (%) dans les données, sans valeurs entre guillemets, sans valeurs manquantes (?) et pas au format creux ({0 X, 3 Y}) : ces cas ne se lisent pas ainsi. Le nombre de lignes d'en-tête dépend du fichier.
This is enough for a file without comments (%) in the data, without quoted values, without missing values (?) and not in the sparse format ({0 X, 3 Y}): these cases cannot be read this way. The number of header lines depends on the file.
Défaut du modèle tFileInputARFF_begin.javajet : le fichier est ouvert par new java.io.FileReader(…), sans le réglage Encodage. Les caractères accentués d'un fichier sont lus dans l'encodage par défaut de la JVM qui exécute le job (UTF-8 quand Talaxie le lance) : un fichier écrit dans un autre encodage est mal lu.
Defect of the tFileInputARFF_begin.javajet template: the file is opened with new java.io.FileReader(…), without the Encoding setting. The accented characters of a file are read in the default encoding of the JVM that runs the job (UTF-8 when Talaxie runs it): a file written in another encoding is read wrongly.
Les colonnes sont appariées aux attributs par leur rang, pas par leur nom : ajouter un attribut au début du fichier décale toutes les colonnes. Le fichier est chargé en entier avant la première ligne : un gros jeu de données occupe la mémoire du job. Columns are matched to attributes by their rank, not by their name: adding an attribute at the start of the file shifts all the columns. The file is fully loaded before the first row: a large data set uses the job memory.
tFileOutputARFF · écrire un fichier ARFFwrite an ARFF filetFileInputDelimited · lire les données d'un ARFF simpleread the data of a simple ARFFtFileInputFullRow · lire un fichier ligne par ligne, sans découpageread a file line by line, without splittingtConvertType · convertir les colonnes lues en texteconvert the columns read as texttLibraryLoad · charger un jar dans un jobload a jar in a jobtLogRow · afficher les lignes luesdisplay the rows read