TSV 文字列, 矩形検証
TSV 文字列, 矩形検証 (TSV String, Verify Rectangle)
TSVのセルデータがマトリックス形状になっているか検証します。もし各行でセルデータ数が異なる場合、行末タブが追加されます。整形後の行数と列数を取得することも可能です。なお、検証後TSVの末尾に改行コードは付与されません。
Configs
  • A1: TSVをセットしてください *#{EL}
  • B1: Output TSVが格納される文字列型データ項目を選択してください (更新)
  • B2: 行数が格納される数値型データを選択してください (更新)
  • B3: 列数が格納される数値型データを選択してください (更新)
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strTsv          = configs.get( "StrConfA1" );           /// REQUIRED /////////////
  if( strTsv        === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: Tsv} is empty \n" );
  }
  const arr2dTsv      = parseAsRectangular( strTsv );
const strPocketOutput       = configs.getObject( "SelectConfB1" );  // NotRequired /////
const numPocketNumOfRows    = configs.getObject( "SelectConfB2" );  // NotRequired /////
const numPocketNumOfColumns = configs.getObject( "SelectConfB3" );  // NotRequired /////


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==

// output TSV
let strOutput = "";
for( let i = 0; i < arr2dTsv.length; i++ ){
  strOutput += arr2dTsv[i].join("\t") + "\n";
}
strOutput = strOutput.slice( 0, -1 ); // delete last "\n"


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketOutput !== null ){
  engine.setData( strPocketOutput, strOutput );
}
if( numPocketNumOfRows !== null ){
  engine.setData( numPocketNumOfRows, new java.math.BigDecimal( arr2dTsv.length ) );
}
if( numPocketNumOfColumns !== null ){
  engine.setData( numPocketNumOfColumns, new java.math.BigDecimal( arr2dTsv[0].length ) );
}


} //////// END "main()" /////////////////////////////////////////////////////////////////


// Parses TSV string as two-dimensional rectangular data matrix and creates a 2D array.
function parseAsRectangular( strTsv ){
  const arrTsv = strTsv.split("\n");

  /// Get numMinWidth and numMaxWidth (blank lines are excluded)
  let numMinWidth   = Infinity; // cf. String-Type Max: 1 million
  let numMaxWidth   = 0;
  let numBlanklines = 0;
  for( let i = 0; i < arrTsv.length; i++ ){
    if( arrTsv[i] === "" ){ // Skip blank lines
      numBlanklines += 1;
      continue;
    }
    let arrCells = arrTsv[i].split("\t");
    if( numMinWidth > arrCells.length ){ numMinWidth = arrCells.length; }
    if( numMaxWidth < arrCells.length ){ numMaxWidth = arrCells.length; }
  }
  engine.log( " AutomatedTask TsvDataCheck:" + 
              " MinWidth:" + numMinWidth +
              " MaxWidth:" + numMaxWidth +
              " Lines:" + arrTsv.length +
              " (BlankLines:" + numBlanklines + ")" );

  /// Get numMinWidth and numMaxWidth (blank lines are excluded)
  let arr2dTsv      = [];
  for( let i = 0; i < arrTsv.length; i++ ){
    if( arrTsv[i] === "" ){ // Skip blank lines
      continue;
    }
    let arrTmp = [];
    let arrCells = arrTsv[i].split("\t");
    for( let j = 0; j < numMaxWidth; j++ ){
      if( j < arrCells.length ){
        arrTmp[j] = arrCells[j];
      }else{
        arrTmp[j] = "";
      }
    }
    arr2dTsv.push( arrTmp );
  }

  return arr2dTsv;
}

/*
Notes:
- When the process reaches this automated task, TSV is automatically read.
    - TSV: Monthly sales, monthly access log, etc.
- If there is a blank line in the input TSV text, it will be skipped.
    - The output TSV is rectangular data. There are no blank lines.
    - No line feed code is added to the last line of the output TSV.

APPENDIX:
- TSV data that is not rectangular is automatically formatted with an empty string.
    - Tabs are added according to the row with the largest number of columns.
    - However, lines with only line breaks (blank lines) are skipped.


Notes-ja:
- 案件が自動処理工程に到達した際、文字列型データに保存されているTSVが自動的に読み込まれます。
    - TSV: 月次売上、月次アクセスログ、など
- 入力TSVテキストに空行がある場合、スキップされます。
    - 出力TSVは矩形データとなります。空行は存在しません。
    - 出力TSVの最終行に改行コードは付与されません。

APPENDIX-ja:
- 矩形でないTSVデータは、空文字によって自動整形されます。
    - もっとも列数(タブ数)が多い行にあわせて、タブが追加されます。
    - ただし、改行のみの行(空行)は、スキップされます。
*/

Download

Addonファイルのインポートは Professional でのみご利用いただけます。
自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。

Notes

  • 案件が自動処理工程に到達した際、文字列型データに保存されているTSVが自動的に読み込まれます。
    • TSV: 月次売上、月次アクセスログ、など
  • 入力TSVテキストに空行がある場合、スキップされます。
    • 出力TSVは矩形データとなります。空行は存在しません。
    • 出力TSVの最終行に改行コードは付与されません。

Capture

TSVのセルデータがマトリックス形状になっているか検証します。もし各行でセルデータ数が異なる場合、行末タブが追加されます。整形後の行数と列数を取得することも可能です。なお、検証後TSVの末尾に改行コードは付与されません。
TSVのセルデータがマトリックス形状になっているか検証します。もし各行でセルデータ数が異なる場合、行末タブが追加されます。整形後の行数と列数を取得することも可能です。なお、検証後TSVの末尾に改行コードは付与されません。

Appendix

  • 矩形でないTSVデータは、空文字によって自動整形されます。
    • もっとも列数(タブ数)が多い行にあわせて、タブが追加されます。
    • ただし、改行のみの行(空行)は、スキップされます。

See also

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

%d