UNPKG

sai-language

Version:

An object-oriented language designed to afford code comprehension and maintenance. Transpiles in-place to Javascript.

124 lines (120 loc) 4.52 kB
#!/usr/bin/env node // Javascript source for uniques.sai transipled by SAI // "use strict"; var prototype=new function(){ this.Constructor=function(){}; this.__tobelocked=[]; this.__tobefrozen=[]; this.__contracts=[]; this.__unverified=true; this.isof={}; return this; }(); var $AI=require("sai-library"); // Generated code follows var __context={"name":"uniques.sai","loader":"SAI.GetSourceFromPaths","path":"uniques.sai","mtime":"2018-02-16T17:37:34.314Z","fetched":"2018-02-16T17:38:25.676Z"}; var _FS = require('fs'); var _ReadFile = _FS.readFileSync; var _Exit = process.exit; var isa = prototype.isa = 'Unique'; prototype.isof['Unique'] = { version: '0.0.0-unspecified', isa: isa, context: __context, type: "main" }; prototype.__tobelocked = prototype.__tobelocked.concat(["'Instantiate'", "'TallyUp'", "isa"]); prototype.__tobefrozen = prototype.__tobefrozen.concat(["isof"]); var $1g = function() { var $ = this; return { truncate: undefined, frequency: false, minimum: 0, tally: {} }; } for (var i in $1g()) { prototype[i] = "uninitialized instance attribute"; }; var $2g = prototype.Constructor || function() {}; prototype.Constructor = function() { $2g.call(this); var t = $1g(); for (var i in t) this[i] = t[i]; }; var $3g = prototype['Instantiate']; prototype['Instantiate'] = function(p) { var $_d, $_c, $5, _results, $4, $3, $2, $1, $0, _argv, $ = this; { _argv = process.argv; if (($0 = (('node' === $AI.slice_op((_argv[0]), undefined, (0 - (4))))))) { _argv.shift();; } if (($1 = (('sai-run' === $AI.slice_op((_argv[0]), undefined, (0 - (7))))))) { _argv.shift();; } _argv.shift(); if (($2 = ((_argv.length < 1)))) { $AI.debug_op('UNIQUES -- Count and display frequency of unique words (a-z plus dash)' + '\n' + '' + '\n' + 'USAGE' + '\n' + ' uniques [seed.txt] - print a markov chain generated list of random words' + '\n' + '' + '\n' + 'OPTIONS' + '\n' + ' -f, --frequency - show frequency counts for each unique word' + '\n' + ' -l, --limit [number] - limit output to how many most frequent words (default all)' + '\n' + ' -m, --minimum [number] - minimum length of word to include (default none)' + '\n' + '' + '\n' + 'EXAMPLE' + '\n' + ' uniques -l 50 countries.txt' + '\n' + '' + '\n' + 'NOTE' + '\n' + ' Results are printed to STDOUT, separated by spaces. STDIN is not accepted, you must' + '\n' + ' supply a file.' + '\n' + ''); _Exit(); } var $4; while ($4 = (_argv.shift())) { switch ($3 = ($4)) { case ('-f'): case ('--frequency'): $.frequency = true; break; case ('-l'): case ('--limit'): $.truncate = ($AI.number_op(_argv.shift())); break; case ('-m'): case ('--minimum'): $.minimum = ($AI.number_op(_argv.shift())); break; default: $.TallyUp(_ReadFile($4, 'utf8')); break; } } _results = $AI.sort_op(($AI.keys_op($.tally)), function(a, b) { var aa, bb; aa = $.tally[a]; bb = $.tally[b]; if (aa < bb) return 1; if (aa > bb) return -1; return 0; }); if (!(_results.length)) { $AI.debug_op('No words found.'); _Exit(); } if (($5 = ($.frequency))) { _results = $AI.map_op(_results, function($_v, $_k) { return '' + $_v + '(' + $.tally[$_v] + ')' }); } _results = $AI.slice_op((_results), 0, $.truncate); $AI.debug_op(_results.join(' ')); } }; var $4g = prototype['TallyUp']; prototype['TallyUp'] = function(p) { var $_d, $_c, $_b, $6, _source = p, $ = this; { $AI.drain_op($AI.map_op(((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = _source).toLowerCase()))) ? $_d : $_c)).replace(/[^a-z\-]/g, ' ')))) ? $_d : $_c)).split(/[\r\n]/)))) ? $_d : $_c), function($_v, $_k) { return $AI.audit_op($AI.filter_op(($_v.split(/\s+/)), function($_v, $_k) { return (($_v.length >= $.minimum)); }), function($_v, $_k) { $.tally[$_v] = (((undefined !== ($_b = $.tally[$_v])) ? $_b : 0) + 1); }) })); } }; $AI.finalizePrototype(prototype); if (prototype.isof[prototype.isa].type === "singleton") { prototype.Constructor(); prototype.Instantiate(); } var result=prototype.isof[prototype.isa].type === "main" ? prototype.constructor() : prototype; exports=result; try { module.exports=result; } catch(e) {}; return result;