差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
20220907_invertebrate_grouping_script_3 [2022/09/07 08:17] – 133.11.50.163 | 20220907_invertebrate_grouping_script_3 [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ``` | ||
- | var fs = require(" | ||
- | var data = fs.readFileSync('/ | ||
- | var arr = data.toString().split(" | ||
- | arr.sort(); | ||
- | var speciesNumber=arr.length | ||
- | var speciesList={} | ||
- | var processlist=speciesList | ||
- | var savelist=[] | ||
- | |||
- | var wordList=[] | ||
- | var countList=[] | ||
- | |||
- | //save the data to array | ||
- | for (var s=0; s< | ||
- | var rowKey=s+1 | ||
- | processlist[" | ||
- | } | ||
- | |||
- | //counting words | ||
- | var layer=0 | ||
- | do{ | ||
- | var counttmp=[] | ||
- | var wordListtmp=[] | ||
- | for (var s=0; s< | ||
- | var rowKey=s+1 | ||
- | var existchecker=" | ||
- | for (i=0; | ||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(" | ||
- | if (processlist[" | ||
- | existchecker=" | ||
- | var posilog=i | ||
- | } | ||
- | } | ||
- | if (existchecker==" | ||
- | counttmp[posilog]=counttmp[posilog]+1 | ||
- | } | ||
- | else{ | ||
- | wordListtmp.push(processlist[" | ||
- | counttmp.push(1) | ||
- | } | ||
- | } | ||
- | //get most counted word | ||
- | var countNumber=0 | ||
- | for (var j=0; | ||
- | if (countNumber< | ||
- | countNumber=counttmp[j] | ||
- | var indexOfCountNumber=j | ||
- | } | ||
- | var mostCountedWord=wordListtmp[indexOfCountNumber] | ||
- | } | ||
- | //keep the most counted species in processlist; | ||
- | //save other to savelist. | ||
- | savelisttmp=[] | ||
- | for (var s=0; s< | ||
- | var rowKey=s+1 | ||
- | if (mostCountedWord!==processlist[" | ||
- | savelisttmp.push(" | ||
- | delete processlist[" | ||
- | } | ||
- | } | ||
- | if (savelisttmp.length!==0){ | ||
- | savelist.push(savelisttmp) | ||
- | } | ||
- | |||
- | | ||
- | | ||
- | //save less counted words and numbers to list | ||
- | wordList.push(wordListtmp) | ||
- | countList.push(counttmp) | ||
- | layer=layer+1 | ||
- | speciesNumber=countNumber | ||
- | |||
- | |||
- | |||
- | console.log(" | ||
- | console.log(Object.keys(processlist).length) | ||
- | console.log(" | ||
- | console.log(wordList) | ||
- | console.log(" | ||
- | console.log(countList) | ||
- | console.log(" | ||
- | console.log(countNumber) | ||
- | console.log(" | ||
- | console.log(mostCountedWord) | ||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(savelist) | ||
- | console.log(" | ||
- | } | ||
- | while (countNumber> | ||
- | ``` | ||
- | is not working well | ||
- | |||
- | ``` | ||
- | / | ||
- | wordListtmp.push(processlist[" | ||
- | ^ | ||
- | |||
- | TypeError: Cannot read property ' | ||
- | at Object.< | ||
- | at Module._compile (node: | ||
- | at Object.Module._extensions..js (node: | ||
- | at Module.load (node: | ||
- | at Function.Module._load (node: | ||
- | at Function.executeUserEntryPoint [as runMain] (node: | ||
- | at node: | ||
- | pch12005m: | ||
- | ``` | ||
- | |||
- | |||
- | |||
- | |||