const fs = require('fs');
const es = require('event-stream');
const _ = require('lodash');
const pyfl = require('pyfl').default;

fs.createReadStream(__dirname + '/sqlResult_2995229.csv')
  .pipe(es.split())
  .pipe(
    es.mapSync(function (line) {
      const [word, id] = line.split(',');
      if (['wx', 'mb'].every((spl) => word.indexOf(spl) == -1)) {
        if (escape(word).indexOf('%u') >= 0) {
          let newWord = word.replace(/\d/g, '');
          newWord = _.replace(word, /\"/g, '');
          if (
            newWord.length >= 3 &&
            ['XJP', 'LKQ', 'DXP', 'HJT', 'WJB', 'MZD', 'ZEL', 'JZM'].some(
              (T) => pyfl(newWord).indexOf(T) > -1
            )
          ) {
            return `"${newWord}",${id},"${pyfl(newWord)}" \n`;
          }
        }
      }
    })
  )
  .pipe(fs.createWriteStream(__dirname + '/谐音.csv'));

最后编辑时间: 6/19/2020, 8:30:59 AM