12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- // librairie de gestion des répertoires et fichiers
- const fs = require("fs");
- const path = require("path");
- // librairie de gestion des fichiers csv
- var csv = require("comma-separated-values");
- // librairie de traitement du pinyin
- const pinyinizer = require('pinyinizer');
- // on crée le fichier csv de sortie
- var moncsvSortie = fs.createWriteStream("../MaineEdu-vocabulary-1.csv");
- // on crée le fichier csv d'entrée
- var moncsvEntree = "../MaineEdu-vocabulary.csv";
- // utilitaires
- var tab = "\t";
- var endLine = "\n";
- var ligneCSV = "";
- var fichierATraiter = fs.readFileSync(moncsvEntree, "UTF-8");
- var monjson = new csv(fichierATraiter, {
- header: [
- 'hanzi',
- 'traditional',
- 'pinyin',
- 'translation',
- 'classifier',
- "taiwan-pinyin",
- "sameword",
- 'example'
- ],
- cast: [
- 'String',
- 'String',
- 'String',
- 'String',
- 'String',
- 'String',
- 'String',
- 'String'
- ]
- }).parse();
- monjson.forEach(function(enregistrement){
- // console.log(enregistrement.hanzi);
- ligneCSV = "";
- // traitement de la ligne
- console.log(enregistrement.translation);
- enregistrement.translation = pinyinizer.pinyinize(enregistrement.translation);
- console.log(enregistrement.translation);
-
- ligneCSV = enregistrement.hanzi + tab +
- enregistrement.traditional + tab +
- enregistrement.pinyin + tab +
- enregistrement.translation + tab +
- enregistrement.classifier + tab +
- enregistrement.example +
- endLine;
- moncsvSortie.write(ligneCSV);
- });
|