diff --git a/src/rita.js b/src/rita.js index 0560e903..e563428a 100755 --- a/src/rita.js +++ b/src/rita.js @@ -4,7 +4,6 @@ var _VERSION_ = '##version##'; - /* @private Simple type-checking functions */ var Type = { N: 'number', @@ -46,7 +45,7 @@ var RiText = {}; - RiText._graphics = function() {}; // return undef + RiText._graphics = function() {}; // //////////////////////////////////////////////////////////// // RiTa object (singleton) @@ -63,7 +62,7 @@ /* For tokenization, Can't -> Can not, etc. */ SPLIT_CONTRACTIONS: false, - // :::: For RiTaEvents ::::::::: + // For RiTaEvents ================================= MOVE_TO: "MoveTo", COLOR_TO: "ColorTo", @@ -156,8 +155,6 @@ // Start Methods ================================= - start: function() { /* no-op, just for api */ }, - untokenize: function(arr, delim, adjustPunctuationSpacing) { delim = delim || SP; @@ -207,80 +204,6 @@ return Math.sqrt(dx * dx + dy * dy); }, - // TODO: test (with and w'out callback) - timer: function(period, callback) { - - var a = arguments, - id, timer; - - // if 1st arg is an object (e.g., 'this'), ignore it... - if (a.length && is(a[0], O)) - a = Array.prototype.slice.call(a, 1); - - if (a.length < 1) - throw Error("Bad args to RiTa.timer(" + a + ")"); - - callback = a.length > 1 ? a[1] : null; - - // TODO: need to pass Id to RiTaEvent here (to match Java-API[or change Java**]) - timer = new Timer( - function() { - RiTaEvent(RiTa, 'tick')._fire(callback); - }, [a[0]] * 1000, true); - - timer.go(); - id = timer.id(); - timers[id] = timer; - - return id; - }, - - // TODO: test - stopTimer: function(id) { - - // TODO: THIS DEFINITELY BROKEN - if (timers[id]) - timers[id].stop(); - else - warn('no timer with id: ' + id); - }, - - // TODO: test - pauseTimer: function(id, pauseSec) { - - //console.log("id: "+id); - - pauseSec = is(pauseSec, N) ? pauseSec : Number.MAX_VALUE; - - if (timers[id]) { - - timers[id].pause(); - - var theId = id; - - //console.log("OK-theId: "+theId); - - setTimeout(function() { - if (timers[theId]) - timers[theId].play(); - else - warn("no timer!!!"); - }, pauseSec * 1000); - - return theId; - } else { - - warn('no timer with id: ' + id); - } - - return -1; - }, - - _isPosTag: function(tag) { - - return PosTagger.isTag(tag); - }, - _tagForPENN: function(words) { if (!words || !words.length) return EA; @@ -333,25 +256,6 @@ return sb.trim(); }, - // TODO: example - posToWordNet: function(tag) { - - if (!strOk(tag)) return E; - - if (PosTagger.isNoun(tag)) - return 'n'; - else if (PosTagger.isVerb(tag)) - return 'v'; - else if (PosTagger.isAdverb(tag)) - return 'r'; - else if (PosTagger.isAdj(tag)) - return 'a'; - else { - warn(tag + " is not a valid pos-tag"); - return '-'; - } - }, - getPresentParticiple: function(verb) { // TODO: need to call stem() and try again if first try fails @@ -376,7 +280,8 @@ return s.charAt(0).toUpperCase() + s.substring(1); }, - // TODO: 2 examples (regular & irregular) in javadoc + // TODO: 2 examples (regular & irregular) in docs + pluralize: function(word) { if (!strOk(word)) return E; @@ -397,13 +302,12 @@ return DEFAULT_PLURAL_RULE.fire(word); }, - // TODO: 2 examples (regular & irregular) in javadoc + // TODO: 2 examples (regular & irregular) in docs singularize: function(word) { if (!strOk(word)) return E; - //// TODO: WHY IS THIS NOT IN JAVA? //// var i, rule, rules = SINGULAR_RULES; if (inArray(MODALS, word.toLowerCase())) { @@ -429,7 +333,8 @@ tokenize: function(words, regex) { - //TODO: 2 examples for doc comment, one with 1 arg, one with 2 (a regex that splits on spaces) + //TODO: 2 examples for doc comment, one with 1 arg, + // one with 2 (a regex that splits on spaces) if (regex) return words.split(regex); @@ -473,7 +378,6 @@ return trim(words).split(/\s+/); // DCH: fixed bug here, 6/3/12 }, - // TODO: test and (probably) re-implement from RiTa (RiSplitter.java) splitSentences: function(text, regex) { var arr = text.match(/(\S.+?[.!?])(?=\s+|$)/g); @@ -481,33 +385,6 @@ return (text.length && arr && arr.length) ? arr : [text]; }, - /* - * Returns true if and only if the string matches 'pattern' - * - * @param {string} string string to test - * @param {string | regex} pattern object containing regular expression - * @returns {boolean} true if matched, else false - */ - _regexMatch: function(string, pattern) { - - if (!string || !pattern) - return false; - - if (typeof pattern === S) - pattern = new RegExp(pattern); - - return pattern.test(string); - }, - - _regexReplace: function(string, pattern, replacement) { - - if (!string || !pattern) - return E; - if (typeof pattern === S) - pattern = new RegExp(pattern); // TODO: is this necessary? - return string.replace(pattern, replacement); - }, - isAbbreviation: function(input, caseSensitive) { caseSensitive = caseSensitive || false; @@ -515,7 +392,6 @@ return inArray(this.ABBREVIATIONS, input); }, - // TODO: make sure this is getting tested _loadStringNode: function(url, callback, linebreakChars) { var data = '', @@ -540,9 +416,9 @@ }); }; - //var req = require('http').get(url, httpcb); // or this? var req = require('http').request(url, httpcb); - req.on('socket', function(socket) { // shouldnt be needded + req.on('socket', function(socket) { // shouldnt be needed + socket.setTimeout(3000); // ? socket.on('timeout', function() { req.abort(); @@ -550,11 +426,13 @@ }); }); req.end(); + } else { // try with node file-system var rq = require('fs'); rq.readFile(url, function(e, data) { + if (e || !data) { err("[Node] Error reading file: " + url + "\n" + e); throw e; @@ -562,6 +440,7 @@ data = data.toString('utf-8').replace(/[\r\n]+/g, lb).trim(); me.fireDataLoaded(url, callback, data); }); + } }, @@ -609,7 +488,6 @@ } data = htmlDecode(data.replace(/[\r\n]+/g, lb).trim()); - me.fireDataLoaded(url, callback, data); }; }, @@ -628,7 +506,6 @@ }, - // TODO: add NodeJS tests for all loadXX methods loadString: function(url, callback, linebreakChars) { ok(url, S); @@ -785,8 +662,12 @@ for (var z = 0; z < num; z++) o.push(z); - // Array shuffle, from Jonas Raoni Soares Silva (http://jsfromhell.com/array/shuffle) - for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x) {} + // Array shuffle, from Jonas Raoni Soares Silva + // (http://jsfromhell.com/array/shuffle) + for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), + x = o[--i], o[i] = o[j], o[j] = x) { + + } } return o; @@ -879,7 +760,7 @@ stem: function(word, type) { - type = type || 'Lancaster'; // USE CONSTANTS + type = type || 'Lancaster'; if (type != 'Lancaster' && type != 'Porter' && type != 'Pling') err('Bad stemmer type: ' + type); @@ -903,57 +784,6 @@ return res.join(SP); }, - p5Compatible: function(value) { // TODO: remove? yes, no one cares (cnage to autoLoop() or similar) - - if (!arguments.callee.setupAndDraw) { - - arguments.callee.setupAndDraw = function() { - if (typeof window.setup == F) window.setup(); - if (typeof window.draw == F && typeof RiText.loop == F) RiText.loop(); - }; - } - - if (typeof window != 'undefined' && window) { - - // TODO: add mouse-handling methods here? - if (typeof window.mouseClicked == F) - window.onmouseup = window.mouseClicked; - if (typeof window.mousePressed == F) - window.onmousedown = window.mousePressed; - if (typeof window.mouseReleased == F) - window.onmouseup = window.mouseReleased; - if (typeof window.mouseMoved == F) - window.onmousemove = window.mouseMoved; - } - - if (value) { - - if (typeof window != 'undefined' && window && !hasProcessing) { - - if (!window.UP) window.UP = RiTa.UP; - if (!window.DOWN) window.DOWN = RiTa.DOWN; - if (!window.LEFT) window.LEFT = RiTa.LEFT; - if (!window.RIGHT) window.RIGHT = RiTa.RIGHT; - if (!window.CENTER) window.CENTER = RiTa.CENTER; - - if (!window.onload) window.onload = arguments.callee.setupAndDraw; - } - } else { // non-compatible mode (clear extra stuff) - - if (typeof window != 'undefined' && window && !hasProcessing) { - - // are you sure about this? - if (window.UP === RiTa.UP) delete window.UP; - if (window.DOWN === RiTa.DOWN) delete window.DOWN; - if (window.LEFT === RiTa.LEFT) delete window.LEFT; - if (window.RIGHT === RiTa.RIGHT) delete window.RIGHT; - if (window.CENTER === RiTa.CENTER) delete window.CENTER; - if (window.onload && (window.onload == arguments.callee.setupAndDraw)) - window.onload = undefined; // ? - } - } - }, - // Converts 'input' to Titlecase (1st letter upper, rest lower) _titleCase: function(input) { @@ -966,7 +796,7 @@ * Takes pair of strings or string-arrays and returns the min-edit distance * @param normalized based on max-length if 3rd (optional) parameter is true (default=f). */ - minEditDist: function(a, b, adjusted) { // TODO: add to docs/tests + minEditDist: function(a, b, adjusted) { var fun = !adjusted ? MinEditDist.computeRaw : MinEditDist.computeAdjusted; return fun.call(MinEditDist, a, b); @@ -980,12 +810,9 @@ var RiMarkov = makeClass(); - /* constant for max # of tries for a generation */ RiMarkov.MAX_GENERATION_ATTEMPTS = 1000; - RiMarkov._SSRE = /"?[A-Z][a-z"',;`-]*/; - - RiMarkov._SSDLM = 'D=l1m_'; // TODO: (OR use HTML-style tag) ?? + RiMarkov._SSDLM = 'D=l1m_'; RiMarkov.prototype = { @@ -1410,7 +1237,6 @@ _tracePathFromRoot: function(node) { - // (TODO: change this node.pathFromRoot(this.pathTrace); this.pathTrace.pop(); // ignore the first element @@ -1419,13 +1245,12 @@ var search = this.pathTrace.pop(); mn = mn.lookup(search); } + return mn; }, _nextNodeForArr: function(previousTokens) { - //if (!is(previousTokens,A)) return this.root; - // Follow the seed path down the tree var firstLookupIdx = Math.max(0, previousTokens.length - (this._n - 1)), node = this.root.lookup(previousTokens[firstLookupIdx++]); @@ -1444,30 +1269,24 @@ var attempts = 0, selector, pTotal = 0, nodes = current.childNodes(), - MAX_PROB_MISSES = 1000; + maxProbMisses = 1000; while (true) { pTotal = 0; selector = Math.random(); - //console.log("current="+current+", selector="+selector); for (var i = 0, j = nodes.length; i < j; i++) { var child = nodes[i]; - //console.log("child="+child); pTotal += child.probability(); - //console.log("pTotal="+pTotal); if (current.isRoot() && (this.isSentenceAware && !child.isSentenceStart())) { - //console.log("continuing..."); continue; } if (selector < pTotal) { - //console.log("returning "+child+"\n===================="); return child; } - //console.log("selector >= pTotal\n===================="); } attempts++; @@ -1475,7 +1294,7 @@ ' Make sure there are a sufficient\n # of sentences' + ' in the model that are longer than \'minSentenceLength\''); - if (attempts == MAX_PROB_MISSES) // should never happen + if (attempts == maxProbMisses) // should never happen err('PROB. MISS' + current + ' total=' + pTotal + ' selector=' + selector); } }, @@ -1564,12 +1383,8 @@ _addSentenceSequence: function(toAdd) { - //log("_addSentenceSequence: "+toAdd.length); - var node = this.root; - //this.root.count += toAdd.length; // here? - for (var i = 0; i < toAdd.length; i++) { if (!toAdd[i]) continue; @@ -1612,8 +1427,6 @@ _findNode: function(path) { - //log("RiMarkov.findNode("+path.toString()+")"); - if (!path || !is(path, A) || !path.length) return null; @@ -1774,14 +1587,18 @@ console.log('[RiTa] Loading lexicon data...'); - RiLexicon.data = {}; // TODO: test perf. of this + RiLexicon.data = _RiTa_DICT; + + /*RiLexicon.data = {}; // changed 6/20/15 DCH for (var word in _RiTa_DICT) { RiLexicon.data[word] = _RiTa_DICT[word]; // needed? - } + }*/ + } else { if (!RiLexicon.emittedWarning) - warn("RiTa lexicon appears to be missing! Part-of-speech tagging (at least) will be inaccurate"); + warn('RiTa lexicon appears to be missing! Part-of-speech tagging (at least) will be inaccurate'); + RiLexicon.emittedWarning = true } }, @@ -2268,8 +2085,6 @@ _getRawPhones: function(word, useLTS) { - // TODO: test this with useLTS=true - var phones, data = this._lookupRaw(word); useLTS = useLTS || false; @@ -2310,14 +2125,11 @@ return (pl.length > 0) ? pl[0] : []; }, - - _firstConsonant: function(rawPhones) { if (!strOk(rawPhones)) return E; var phones = rawPhones.split(RiTa.PHONEME_BOUNDARY); - // var phones = rawPhones.split(PHONEME_BOUNDARY); if (phones) { @@ -2329,7 +2141,6 @@ return E; // return null? }, - _lastStressedPhoneToEnd: function(word, useLTS) { if (!strOk(word)) return E; // return null? @@ -3007,17 +2818,13 @@ substr: function(start, length) { return this._text.substr(start, length); - // return this.text(res); }, - substring: function(from, to) { - // return this.text(this._text.substring(from, to)); return this._text.substring(from, to); }, - toLowerCase: function() { return this.text(this._text.toLowerCase()); @@ -3199,17 +3006,15 @@ delete this._rules[name]; return this; - }, - _copy: function() { // NIAPI + _copy: function() { var tmp = RiGrammar(); for (var name in this._rules) { tmp._rules[name] = this._rules[name]; } return tmp; - }, reset: function() { @@ -3446,7 +3251,6 @@ return null; // no rules matched }, - // private?? (add structure test case) _getStochasticRule: function(temp) { // map var name, dbug = false; @@ -3880,121 +3684,6 @@ ////////////////////////// PRIVATE CLASSES /////////////////////////////// - - // //////////////////////////////////////////////////////////// - // Timer - // //////////////////////////////////////////////////////////// - - var timers = {}; // static - - // Timer - modified from Resig's JQuery-Timer - var Timer = function(func, time, autostart) { - - this.timerImpl = isNode() ? require("timers") : window; - - this.set = function(func, time, autostart) { - - this.init = true; - if (typeof func == 'function') this.action = func; - if (!isNaN(time)) this.intervalTime = time; - if (autostart && !this.isActive) { - this.isActive = true; - this.setTimer(); - } - return this; - }; - - this.once = function(time) { - - var timer = this; - if (isNaN(time)) time = 0; - this.timerImpl.setTimeout(function() { - timer.action(); - }, time); - return this; - }; - - this.play = function(reset) { - - if (!this.isActive) { - if (reset) this.setTimer(); - else this.setTimer(this.remaining); - this.isActive = true; - } - return this; - }; - - this.pause = function() { - - if (this.isActive) { - this.isActive = false; - this.remaining -= new Date() - this.last; - this.clearTimer(); - } - return this; - }; - - this.stop = function() { - - this.isActive = false; - this.remaining = this.intervalTime; - this.clearTimer(); - return this; - }; - - this.toggle = function(reset) { - - if (this.isActive) this.pause(); - else if (reset) this.play(true); - else this.play(); - return this; - }; - - this.reset = function() { - - this.isActive = false; - this.play(true); - return this; - }; - - this.id = function() { - - return this.timeoutId; - }; - - this.clearTimer = function() { // private - - this.timerImpl.clearTimeout(this.timeoutId); - }; - - this.setTimer = function(time) { - - var timer = this; - - if (typeof this.action != 'function') - return; - - if (isNaN(time)) time = this.intervalTime; - this.remaining = time; - this.last = new Date(); - this.clearTimer(); - this.timeoutId = this.timerImpl.setTimeout(function() { - timer.go(); - }, time); - }; - - this.go = function() { - - if (this.isActive) { - this.action(); - this.setTimer(); - } - }; - - return (this.init) ? new Timer(func, time, autostart) : - this.set(func, time, autostart); - }; - // //////////////////////////////////////////////////////////// // TextNode // //////////////////////////////////////////////////////////// @@ -4245,8 +3934,6 @@ init: function() { - // TODO: get rid of these and make static method ? - this.perfect = this.progressive = this.passive = this.interrogative = false; this.tense = RiTa.PRESENT_TENSE; this.person = RiTa.FIRST_PERSON; @@ -5628,7 +5315,6 @@ })(); - // TODO: remove these eventually Array.prototype._arrayContains = function(ele) { return (Array.prototype.indexOf(ele) > -1); }; @@ -5760,6 +5446,7 @@ // -us to -i if (categoryUS_I._arrayContains(s)) return (cut(s, "i") + "us"); + //Wrong plural if (s._endsWith("uses") && (categoryUS_I._arrayContains(cut(s, "uses") + "i") || s === ("genuses") || s === ("corpuses"))) return (cut(s, "es")); @@ -6150,7 +5837,7 @@ var C = "[bcdfghjklmnpqrstvwxyz]", VL = "[lraeiou]"; - var PLURAL_RULES = [ // TODO: extract all these consts to single file for js/java + var PLURAL_RULES = [ NULL_PLURALS, RE("^(piano|photo|solo|ego|tobacco|cargo|golf|grief)$", 0, "s"), RE("^(wildlife)$", 0, "s"), @@ -6935,14 +6622,12 @@ if (!is(str, S)) return false; return new RegExp(ending + '$').test(str); - //return str.slice(-ending.length) == ending; } function startsWith(str, starting) { if (!is(str, S)) return false; return new RegExp('^' + starting).test(str); - //return text.slice(0, substr.length) == substr; } function equalsIgnoreCase(str1, str2) { diff --git a/test/RiTa-tests.js b/test/RiTa-tests.js index 5f26084a..cf7ba4f4 100755 --- a/test/RiTa-tests.js +++ b/test/RiTa-tests.js @@ -3,785 +3,793 @@ /*jshint loopfunc: true */ -var testResults = [ - { - testName : 'testGetSyllables', - testMethod : 'RiTa.getSyllables', // static - testClass : 'RiTa', - assertion : 'equal', - tests : [ - { input: '', output: '' }, - { input: 'The Laggin Dragon', output: 'dh-ax l-ae/g-ih-n d-r-ae-g/aa-n' }, - { input: 'The emperor had no clothes on.', output: 'dh-ax eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n .' }, - { input: 'The dog ran faster than the other dog. But the other dog was prettier.', output: 'dh-ax d-ao-g r-ae-n f-ae-s/t-er dh-ae-n dh-ax ah-dh/er d-ao-g . b-ah-t dh-ax ah-dh/er d-ao-g w-aa-z p-r-ih-t/iy/er .' }, - { input: '@#$%&*()', output: '@ # $ % ae-n-d * ( )' } - ] - } -]; +var testResults = [{ + testName: 'testGetSyllables', + testMethod: 'RiTa.getSyllables', // static + testClass: 'RiTa', + assertion: 'equal', + tests: [{ + input: '', + output: '' + }, { + input: 'The Laggin Dragon', + output: 'dh-ax l-ae/g-ih-n d-r-ae-g/aa-n' + }, { + input: 'The emperor had no clothes on.', + output: 'dh-ax eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n .' + }, { + input: 'The dog ran faster than the other dog. But the other dog was prettier.', + output: 'dh-ax d-ao-g r-ae-n f-ae-s/t-er dh-ae-n dh-ax ah-dh/er d-ao-g . b-ah-t dh-ax ah-dh/er d-ao-g w-aa-z p-r-ih-t/iy/er .' + }, { + input: '@#$%&*()', + output: '@ # $ % ae-n-d * ( )' + }] +}]; var runtests = function() { - var SILENT = 1, WITHOUT_YAML = typeof YAML == 'undefined'; + var SILENT = 1, + WITHOUT_YAML = typeof YAML == 'undefined'; QUnit.module("RiTa", { - setup: function() {}, - teardown: function() {} - }); + setup: function() {}, + teardown: function() {} + }); // ------------------------------------------------------------------------ test("testGetSyllables", function() { // new-style - var func = RiTa.getSyllables, - tests = testResults[0].tests; - - for (var i=0, len = tests.length; i< len; i++) { - - equal( func(tests[i].input), tests[i].output ); - } - }); - + var func = RiTa.getSyllables, + tests = testResults[0].tests; + + for (var i = 0, len = tests.length; i < len; i++) { + + equal(func(tests[i].input), tests[i].output); + } + }); + test("testGetSyllablesOrig", function() { // old-style - var result, txt, answer; - - result = RiTa.getSyllables(''); - answer = ''; - equal(result, answer); - - txt = 'The dog ran faster than the other dog. But the other dog was prettier.'; - result = RiTa.getSyllables(txt); - answer = 'dh-ax d-ao-g r-ae-n f-ae-s/t-er dh-ae-n dh-ax ah-dh/er d-ao-g . b-ah-t dh-ax ah-dh/er d-ao-g w-aa-z p-r-ih-t/iy/er .'; - equal(result, answer); - - txt = 'The emperor had no clothes on.'; - result = RiTa.getSyllables(txt); - answer = 'dh-ax eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n .'; - equal(result, answer); - - txt = 'The Laggin Dragon'; - result = RiTa.getSyllables(txt); - answer = 'dh-ax l-ae/g-ih-n d-r-ae-g/aa-n'; - equal(result, answer); - - result = RiTa.getSyllables('@#$%&*()'); - answer = '@ # $ % ae-n-d * ( )'; - equal(result, answer); - }); - + var result, txt, answer; + + result = RiTa.getSyllables(''); + answer = ''; + equal(result, answer); + + txt = 'The dog ran faster than the other dog. But the other dog was prettier.'; + result = RiTa.getSyllables(txt); + answer = 'dh-ax d-ao-g r-ae-n f-ae-s/t-er dh-ae-n dh-ax ah-dh/er d-ao-g . b-ah-t dh-ax ah-dh/er d-ao-g w-aa-z p-r-ih-t/iy/er .'; + equal(result, answer); + + txt = 'The emperor had no clothes on.'; + result = RiTa.getSyllables(txt); + answer = 'dh-ax eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n .'; + equal(result, answer); + + txt = 'The Laggin Dragon'; + result = RiTa.getSyllables(txt); + answer = 'dh-ax l-ae/g-ih-n d-r-ae-g/aa-n'; + equal(result, answer); + + result = RiTa.getSyllables('@#$%&*()'); + answer = '@ # $ % ae-n-d * ( )'; + equal(result, answer); + }); + // ------------------------------------------------------------------------ - + test("testConstants", function() { - ok(RiTa.VERSION); - }); + ok(RiTa.VERSION); + }); test("testMinEditDist", function() { - var arr1 = ['The', 'dog', 'ate'], - arr2 = ['The', 'cat', 'ate']; - equal(RiTa.minEditDist(arr1, arr2, false), 1); - equal(RiTa.minEditDist(arr1, arr2, true), 1 / 3.0); + var arr1 = ['The', 'dog', 'ate'], + arr2 = ['The', 'cat', 'ate']; + equal(RiTa.minEditDist(arr1, arr2, false), 1); + equal(RiTa.minEditDist(arr1, arr2, true), 1 / 3.0); - var arr1 = ['The', 'dog', 'ate'], - arr2 = []; - equal(RiTa.minEditDist(arr1, arr2, false), 3); - equal(RiTa.minEditDist(arr1, arr2, true), 1); + var arr1 = ['The', 'dog', 'ate'], + arr2 = []; + equal(RiTa.minEditDist(arr1, arr2, false), 3); + equal(RiTa.minEditDist(arr1, arr2, true), 1); - var arr1 = 'The dog', - arr2 = 'The cat'; - equal(RiTa.minEditDist(arr1, arr2, false), 3); - equal(RiTa.minEditDist(arr1, arr2, true), 3 / 7); + var arr1 = 'The dog', + arr2 = 'The cat'; + equal(RiTa.minEditDist(arr1, arr2, false), 3); + equal(RiTa.minEditDist(arr1, arr2, true), 3 / 7); - var arr1 = 'The dog', - arr2 = ''; - equal(RiTa.minEditDist(arr1, arr2, false), 7); - equal(RiTa.minEditDist(arr1, arr2, true), 1); - }); + var arr1 = 'The dog', + arr2 = ''; + equal(RiTa.minEditDist(arr1, arr2, false), 7); + equal(RiTa.minEditDist(arr1, arr2, true), 1); + }); test("testEnv", function() { - var mode = RiTa.env(); - var inNode = (typeof module != 'undefined' && module.exports); - inNode && ok(mode == RiTa.NODE); + var mode = RiTa.env(); + var inNode = (typeof module != 'undefined' && module.exports); + inNode && ok(mode == RiTa.NODE); - var inBrowser = typeof window != 'undefined'; - inBrowser && ok(mode == RiTa.JS); - }); + var inBrowser = typeof window != 'undefined'; + inBrowser && ok(mode == RiTa.JS); + }); test("testIsAbbreviation", function() { - ok(RiTa.isAbbreviation("Dr.")); - ok(RiTa.isAbbreviation("dr.")); - //T in processing - - ok(!RiTa.isAbbreviation("DR.")); - // F in Processing.lowercase is true but uppercase is false - ok(!RiTa.isAbbreviation("Dr. ")); - //space - ok(!RiTa.isAbbreviation(" Dr.")); - //space - ok(!RiTa.isAbbreviation(" Dr.")); - //double space - ok(!RiTa.isAbbreviation("Dr. ")); - //double space - ok(!RiTa.isAbbreviation(" Dr.")); - //tab space - ok(!RiTa.isAbbreviation("Dr. ")); - //tab space - ok(!RiTa.isAbbreviation("Dr")); - ok(!RiTa.isAbbreviation("Doctor")); - ok(!RiTa.isAbbreviation("Doctor.")); - - ok(RiTa.isAbbreviation("Prof.")); - ok(RiTa.isAbbreviation("prof.")); - //T in processing - ok(!RiTa.isAbbreviation("PRFO.")); - // F in Processing. lowercase is true but uppercase is false - ok(!RiTa.isAbbreviation("PrFo.")); - // F in Processing. lowercase is true but uppercase is false - ok(!RiTa.isAbbreviation("Professor")); - ok(!RiTa.isAbbreviation("professor")); - ok(!RiTa.isAbbreviation("PROFESSOR")); - ok(!RiTa.isAbbreviation("Professor.")); - - ok(!RiTa.isAbbreviation("@#$%^&*()")); - - ok(!RiTa.isAbbreviation("")); - ok(!RiTa.isAbbreviation(null)); - ok(!RiTa.isAbbreviation(undefined)); - ok(!RiTa.isAbbreviation(1)); - }); + ok(RiTa.isAbbreviation("Dr.")); + ok(RiTa.isAbbreviation("dr.")); + //T in processing + + ok(!RiTa.isAbbreviation("DR.")); + // F in Processing.lowercase is true but uppercase is false + ok(!RiTa.isAbbreviation("Dr. ")); + //space + ok(!RiTa.isAbbreviation(" Dr.")); + //space + ok(!RiTa.isAbbreviation(" Dr.")); + //double space + ok(!RiTa.isAbbreviation("Dr. ")); + //double space + ok(!RiTa.isAbbreviation(" Dr.")); + //tab space + ok(!RiTa.isAbbreviation("Dr. ")); + //tab space + ok(!RiTa.isAbbreviation("Dr")); + ok(!RiTa.isAbbreviation("Doctor")); + ok(!RiTa.isAbbreviation("Doctor.")); + + ok(RiTa.isAbbreviation("Prof.")); + ok(RiTa.isAbbreviation("prof.")); + //T in processing + ok(!RiTa.isAbbreviation("PRFO.")); + // F in Processing. lowercase is true but uppercase is false + ok(!RiTa.isAbbreviation("PrFo.")); + // F in Processing. lowercase is true but uppercase is false + ok(!RiTa.isAbbreviation("Professor")); + ok(!RiTa.isAbbreviation("professor")); + ok(!RiTa.isAbbreviation("PROFESSOR")); + ok(!RiTa.isAbbreviation("Professor.")); + + ok(!RiTa.isAbbreviation("@#$%^&*()")); + + ok(!RiTa.isAbbreviation("")); + ok(!RiTa.isAbbreviation(null)); + ok(!RiTa.isAbbreviation(undefined)); + ok(!RiTa.isAbbreviation(1)); + }); test("testIsQuestion", function() { - ok(RiTa.isQuestion("what")); - ok(RiTa.isQuestion("what")); - ok(RiTa.isQuestion("what is this")); - ok(RiTa.isQuestion("what is this?")); - ok(RiTa.isQuestion("Does it?")); - ok(RiTa.isQuestion("Is this yours?")); - - ok(RiTa.isQuestion("Are you done?")); - // if "is" is true, "Are" should also be True (NICE!) - - ok(RiTa.isQuestion("what is this?")); - //extra space - ok(RiTa.isQuestion(" what is this? ")); - //extra space - ok(RiTa.isQuestion("what is this?")); - //extra double space - ok(RiTa.isQuestion("what is this?")); - //extra tab - ok(RiTa.isQuestion("what is this? , where is that?")); - ok(!RiTa.isQuestion("That is not a toy This is an apple")); - ok(!RiTa.isQuestion("string")); - ok(!RiTa.isQuestion("?")); - ok(!RiTa.isQuestion("")); - }); + ok(RiTa.isQuestion("what")); + ok(RiTa.isQuestion("what")); + ok(RiTa.isQuestion("what is this")); + ok(RiTa.isQuestion("what is this?")); + ok(RiTa.isQuestion("Does it?")); + ok(RiTa.isQuestion("Is this yours?")); + + ok(RiTa.isQuestion("Are you done?")); + // if "is" is true, "Are" should also be True (NICE!) + + ok(RiTa.isQuestion("what is this?")); + //extra space + ok(RiTa.isQuestion(" what is this? ")); + //extra space + ok(RiTa.isQuestion("what is this?")); + //extra double space + ok(RiTa.isQuestion("what is this?")); + //extra tab + ok(RiTa.isQuestion("what is this? , where is that?")); + ok(!RiTa.isQuestion("That is not a toy This is an apple")); + ok(!RiTa.isQuestion("string")); + ok(!RiTa.isQuestion("?")); + ok(!RiTa.isQuestion("")); + }); test("testIsSentenceEnd", function() { - var words = 'The dog ate the small baby. Then it threw up.'.split(' '); - ok(RiTa.isSentenceEnd(words[5], words[6])); // true - ok(!RiTa.isSentenceEnd(words[3], words[4])); // false - ok(!RiTa.isSentenceEnd(words[6], words[7])); // false - ok(!RiTa.isSentenceEnd('', '')); // false + var words = 'The dog ate the small baby. Then it threw up.'.split(' '); + ok(RiTa.isSentenceEnd(words[5], words[6])); // true + ok(!RiTa.isSentenceEnd(words[3], words[4])); // false + ok(!RiTa.isSentenceEnd(words[6], words[7])); // false + ok(!RiTa.isSentenceEnd('', '')); // false - // TODO: needs more tests - }); + // TODO: needs more tests + }); test("testIsW_Question", function() { - ok(RiTa.isW_Question("What the")); - ok(RiTa.isW_Question("What is it")); - ok(RiTa.isW_Question("how is it?")); - ok(RiTa.isW_Question("will is it.")); - ok(RiTa.isW_Question("Where is it?")); - ok(RiTa.isW_Question("How is it.")); + ok(RiTa.isW_Question("What the")); + ok(RiTa.isW_Question("What is it")); + ok(RiTa.isW_Question("how is it?")); + ok(RiTa.isW_Question("will is it.")); + ok(RiTa.isW_Question("Where is it?")); + ok(RiTa.isW_Question("How is it.")); - ok(!RiTa.isW_Question("Does it?")); - ok(!RiTa.isW_Question("Is this yours?")); - ok(!RiTa.isW_Question("Are you done?")); - ok(!RiTa.isW_Question("")); + ok(!RiTa.isW_Question("Does it?")); + ok(!RiTa.isW_Question("Is this yours?")); + ok(!RiTa.isW_Question("Are you done?")); + ok(!RiTa.isW_Question("")); - }); + }); test("testRandomItem", function() { - var toks = RiTa.tokenize("The boy, dressed in red, ate an apple.!?"); - for (var i = 0; i < toks.length * 2; i++) { - ok(RiTa.randomItem(toks)); - } - - toks = RiTa.tokenize("The quick brown fox jumps over the lazy dog."); - for (var i = 0; i < toks.length * 2; i++) { - ok(RiTa.randomItem(toks)); - } - - toks = RiTa.tokenize("123 123 1 2 3 1,1 1.1 23.45.67 22/05/2012 12th May,2012"); - for (var i = 0; i < toks.length * 2; i++) { - ok(RiTa.randomItem(toks)); - } - }); + var toks = RiTa.tokenize("The boy, dressed in red, ate an apple.!?"); + for (var i = 0; i < toks.length * 2; i++) { + ok(RiTa.randomItem(toks)); + } + + toks = RiTa.tokenize("The quick brown fox jumps over the lazy dog."); + for (var i = 0; i < toks.length * 2; i++) { + ok(RiTa.randomItem(toks)); + } + + toks = RiTa.tokenize("123 123 1 2 3 1,1 1.1 23.45.67 22/05/2012 12th May,2012"); + for (var i = 0; i < toks.length * 2; i++) { + ok(RiTa.randomItem(toks)); + } + }); test("testRandomOrdering", function() { - var result = RiTa.randomOrdering(5); - equal(result.length, 5); + var result = RiTa.randomOrdering(5); + equal(result.length, 5); - var result = RiTa.randomOrdering(50); - equal(result.length, 50); + var result = RiTa.randomOrdering(50); + equal(result.length, 50); - var obj = {}; - for (var i = 0; i < result.length; i++) { - ok(!obj.hasOwnProperty(i + '')); - obj[i + ''] = i + ''; - } - }); + var obj = {}; + for (var i = 0; i < result.length; i++) { + ok(!obj.hasOwnProperty(i + '')); + obj[i + ''] = i + ''; + } + }); test("testSplitSentences", function() { - // TODO: check Penn-Treebank splitting rules - var input = "Stealth's Open Frame, OEM style LCD monitors are designed for special mounting applications. The slim profile packaging provides an excellent solution for building into kiosks, consoles, machines and control panels. If you cannot find an off the shelf solution call us today about designing a custom solution to fit your exact needs."; - var expected = ["Stealth's Open Frame, OEM style LCD monitors are designed for special mounting applications.", "The slim profile packaging provides an excellent solution for building into kiosks, consoles, machines and control panels.", "If you cannot find an off the shelf solution call us today about designing a custom solution to fit your exact needs."]; - var output = RiTa.splitSentences(input); - deepEqual(output, expected); + // TODO: check Penn-Treebank splitting rules + var input = "Stealth's Open Frame, OEM style LCD monitors are designed for special mounting applications. The slim profile packaging provides an excellent solution for building into kiosks, consoles, machines and control panels. If you cannot find an off the shelf solution call us today about designing a custom solution to fit your exact needs."; + var expected = ["Stealth's Open Frame, OEM style LCD monitors are designed for special mounting applications.", "The slim profile packaging provides an excellent solution for building into kiosks, consoles, machines and control panels.", "If you cannot find an off the shelf solution call us today about designing a custom solution to fit your exact needs."]; + var output = RiTa.splitSentences(input); + deepEqual(output, expected); - var input = "\"The boy went fishing.\", he said. Then he went away."; - var expected = ["\"The boy went fishing.\", he said.", "Then he went away."]; - var output = RiTa.splitSentences(input); - deepEqual(output, expected); + var input = "\"The boy went fishing.\", he said. Then he went away."; + var expected = ["\"The boy went fishing.\", he said.", "Then he went away."]; + var output = RiTa.splitSentences(input); + deepEqual(output, expected); - var input = "The dog"; - var output = RiTa.splitSentences(input); - deepEqual(output, [input]); + var input = "The dog"; + var output = RiTa.splitSentences(input); + deepEqual(output, [input]); - var input = "I guess the dog ate the baby."; - var output = RiTa.splitSentences(input); - deepEqual(output, [input]); + var input = "I guess the dog ate the baby."; + var output = RiTa.splitSentences(input); + deepEqual(output, [input]); - var input = "Oh my god, the dog ate the baby!"; - var output = RiTa.splitSentences(input); - var expected = ["Oh my god, the dog ate the baby!"]; - deepEqual(output, expected); + var input = "Oh my god, the dog ate the baby!"; + var output = RiTa.splitSentences(input); + var expected = ["Oh my god, the dog ate the baby!"]; + deepEqual(output, expected); - var input = "Which dog ate the baby?" - var output = RiTa.splitSentences(input); - var expected = ["Which dog ate the baby?"]; - deepEqual(output, expected); + var input = "Which dog ate the baby?" + var output = RiTa.splitSentences(input); + var expected = ["Which dog ate the baby?"]; + deepEqual(output, expected); - var input = "'Yes, it was a dog that ate the baby', he said." - var output = RiTa.splitSentences(input); - var expected = ["\'Yes, it was a dog that ate the baby\', he said."]; - deepEqual(output, expected); + var input = "'Yes, it was a dog that ate the baby', he said." + var output = RiTa.splitSentences(input); + var expected = ["\'Yes, it was a dog that ate the baby\', he said."]; + deepEqual(output, expected); - deepEqual(RiTa.splitSentences(""), [""]); - }); + deepEqual(RiTa.splitSentences(""), [""]); + }); test("testStripPunctuation", function() { - //strip/trimPunctuation "����������`',;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^ - var res = RiTa.stripPunctuation("$%He%^&ll,o,"); - equal(res, "Hello"); - - equal(RiTa.stripPunctuation(""), ""); - - equal(RiTa.stripPunctuation("Hel_lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel;lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel:lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel'lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel/lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel\"lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel-lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel`lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel?lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel.lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel+lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel*lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel&lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel$lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel(lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel)lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel@lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel[lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel]lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel{lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel}lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel\\lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel%lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel~lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel:lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel;lo"), "Hello"); - equal(RiTa.stripPunctuation("Hello"), "Hello"); - equal(RiTa.stripPunctuation("Hel^lo"), "Hello"); - equal(RiTa.stripPunctuation("Hel|lo"), "Hello"); - - var res = RiTa.stripPunctuation("\"\\!@$%&}<>|+=-_\\/*{^He&^ll,o\!@$%&}<>|+=-_\\/*{^"); - equal(res, "Hello"); - - }); + //strip/trimPunctuation "����������`',;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^ + var res = RiTa.stripPunctuation("$%He%^&ll,o,"); + equal(res, "Hello"); + + equal(RiTa.stripPunctuation(""), ""); + + equal(RiTa.stripPunctuation("Hel_lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel;lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel:lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel'lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel/lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel\"lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel-lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel`lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel?lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel.lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel+lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel*lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel&lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel$lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel(lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel)lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel@lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel[lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel]lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel{lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel}lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel\\lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel%lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel~lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel:lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel;lo"), "Hello"); + equal(RiTa.stripPunctuation("Hello"), "Hello"); + equal(RiTa.stripPunctuation("Hel^lo"), "Hello"); + equal(RiTa.stripPunctuation("Hel|lo"), "Hello"); + + var res = RiTa.stripPunctuation("\"\\!@$%&}<>|+=-_\\/*{^He&^ll,o\!@$%&}<>|+=-_\\/*{^"); + equal(res, "Hello"); + + }); test("testTrimPunctuation", function() { - var res = RiTa.trimPunctuation("$%He&^ll,o,"); - equal(res, "He&^ll,o"); + var res = RiTa.trimPunctuation("$%He&^ll,o,"); + equal(res, "He&^ll,o"); - // fix these strange characters - var res = RiTa.trimPunctuation("����������`He&^ll,o\!@$%&}<>|+=-_\\/*{^"); - equal(res, "He&^ll,o"); + // fix these strange characters + var res = RiTa.trimPunctuation("����������`He&^ll,o\!@$%&}<>|+=-_\\/*{^"); + equal(res, "He&^ll,o"); - var res = RiTa.trimPunctuation("\"\\!@$%&}<>|+=-_\\/*{^He&^ll,o\!@$%&}<>|+=-_\\/*{^"); - equal(res, "He&^ll,o"); + var res = RiTa.trimPunctuation("\"\\!@$%&}<>|+=-_\\/*{^He&^ll,o\!@$%&}<>|+=-_\\/*{^"); + equal(res, "He&^ll,o"); - deepEqual(RiTa.trimPunctuation(""), ""); + deepEqual(RiTa.trimPunctuation(""), ""); - deepEqual(RiTa.trimPunctuation(1234), 1234); - }); + deepEqual(RiTa.trimPunctuation(1234), 1234); + }); test("testIsPunctuation", function() { - ok(!RiTa.isPunctuation("What the")); - ok(!RiTa.isPunctuation("What ! the")); - ok(!RiTa.isPunctuation(".#\"\\!@i$%&}<>")); + ok(!RiTa.isPunctuation("What the")); + ok(!RiTa.isPunctuation("What ! the")); + ok(!RiTa.isPunctuation(".#\"\\!@i$%&}<>")); + + ok(RiTa.isPunctuation("!")); + + ok(!RiTa.isPunctuation("! ")); + //space + ok(!RiTa.isPunctuation(" !")); + //space + ok(!RiTa.isPunctuation("! ")); + //double space + ok(!RiTa.isPunctuation(" !")); + //double space + ok(!RiTa.isPunctuation("! ")); + //tab space + ok(!RiTa.isPunctuation(" !")); + //tab space + ok(RiTa.isPunctuation("?")); + ok(RiTa.isPunctuation("?!")); + ok(RiTa.isPunctuation(".")); + ok(RiTa.isPunctuation("..")); + ok(RiTa.isPunctuation("...")); + ok(RiTa.isPunctuation("....")); + ok(RiTa.isPunctuation("%...")); + var punct = '$%&^,'; + for (var i = 0; i < punct.length; i++) { + ok(RiTa.isPunctuation(punct[i])); + } + + var punct = ",;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^"; + for (var i = 0; i < punct.length; i++) { + ok(RiTa.isPunctuation(punct[i]), punct[i]); + } + + // TODO: also test multiple characters strings here **** + var punct = "\"��������`'"; + for (var i = 0; i < punct.length; i++) { + ok(RiTa.isPunctuation(punct[i]), punct[i]); + } + + var punct = "\"��������`',;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^"; + for (var i = 0; i < punct.length; i++) { + ok(RiTa.isPunctuation(punct[i]), punct[i]); + } + + // TODO: and here... + var nopunct = 'Helloasdfnals FgG \t kjdhfakjsdhf askjdfh aaf98762348576'; + for (var i = 0; i < nopunct.length; i++) { + ok(!RiTa.isPunctuation(nopunct[i]), nopunct[i]); + } + + ok(!RiTa.isPunctuation("")); + + }); - ok(RiTa.isPunctuation("!")); - - ok(!RiTa.isPunctuation("! ")); - //space - ok(!RiTa.isPunctuation(" !")); - //space - ok(!RiTa.isPunctuation("! ")); - //double space - ok(!RiTa.isPunctuation(" !")); - //double space - ok(!RiTa.isPunctuation("! ")); - //tab space - ok(!RiTa.isPunctuation(" !")); - //tab space - ok(RiTa.isPunctuation("?")); - ok(RiTa.isPunctuation("?!")); - ok(RiTa.isPunctuation(".")); - ok(RiTa.isPunctuation("..")); - ok(RiTa.isPunctuation("...")); - ok(RiTa.isPunctuation("....")); - ok(RiTa.isPunctuation("%...")); - var punct = '$%&^,'; - for (var i = 0; i < punct.length; i++) { - ok(RiTa.isPunctuation(punct[i])); - } - - var punct = ",;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^"; - for (var i = 0; i < punct.length; i++) { - ok(RiTa.isPunctuation(punct[i]), punct[i]); - } + test("testTokenize", function() { - // TODO: also test multiple characters strings here **** - var punct = "\"��������`'"; - for (var i = 0; i < punct.length; i++) { - ok(RiTa.isPunctuation(punct[i]), punct[i]); - } + var input = "The boy, dressed in red, ate an apple."; + var expected = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "apple", "."]; + var output = RiTa.tokenize(input); + deepEqual(output, expected); - var punct = "\"��������`',;:!?)([].#\"\\!@$%&}<>|+=-_\\/*{^"; - for (var i = 0; i < punct.length; i++) { - ok(RiTa.isPunctuation(punct[i]), punct[i]); - } + var input = "The boy screamed, 'Where is my apple?'"; + //'Where is one word here, same result as Processing (TODO: THIS IS INCORRECT IN BOTH) + var expected = ["The", "boy", "screamed", ",", "'Where", "is", "my", "apple", "?", "'"]; + var output = RiTa.tokenize(input); + deepEqual(output, expected); - // TODO: and here... - var nopunct = 'Helloasdfnals FgG \t kjdhfakjsdhf askjdfh aaf98762348576'; - for (var i = 0; i < nopunct.length; i++) { - ok(!RiTa.isPunctuation(nopunct[i]), nopunct[i]); - } + var input = "why? Me?huh?!"; + var expected = ["why", "?", "Me", "?", "huh", "?", "!"]; + var output = RiTa.tokenize(input); + deepEqual(output, expected); - ok(!RiTa.isPunctuation("")); + var input = "123 123 1 2 3 1,1 1.1 23.45.67 22/05/2012 12th May,2012"; + var expected = ["123", "123", "1", "2", "3", "1", ",", "1", "1", ".", "1", "23", ".", "45", ".", "67", "22/05/2012", "12th", "May", ",", "2012"]; + var output = RiTa.tokenize(input); + deepEqual(output, expected); - }); + // TODO: check Penn-Treebank tokenizer rules & add some more edge cases + var inputs = ["A simple sentence.", "that's why this is our place).", ]; + var outputs = [ + ["A", "simple", "sentence", "."], + ["that's", "why", "this", "is", "our", "place", ")", "."], + ]; - test("testTokenize", function() { + ok(inputs.length == outputs.length); - var input = "The boy, dressed in red, ate an apple."; - var expected = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "apple", "."]; - var output = RiTa.tokenize(input); - deepEqual(output, expected); - - var input = "The boy screamed, 'Where is my apple?'"; - //'Where is one word here, same result as Processing (TODO: THIS IS INCORRECT IN BOTH) - var expected = ["The", "boy", "screamed", ",", "'Where", "is", "my", "apple", "?", "'"]; - var output = RiTa.tokenize(input); - deepEqual(output, expected); - - var input = "why? Me?huh?!"; - var expected = ["why", "?", "Me", "?", "huh", "?", "!"]; - var output = RiTa.tokenize(input); - deepEqual(output, expected); - - var input = "123 123 1 2 3 1,1 1.1 23.45.67 22/05/2012 12th May,2012"; - var expected = ["123", "123", "1", "2", "3", "1", ",", "1", "1", ".", "1", "23", ".", "45", ".", "67", "22/05/2012", "12th", "May", ",", "2012"]; - var output = RiTa.tokenize(input); - deepEqual(output, expected); - - // TODO: check Penn-Treebank tokenizer rules & add some more edge cases - var inputs = ["A simple sentence.", "that's why this is our place).", ]; - var outputs = [ - ["A", "simple", "sentence", "."], - ["that's", "why", "this", "is", "our", "place", ")", "."], - ]; - - ok(inputs.length == outputs.length); - - for (var i = 0; i < inputs.length; i++) { - var result = RiTa.tokenize(inputs[i]); - deepEqual(result, outputs[i]); - } + for (var i = 0; i < inputs.length; i++) { + var result = RiTa.tokenize(inputs[i]); + deepEqual(result, outputs[i]); + } - deepEqual(RiTa.tokenize(""), [""]); + deepEqual(RiTa.tokenize(""), [""]); - var input = "Dr. Chan is talking slowly with Mr. Cheng, and they're friends."; // strange but same as RiTa-java - //var expected = ["Dr.", "Chan", "is", "talking", "slowly", "with", "Mr.", "Cheng", ",", "and", "they're", "friends", "."]; - var expected = ["Dr", ".", "Chan", "is", "talking", "slowly", "with", "Mr", ".", "Cheng", ",", "and", "they're", "friends", "."]; - var output = RiTa.tokenize(input); - deepEqual(output, expected); + var input = "Dr. Chan is talking slowly with Mr. Cheng, and they're friends."; // strange but same as RiTa-java + //var expected = ["Dr.", "Chan", "is", "talking", "slowly", "with", "Mr.", "Cheng", ",", "and", "they're", "friends", "."]; + var expected = ["Dr", ".", "Chan", "is", "talking", "slowly", "with", "Mr", ".", "Cheng", ",", "and", "they're", "friends", "."]; + var output = RiTa.tokenize(input); + deepEqual(output, expected); - var txt = "The dog"; - var words = RiTa.tokenize(txt); - deepEqual(words, ["The", "dog"]); + var txt = "The dog"; + var words = RiTa.tokenize(txt); + deepEqual(words, ["The", "dog"]); - var words = RiTa.tokenize("closed"); - deepEqual(words, ["closed"]); - }); + var words = RiTa.tokenize("closed"); + deepEqual(words, ["closed"]); + }); test("testTrim", function() { - equal(RiTa.trim(""), ""); - equal(RiTa.trim(" "), ""); - equal(RiTa.trim("hello "), "hello"); - equal(RiTa.trim("hel'lo "), "hel'lo"); - equal(RiTa.trim(" hel o"), "hel o"); - equal(RiTa.trim(" hello "), "hello"); - equal(RiTa.trim("'hell' "), "'hell'"); - equal(RiTa.trim("'hello "), "'hello"); - //tab - equal(RiTa.trim(" hello "), "hello"); - //multiple - equal(RiTa.trim(" hello "), "hello"); - //mixed + equal(RiTa.trim(""), ""); + equal(RiTa.trim(" "), ""); + equal(RiTa.trim("hello "), "hello"); + equal(RiTa.trim("hel'lo "), "hel'lo"); + equal(RiTa.trim(" hel o"), "hel o"); + equal(RiTa.trim(" hello "), "hello"); + equal(RiTa.trim("'hell' "), "'hell'"); + equal(RiTa.trim("'hello "), "'hello"); + //tab + equal(RiTa.trim(" hello "), "hello"); + //multiple + equal(RiTa.trim(" hello "), "hello"); + //mixed - }); + }); test("testDistance", function() { - equal(1, RiTa.distance(1, 3, 2, 3)); - equal(28, RiTa.distance(30, 1, 2, 1)); - equal(5.656854249492381, RiTa.distance(0, 0, 4, 4)); - equal(5.0990195135927845, RiTa.distance(3, 3, 8, 4)); + equal(1, RiTa.distance(1, 3, 2, 3)); + equal(28, RiTa.distance(30, 1, 2, 1)); + equal(5.656854249492381, RiTa.distance(0, 0, 4, 4)); + equal(5.0990195135927845, RiTa.distance(3, 3, 8, 4)); - }); + }); test("testRandom", function() { - // float random() - var answer = RiTa.random(); - ok(answer >= 0, answer); - var answer2 = RiTa.random(); - ok(answer2 < 1, answer2); - - // int random(int max) - var answer = RiTa.random(50); - ok(answer >= 0); - var answer2 = RiTa.random(50); - ok(answer2 < 50); - - answer = RiTa.random(1); - ok(answer >= 0); - answer2 = RiTa.random(1); - ok(answer2 < 1); - - answer = RiTa.random(2); - ok(answer >= 0); - answer2 = RiTa.random(2); - ok(answer2 < 2); - - answer = RiTa.random(0); - ok(answer == 0); - - // int random(int min, int max) - var answer = RiTa.random(10, 34); - ok(answer >= 10); - var answer2 = RiTa.random(10, 34); - ok(answer2 < 34); - - answer = RiTa.random(1, 2); - ok(answer >= 1); - answer2 = RiTa.random(1, 2); - ok(answer2 < 2); - - answer = RiTa.random(1, 3); - ok(answer >= 1); - answer2 = RiTa.random(1, 3); - ok(answer2 < 3); - - answer = RiTa.random(0, 0); - ok(answer == 0); - - answer = RiTa.random(5, 1); //"min > max" - ok(answer >= 1); - answer2 = RiTa.random(0, 0); - ok(answer2 < 5); - - // float random(float max) - var answer = RiTa.random(12.3); - ok(answer >= 0); - var answer2 = RiTa.random(12.3); - ok(answer2 < 12.3); - - answer = RiTa.random(1.1); - ok(answer >= 0); - answer2 = RiTa.random(1.1); - ok(answer2 < 1.1); - - answer = RiTa.random(1.2); - ok(answer >= 0); - answer2 = RiTa.random(1.2); - ok(answer2 < 1.2); - - answer = RiTa.random(0); - ok(answer == 0); - - // float random(float min, float max) - - var answer = RiTa.random(3.4, 3.6); - ok(answer >= 3.4); - var answer2 = RiTa.random(3.4, 3.6); - ok(answer2 < 3.6); - - answer = RiTa.random(1.1, 1.2); - ok(answer >= 1.1); - answer2 = RiTa.random(1.1, 1.2); - ok(answer2 < 1.2); - - answer = RiTa.random(1.1, 1.3); - ok(answer >= 1.1); - answer2 = RiTa.random(1.1, 1.3); - ok(answer2 < 1.3); - - answer = RiTa.random(0, 0); - ok(answer == 0); - - answer = RiTa.random(5.1, 1.1); //TODO "min > max" - ok(answer >= 1.1); - answer2 = RiTa.random(0, 0); - ok(answer2 < 5.1); - }); + // float random() + var answer = RiTa.random(); + ok(answer >= 0, answer); + var answer2 = RiTa.random(); + ok(answer2 < 1, answer2); + + // int random(int max) + var answer = RiTa.random(50); + ok(answer >= 0); + var answer2 = RiTa.random(50); + ok(answer2 < 50); + + answer = RiTa.random(1); + ok(answer >= 0); + answer2 = RiTa.random(1); + ok(answer2 < 1); + + answer = RiTa.random(2); + ok(answer >= 0); + answer2 = RiTa.random(2); + ok(answer2 < 2); + + answer = RiTa.random(0); + ok(answer == 0); + + // int random(int min, int max) + var answer = RiTa.random(10, 34); + ok(answer >= 10); + var answer2 = RiTa.random(10, 34); + ok(answer2 < 34); + + answer = RiTa.random(1, 2); + ok(answer >= 1); + answer2 = RiTa.random(1, 2); + ok(answer2 < 2); + + answer = RiTa.random(1, 3); + ok(answer >= 1); + answer2 = RiTa.random(1, 3); + ok(answer2 < 3); + + answer = RiTa.random(0, 0); + ok(answer == 0); + + answer = RiTa.random(5, 1); //"min > max" + ok(answer >= 1); + answer2 = RiTa.random(0, 0); + ok(answer2 < 5); + + // float random(float max) + var answer = RiTa.random(12.3); + ok(answer >= 0); + var answer2 = RiTa.random(12.3); + ok(answer2 < 12.3); + + answer = RiTa.random(1.1); + ok(answer >= 0); + answer2 = RiTa.random(1.1); + ok(answer2 < 1.1); + + answer = RiTa.random(1.2); + ok(answer >= 0); + answer2 = RiTa.random(1.2); + ok(answer2 < 1.2); + + answer = RiTa.random(0); + ok(answer == 0); + + // float random(float min, float max) + + var answer = RiTa.random(3.4, 3.6); + ok(answer >= 3.4); + var answer2 = RiTa.random(3.4, 3.6); + ok(answer2 < 3.6); + + answer = RiTa.random(1.1, 1.2); + ok(answer >= 1.1); + answer2 = RiTa.random(1.1, 1.2); + ok(answer2 < 1.2); + + answer = RiTa.random(1.1, 1.3); + ok(answer >= 1.1); + answer2 = RiTa.random(1.1, 1.3); + ok(answer2 < 1.3); + + answer = RiTa.random(0, 0); + ok(answer == 0); + + answer = RiTa.random(5.1, 1.1); //TODO "min > max" + ok(answer >= 1.1); + answer2 = RiTa.random(0, 0); + ok(answer2 < 5.1); + }); test("testGetPhonemes", function() { - var result = RiTa.getPhonemes("The"); - var answer = "dh-ax"; - equal(result, answer); + var result = RiTa.getPhonemes("The"); + var answer = "dh-ax"; + equal(result, answer); - var result = RiTa.getPhonemes("The."); - var answer = "dh-ax ."; - equal(result, answer); + var result = RiTa.getPhonemes("The."); + var answer = "dh-ax ."; + equal(result, answer); - var result = RiTa.getPhonemes("The boy jumped over the wild dog."); - var answer = "dh-ax b-oy jh-ah-m-p-t ow-v-er dh-ax w-ay-l-d d-ao-g ."; - equal(result, answer); + var result = RiTa.getPhonemes("The boy jumped over the wild dog."); + var answer = "dh-ax b-oy jh-ah-m-p-t ow-v-er dh-ax w-ay-l-d d-ao-g ."; + equal(result, answer); - var result = RiTa.getPhonemes("The boy ran to the store."); - var answer = "dh-ax b-oy r-ae-n t-uw dh-ax s-t-ao-r ."; - equal(result, answer); + var result = RiTa.getPhonemes("The boy ran to the store."); + var answer = "dh-ax b-oy r-ae-n t-uw dh-ax s-t-ao-r ."; + equal(result, answer); - var txt = "The dog ran faster than the other dog. But the other dog was prettier."; - var result = RiTa.getPhonemes(txt); - var answer = "dh-ax d-ao-g r-ae-n f-ae-s-t-er dh-ae-n dh-ax ah-dh-er d-ao-g . b-ah-t dh-ax ah-dh-er d-ao-g w-aa-z p-r-ih-t-iy-er ."; - equal(result, answer); + var txt = "The dog ran faster than the other dog. But the other dog was prettier."; + var result = RiTa.getPhonemes(txt); + var answer = "dh-ax d-ao-g r-ae-n f-ae-s-t-er dh-ae-n dh-ax ah-dh-er d-ao-g . b-ah-t dh-ax ah-dh-er d-ao-g w-aa-z p-r-ih-t-iy-er ."; + equal(result, answer); - var result = RiTa.getPhonemes(""); - var answer = ""; - equal(result, answer); + var result = RiTa.getPhonemes(""); + var answer = ""; + equal(result, answer); - throws(function() { - RiTa.SILENT = 1; - try { - RiTa.getPhonemes([]); - } catch (e) { - throw e; - } - RiTa.SILENT = 0; - }); + throws(function() { + RiTa.SILENT = 1; + try { + RiTa.getPhonemes([]); + } catch (e) { + throw e; + } + RiTa.SILENT = 0; + }); - }); + }); test("testGetPosTags", function() { - var result = RiTa.getPosTags("the boy dances"); - var answer = ["dt", "nn", "vbz"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("the boy dances"); + var answer = ["dt", "nn", "vbz"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("he dances"); - var answer = ["prp", "vbz"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("he dances"); + var answer = ["prp", "vbz"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("Dave dances"); - var answer = ["nnp", "vbz"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("Dave dances"); + var answer = ["nnp", "vbz"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("mammal"); - var answer = ["nn"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("mammal"); + var answer = ["nn"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("running"); - var answer = ["vbg"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("running"); + var answer = ["vbg"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("asserting"); - var answer = ["vbg"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("asserting"); + var answer = ["vbg"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("assenting"); - var answer = ["vbg"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("assenting"); + var answer = ["vbg"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("asfaasd"); - var answer = ["nn"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("asfaasd"); + var answer = ["nn"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("innings"); - var answer = ["nns"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("innings"); + var answer = ["nns"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("Dave"); - var answer = ["nnp"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("Dave"); + var answer = ["nnp"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("clothes"); - var answer = ["nns"]; - deepEqual(result, answer); + var result = RiTa.getPosTags("clothes"); + var answer = ["nns"]; + deepEqual(result, answer); - var result = RiTa.getPosTags("There is a cat."); - var answer = ["ex", "vbz", "dt", "nn", "."]; - deepEqual(result, answer); + var result = RiTa.getPosTags("There is a cat."); + var answer = ["ex", "vbz", "dt", "nn", "."]; + deepEqual(result, answer); - var result = RiTa.getPosTags("The boy, dressed in red, ate an apple."); - var answer = ["dt", "nn", ",", "vbn", "in", "jj", ",", "vbd", "dt", "nn", "."]; - deepEqual(result, answer); + var result = RiTa.getPosTags("The boy, dressed in red, ate an apple."); + var answer = ["dt", "nn", ",", "vbn", "in", "jj", ",", "vbd", "dt", "nn", "."]; + deepEqual(result, answer); - var txt = "The dog ran faster than the other dog. But the other dog was prettier."; - var result = RiTa.getPosTags(txt); - var answer = ["dt", "nn", "vbd", "rbr", "in", "dt", "jj", "nn", ".", "cc", "dt", "jj", "nn", "vbd", "jjr", "."]; - deepEqual(result, answer); + var txt = "The dog ran faster than the other dog. But the other dog was prettier."; + var result = RiTa.getPosTags(txt); + var answer = ["dt", "nn", "vbd", "rbr", "in", "dt", "jj", "nn", ".", "cc", "dt", "jj", "nn", "vbd", "jjr", "."]; + deepEqual(result, answer); - var result = RiTa.getPosTags(""); - var answer = []; - deepEqual(result, answer); + var result = RiTa.getPosTags(""); + var answer = []; + deepEqual(result, answer); - }); + }); test("testGetPosTags(sns)", function() { - var checks = ["emphasis", "stress", "discus", "colossus", "fibrosis", "digitalis", "pettiness", "mess", "cleanliness", "orderliness", "bronchitis", "preparedness", "highness"]; - for (var i = 0, j = checks.length; i < j; i++) { - if (RiTa.getPosTags(checks[i])[0] !== 'nn') - console.log(checks[i] + ": " + RiTa.getPosTags(checks[i])[0]); - deepEqual(RiTa.getPosTags(checks[i]), ["nn"]); - } - }); + var checks = ["emphasis", "stress", "discus", "colossus", "fibrosis", "digitalis", "pettiness", "mess", "cleanliness", "orderliness", "bronchitis", "preparedness", "highness"]; + for (var i = 0, j = checks.length; i < j; i++) { + if (RiTa.getPosTags(checks[i])[0] !== 'nn') + console.log(checks[i] + ": " + RiTa.getPosTags(checks[i])[0]); + deepEqual(RiTa.getPosTags(checks[i]), ["nn"]); + } + }); test("testGetPosTagsInline", function() { - var result = RiTa.getPosTagsInline("asdfaasd"); - var answer = "asdfaasd/nn"; - deepEqual(result, answer); + var result = RiTa.getPosTagsInline("asdfaasd"); + var answer = "asdfaasd/nn"; + deepEqual(result, answer); - var result = RiTa.getPosTagsInline("clothes"); - var answer = "clothes/nns"; - deepEqual(result, answer); + var result = RiTa.getPosTagsInline("clothes"); + var answer = "clothes/nns"; + deepEqual(result, answer); - var result = RiTa.getPosTagsInline("There is a cat."); - var answer = "There/ex is/vbz a/dt cat/nn ."; - deepEqual(result, answer); + var result = RiTa.getPosTagsInline("There is a cat."); + var answer = "There/ex is/vbz a/dt cat/nn ."; + deepEqual(result, answer); - var result = RiTa.getPosTagsInline("The boy, dressed in red, ate an apple."); - var answer = "The/dt boy/nn , dressed/vbn in/in red/jj , ate/vbd an/dt apple/nn ."; - deepEqual(result, answer); + var result = RiTa.getPosTagsInline("The boy, dressed in red, ate an apple."); + var answer = "The/dt boy/nn , dressed/vbn in/in red/jj , ate/vbd an/dt apple/nn ."; + deepEqual(result, answer); - var txt = "The dog ran faster than the other dog. But the other dog was prettier."; - var result = RiTa.getPosTagsInline(txt); - var answer = "The/dt dog/nn ran/vbd faster/rbr than/in the/dt other/jj dog/nn . But/cc the/dt other/jj dog/nn was/vbd prettier/jjr ."; - equal(result, answer); + var txt = "The dog ran faster than the other dog. But the other dog was prettier."; + var result = RiTa.getPosTagsInline(txt); + var answer = "The/dt dog/nn ran/vbd faster/rbr than/in the/dt other/jj dog/nn . But/cc the/dt other/jj dog/nn was/vbd prettier/jjr ."; + equal(result, answer); - var result = RiTa.getPosTagsInline(""); - var answer = ""; - deepEqual(result, answer); + var result = RiTa.getPosTagsInline(""); + var answer = ""; + deepEqual(result, answer); - }); + }); test("testGetStresses", function() { - var result = RiTa.getStresses("The emperor had no clothes on"); - var answer = "0 1/0/0 1 1 1 1"; - equal(result, answer); + var result = RiTa.getStresses("The emperor had no clothes on"); + var answer = "0 1/0/0 1 1 1 1"; + equal(result, answer); - var result = RiTa.getStresses("The emperor had no clothes on."); - var answer = "0 1/0/0 1 1 1 1 ."; - equal(result, answer); + var result = RiTa.getStresses("The emperor had no clothes on."); + var answer = "0 1/0/0 1 1 1 1 ."; + equal(result, answer); - var result = RiTa.getStresses("The emperor had no clothes on. The King is fat."); - var answer = "0 1/0/0 1 1 1 1 . 0 1 1 1 ."; - equal(result, answer); + var result = RiTa.getStresses("The emperor had no clothes on. The King is fat."); + var answer = "0 1/0/0 1 1 1 1 . 0 1 1 1 ."; + equal(result, answer); - var result = RiTa.getStresses("to preSENT, to exPORT, to deCIDE, to beGIN"); - var answer = "1 0/1 , 1 0/1 , 1 0/1 , 1 0/1"; - equal(result, answer); + var result = RiTa.getStresses("to preSENT, to exPORT, to deCIDE, to beGIN"); + var answer = "1 0/1 , 1 0/1 , 1 0/1 , 1 0/1"; + equal(result, answer); - var result = RiTa.getStresses("to present, to export, to decide, to begin"); - var answer = "1 0/1 , 1 0/1 , 1 0/1 , 1 0/1"; - equal(result, answer); + var result = RiTa.getStresses("to present, to export, to decide, to begin"); + var answer = "1 0/1 , 1 0/1 , 1 0/1 , 1 0/1"; + equal(result, answer); - var txt = "The dog ran faster than the other dog. But the other dog was prettier."; - var result = RiTa.getStresses(txt); - var answer = "0 1 1 1/0 1 0 1/0 1 . 1 0 1/0 1 1 1/0/0 ."; - equal(result, answer); + var txt = "The dog ran faster than the other dog. But the other dog was prettier."; + var result = RiTa.getStresses(txt); + var answer = "0 1 1 1/0 1 0 1/0 1 . 1 0 1/0 1 1 1/0/0 ."; + equal(result, answer); - var result = RiTa.getStresses(""); - var answer = ""; - equal(result, answer); + var result = RiTa.getStresses(""); + var answer = ""; + equal(result, answer); - }); + }); test("testGetWordCount", function() { - var result = RiTa.getWordCount("123 1231 hi"); - deepEqual(result, 3); + var result = RiTa.getWordCount("123 1231 hi"); + deepEqual(result, 3); - var result = RiTa.getWordCount("The boy screamed, 'Where is my apple?'"); - deepEqual(result, 10); + var result = RiTa.getWordCount("The boy screamed, 'Where is my apple?'"); + deepEqual(result, 10); - var result = RiTa.getWordCount("one two three."); - deepEqual(result, 4); + var result = RiTa.getWordCount("one two three."); + deepEqual(result, 4); - var result = RiTa.getWordCount("I guess the dog ate the baby."); - deepEqual(result, 8); + var result = RiTa.getWordCount("I guess the dog ate the baby."); + deepEqual(result, 8); - var result = RiTa.getWordCount("Oh my god, the dog ate the baby!"); - deepEqual(result, 10); + var result = RiTa.getWordCount("Oh my god, the dog ate the baby!"); + deepEqual(result, 10); - var result = RiTa.getWordCount("Which dog ate the baby?"); - deepEqual(result, 6); + var result = RiTa.getWordCount("Which dog ate the baby?"); + deepEqual(result, 6); - var result = RiTa.getWordCount("\'Yes, it was a dog that ate the baby\', he said."); - deepEqual(result, 15); - }); + var result = RiTa.getWordCount("\'Yes, it was a dog that ate the baby\', he said."); + deepEqual(result, 15); + }); - test("testPosToWordNet", function() { + /*test("testPosToWordNet", function() { var result = RiTa.posToWordNet("nn"); equal("n", result); @@ -827,556 +835,556 @@ var runtests = function() { var result = RiTa.posToWordNet(""); equal("", result); - }); + });*/ test("testStem(lancaster)", function() { - var type = 'Lancaster'; - // default + var type = 'Lancaster'; + // default - equal(RiTa.stem("cakes", type), "cak"); + equal(RiTa.stem("cakes", type), "cak"); - var tests = ["run", "runs", "running"]; - for (var i = 0; i < tests.length; i++) { - equal(RiTa.stem(tests[i], type), "run"); - } + var tests = ["run", "runs", "running"]; + for (var i = 0; i < tests.length; i++) { + equal(RiTa.stem(tests[i], type), "run"); + } - equal(RiTa.stem("gases", type), "gas"); - equal(RiTa.stem("buses", type), "bus"); - equal(RiTa.stem("happiness", type), "happy"); - equal(RiTa.stem("terrible", type), "terr"); + equal(RiTa.stem("gases", type), "gas"); + equal(RiTa.stem("buses", type), "bus"); + equal(RiTa.stem("happiness", type), "happy"); + equal(RiTa.stem("terrible", type), "terr"); - var test = 'Stemming is funnier than a bummer says the sushi loving computer'; - var result = 'stem is funny than a bum say the sush lov comput'; - equal(RiTa.stem(test, type), result); - }); + var test = 'Stemming is funnier than a bummer says the sushi loving computer'; + var result = 'stem is funny than a bum say the sush lov comput'; + equal(RiTa.stem(test, type), result); + }); test("testStem(porter)", function() { - var type = 'Porter'; + var type = 'Porter'; - equal(RiTa.stem("cakes", type), "cake"); + equal(RiTa.stem("cakes", type), "cake"); - var tests = ["run", "runs", "running"]; - for (var i = 0; i < tests.length; i++) { - equal(RiTa.stem(tests[i], type), "run"); - } + var tests = ["run", "runs", "running"]; + for (var i = 0; i < tests.length; i++) { + equal(RiTa.stem(tests[i], type), "run"); + } - equal(RiTa.stem("gases", type), "gase"); - equal(RiTa.stem("buses", type), "buse"); - equal(RiTa.stem("happiness", type), "happi"); - equal(RiTa.stem("joyful", type), "joy"); - equal(RiTa.stem("terrible", type), "terribl"); + equal(RiTa.stem("gases", type), "gase"); + equal(RiTa.stem("buses", type), "buse"); + equal(RiTa.stem("happiness", type), "happi"); + equal(RiTa.stem("joyful", type), "joy"); + equal(RiTa.stem("terrible", type), "terribl"); - var test = 'Stemming is funnier than a bummer'; - var result = 'Stem is funnier than a bummer'; - equal(RiTa.stem(test, type), result); - }); + var test = 'Stemming is funnier than a bummer'; + var result = 'Stem is funnier than a bummer'; + equal(RiTa.stem(test, type), result); + }); test("testStem(pling)", function() { - var type = 'Pling'; + var type = 'Pling'; - equal(RiTa.stem("cakes", type), "cake"); + equal(RiTa.stem("cakes", type), "cake"); - var tests = ["run", "runs"]; - for (var i = 0; i < tests.length; i++) { - equal(RiTa.stem(tests[i], type), "run"); - } + var tests = ["run", "runs"]; + for (var i = 0; i < tests.length; i++) { + equal(RiTa.stem(tests[i], type), "run"); + } - equal(RiTa.stem("gases", type), "gas"); - equal(RiTa.stem("buses", type), "bus"); - equal(RiTa.stem("happiness", type), "happiness"); - equal(RiTa.stem("terrible", type), "terrible"); - }); + equal(RiTa.stem("gases", type), "gas"); + equal(RiTa.stem("buses", type), "bus"); + equal(RiTa.stem("happiness", type), "happiness"); + equal(RiTa.stem("terrible", type), "terrible"); + }); test("RiTa.LTSEngine", function() { - //getPhonemes - var result = RiTa.getPhonemes("asdfgasdasdasdasdsadasf"); - var answer = "ae-s-d-f-g-ax-s-d-ae-s-d-ae-s-d-ae-s-d-s-ao-d-ae-s-f"; - equal(result, answer); - - var result = RiTa.getPhonemes("HTERE ^%&*^ IS ^(*^*() fsfa"); - var answer = "t-ih-r ^ % ae-n-d *^ ih-z ^ ( *^* ( ) f-s-f-ax"; - equal(result, answer); - - //getStresses - var result = RiTa.getStresses("deMOcracy, dependaBIlity, phoTOgraphy, geOLogy"); - var answer = "0/1/0/0 , 0/1/0/1/0/0 , 0/1/0/0 , 0/1/0/0"; - equal(result, answer); - - var result = RiTa.getStresses("@#$%^&*()"); - var answer = "@ # $ % ^ 1 * ( )"; - equal(result, answer); - - var result = RiTa.getStresses("asdfgasdasdasdasdsadasf"); - var answer = "1/0/1/1/1/1/1"; - equal(result, answer); - - var result = RiTa.getStresses("HTERE ^%&*^ IS ^(*^*() fsfa"); - var answer = "1 ^ % 1 *^ 1 ^ ( *^* ( ) 0"; - equal(result, answer); - - //getSyllables - var result = RiTa.getSyllables("one two three four five"); - // numbers are not working also - var answer = "w-ah-n t-uw th-r-iy f-ao-r f-ay-v"; - equal(result, answer); - - var result = RiTa.getSyllables("12345"); - // numbers are not working also - var answer = "w-ah-n/t-uw/th-r-iy/f-ao-r/f-ay-v"; - equal(result, answer); - - var result = RiTa.getSyllables("1 2 3 4 5 "); - // numbers are not working also - var answer = "w-ah-n t-uw th-r-iy f-ao-r f-ay-v"; - equal(result, answer); - - var result = RiTa.getPosTags("2"); - // numbers are not working also - var answer = "cd"; - equal(result, answer); - - var result = RiTa.getSyllables("The three emperor had no clothes on."); - var answer = "dh-ax th-r-iy eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n ."; - equal(result, answer); - - var result = RiTa.getSyllables("The 3 emperor had no clothes on."); - var answer = "dh-ax th-r-iy eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n ."; - equal(result, answer); - - var result = RiTa.getSyllables("The 3 emperor! Had no clothes, on."); - var answer = "dh-ax th-r-iy eh-m-p/er/er ! hh-ae-d n-ow k-l-ow-dh-z , aa-n ."; - equal(result, answer); - - var result = RiTa.getSyllables("asdfgasdasdasdasdsadasf"); - var answer = "ae-s-d-f/g-ax-s/d-ae-s/d-ae-s/d-ae-s-d/s-ao/d-ae-s-f"; - equal(result, answer); - - var result = RiTa.getSyllables("HTERE ^%&*^ IS ^(*^*() fsfa"); - var answer = "t-ih-r ^ % ae-n-d *^ ih-z ^ ( *^* ( ) f-s-f-ax"; - equal(result, answer); - }); + //getPhonemes + var result = RiTa.getPhonemes("asdfgasdasdasdasdsadasf"); + var answer = "ae-s-d-f-g-ax-s-d-ae-s-d-ae-s-d-ae-s-d-s-ao-d-ae-s-f"; + equal(result, answer); + + var result = RiTa.getPhonemes("HTERE ^%&*^ IS ^(*^*() fsfa"); + var answer = "t-ih-r ^ % ae-n-d *^ ih-z ^ ( *^* ( ) f-s-f-ax"; + equal(result, answer); + + //getStresses + var result = RiTa.getStresses("deMOcracy, dependaBIlity, phoTOgraphy, geOLogy"); + var answer = "0/1/0/0 , 0/1/0/1/0/0 , 0/1/0/0 , 0/1/0/0"; + equal(result, answer); + + var result = RiTa.getStresses("@#$%^&*()"); + var answer = "@ # $ % ^ 1 * ( )"; + equal(result, answer); + + var result = RiTa.getStresses("asdfgasdasdasdasdsadasf"); + var answer = "1/0/1/1/1/1/1"; + equal(result, answer); + + var result = RiTa.getStresses("HTERE ^%&*^ IS ^(*^*() fsfa"); + var answer = "1 ^ % 1 *^ 1 ^ ( *^* ( ) 0"; + equal(result, answer); + + //getSyllables + var result = RiTa.getSyllables("one two three four five"); + // numbers are not working also + var answer = "w-ah-n t-uw th-r-iy f-ao-r f-ay-v"; + equal(result, answer); + + var result = RiTa.getSyllables("12345"); + // numbers are not working also + var answer = "w-ah-n/t-uw/th-r-iy/f-ao-r/f-ay-v"; + equal(result, answer); + + var result = RiTa.getSyllables("1 2 3 4 5 "); + // numbers are not working also + var answer = "w-ah-n t-uw th-r-iy f-ao-r f-ay-v"; + equal(result, answer); + + var result = RiTa.getPosTags("2"); + // numbers are not working also + var answer = "cd"; + equal(result, answer); + + var result = RiTa.getSyllables("The three emperor had no clothes on."); + var answer = "dh-ax th-r-iy eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n ."; + equal(result, answer); + + var result = RiTa.getSyllables("The 3 emperor had no clothes on."); + var answer = "dh-ax th-r-iy eh-m-p/er/er hh-ae-d n-ow k-l-ow-dh-z aa-n ."; + equal(result, answer); + + var result = RiTa.getSyllables("The 3 emperor! Had no clothes, on."); + var answer = "dh-ax th-r-iy eh-m-p/er/er ! hh-ae-d n-ow k-l-ow-dh-z , aa-n ."; + equal(result, answer); + + var result = RiTa.getSyllables("asdfgasdasdasdasdsadasf"); + var answer = "ae-s-d-f/g-ax-s/d-ae-s/d-ae-s/d-ae-s-d/s-ao/d-ae-s-f"; + equal(result, answer); + + var result = RiTa.getSyllables("HTERE ^%&*^ IS ^(*^*() fsfa"); + var answer = "t-ih-r ^ % ae-n-d *^ ih-z ^ ( *^* ( ) f-s-f-ax"; + equal(result, answer); + }); test("testPluralize", function() { - equal("blondes", RiTa.pluralize("blonde")); - equal("eyes", RiTa.pluralize("eye")); - equal("blondes", RiTa.pluralize("blond")); + equal("blondes", RiTa.pluralize("blonde")); + equal("eyes", RiTa.pluralize("eye")); + equal("blondes", RiTa.pluralize("blond")); - equal("dogs", RiTa.pluralize("dog")); - equal("feet", RiTa.pluralize("foot")); - equal("men", RiTa.pluralize("man")); + equal("dogs", RiTa.pluralize("dog")); + equal("feet", RiTa.pluralize("foot")); + equal("men", RiTa.pluralize("man")); - equal("beautifuls", RiTa.pluralize("beautiful")); - equal("teeth", RiTa.pluralize("tooth")); - equal("cakes", RiTa.pluralize("cake")); - equal("kisses", RiTa.pluralize("kiss")); - equal("children", RiTa.pluralize("child")); + equal("beautifuls", RiTa.pluralize("beautiful")); + equal("teeth", RiTa.pluralize("tooth")); + equal("cakes", RiTa.pluralize("cake")); + equal("kisses", RiTa.pluralize("kiss")); + equal("children", RiTa.pluralize("child")); - equal("randomwords", RiTa.pluralize("randomword")); - equal("lice", RiTa.pluralize("louse")); + equal("randomwords", RiTa.pluralize("randomword")); + equal("lice", RiTa.pluralize("louse")); - equal("sheep", RiTa.pluralize("sheep")); - equal("shrimps", RiTa.pluralize("shrimp")); - equal("series", RiTa.pluralize("series")); - equal("mice", RiTa.pluralize("mouse")); + equal("sheep", RiTa.pluralize("sheep")); + equal("shrimps", RiTa.pluralize("shrimp")); + equal("series", RiTa.pluralize("series")); + equal("mice", RiTa.pluralize("mouse")); - equal("", RiTa.pluralize("")); + equal("", RiTa.pluralize("")); - equal(RiTa.pluralize("tomato"), "tomatoes"); - equal(RiTa.pluralize("toe"), "toes"); + equal(RiTa.pluralize("tomato"), "tomatoes"); + equal(RiTa.pluralize("toe"), "toes"); - equal(RiTa.pluralize("deer"), "deer"); - equal(RiTa.pluralize("ox"), "oxen"); + equal(RiTa.pluralize("deer"), "deer"); + equal(RiTa.pluralize("ox"), "oxen"); - equal(RiTa.pluralize("tobacco"), "tobacco"); - equal(RiTa.pluralize("cargo"), "cargo"); - equal(RiTa.pluralize("golf"), "golf"); - equal(RiTa.pluralize("grief"), "grief"); - equal(RiTa.pluralize("wildlife"), "wildlife"); - equal(RiTa.pluralize("taxi"), "taxis"); - equal(RiTa.pluralize("Chinese"), "Chinese"); - equal(RiTa.pluralize("bonsai"), "bonsai"); + equal(RiTa.pluralize("tobacco"), "tobacco"); + equal(RiTa.pluralize("cargo"), "cargo"); + equal(RiTa.pluralize("golf"), "golf"); + equal(RiTa.pluralize("grief"), "grief"); + equal(RiTa.pluralize("wildlife"), "wildlife"); + equal(RiTa.pluralize("taxi"), "taxis"); + equal(RiTa.pluralize("Chinese"), "Chinese"); + equal(RiTa.pluralize("bonsai"), "bonsai"); - equal(RiTa.pluralize("gas"), "gases"); - equal(RiTa.pluralize("bus"), "buses"); + equal(RiTa.pluralize("gas"), "gases"); + equal(RiTa.pluralize("bus"), "buses"); - equal("crises", RiTa.pluralize("crisis")); - equal("theses", RiTa.pluralize("thesis")); - equal("apotheses", RiTa.pluralize("apothesis")); - equal("stimuli", RiTa.pluralize("stimulus")); - equal("alumni", RiTa.pluralize("alumnus")); - equal("corpora", RiTa.pluralize("corpus")); - }); + equal("crises", RiTa.pluralize("crisis")); + equal("theses", RiTa.pluralize("thesis")); + equal("apotheses", RiTa.pluralize("apothesis")); + equal("stimuli", RiTa.pluralize("stimulus")); + equal("alumni", RiTa.pluralize("alumnus")); + equal("corpora", RiTa.pluralize("corpus")); + }); test("testSingularize", function() { - equal("blonde", RiTa.singularize("blondes")); - equal("eye", RiTa.singularize("eyes")); - equal(RiTa.singularize("bonsai"), "bonsai"); - equal(RiTa.singularize("taxis"), "taxi"); - equal(RiTa.singularize("chiefs"), "chief"); - equal(RiTa.singularize("monarchs"), "monarch"); - equal(RiTa.singularize("lochs"), "loch"); - equal(RiTa.singularize("stomachs"), "stomach"); - - equal(RiTa.singularize("Chinese"), "Chinese"); - - equal(RiTa.singularize("people"), "person"); - equal(RiTa.singularize("monies"), "money"); - equal(RiTa.singularize("vertebrae"), "vertebra"); - equal(RiTa.singularize("humans"), "human"); - equal(RiTa.singularize("germans"), "german"); - equal(RiTa.singularize("romans"), "roman"); - - equal(RiTa.singularize("memoranda"), "memorandum"); - equal(RiTa.singularize("data"), "datum"); - equal(RiTa.singularize("appendices"), "appendix"); - equal(RiTa.singularize("theses"), "thesis"); - equal(RiTa.singularize("alumni"), "alumnus"); - - equal(RiTa.singularize("solos"), "solo"); - equal(RiTa.singularize("music"), "music"); - - equal(RiTa.singularize("oxen"), "ox"); - equal(RiTa.singularize("solos"), "solo"); - equal(RiTa.singularize("music"), "music"); - - equal(RiTa.singularize("tobacco"), "tobacco"); - equal(RiTa.singularize("cargo"), "cargo"); - equal(RiTa.singularize("golf"), "golf"); - equal(RiTa.singularize("grief"), "grief"); - - equal(RiTa.singularize("cakes"), "cake"); - - equal("dog", RiTa.singularize("dogs")); - equal("foot", RiTa.singularize("feet")); - equal("tooth", RiTa.singularize("teeth")); - equal("kiss", RiTa.singularize("kisses")); - equal("child", RiTa.singularize("child")); - equal("randomword", RiTa.singularize("randomwords")); - equal("deer", RiTa.singularize("deer")); - equal("sheep", RiTa.singularize("sheep")); - equal("shrimp", RiTa.singularize("shrimps")); - - equal(RiTa.singularize("tomatoes"), "tomato"); - equal(RiTa.singularize("photos"), "photo"); - - equal(RiTa.singularize("toes"), "toe"); - - equal("series", RiTa.singularize("series")); - equal("ox", RiTa.singularize("oxen")); - equal("man", RiTa.singularize("men")); - equal("mouse", RiTa.singularize("mice")); - equal("louse", RiTa.singularize("lice")); - equal("child", RiTa.singularize("children")); - - equal(RiTa.singularize("gases"), "gas"); - equal(RiTa.singularize("buses"), "bus"); - equal(RiTa.singularize("happiness"), "happiness"); - - equal(RiTa.singularize("crises"), "crisis"); - equal(RiTa.singularize("theses"), "thesis"); - equal(RiTa.singularize("apotheses"), "apothesis"); - equal(RiTa.singularize("stimuli"), "stimulus"); - equal(RiTa.singularize("alumni"), "alumnus"); - equal(RiTa.singularize("corpora"), "corpus"); - - equal("", RiTa.singularize("")); - }); + equal("blonde", RiTa.singularize("blondes")); + equal("eye", RiTa.singularize("eyes")); + equal(RiTa.singularize("bonsai"), "bonsai"); + equal(RiTa.singularize("taxis"), "taxi"); + equal(RiTa.singularize("chiefs"), "chief"); + equal(RiTa.singularize("monarchs"), "monarch"); + equal(RiTa.singularize("lochs"), "loch"); + equal(RiTa.singularize("stomachs"), "stomach"); + + equal(RiTa.singularize("Chinese"), "Chinese"); + + equal(RiTa.singularize("people"), "person"); + equal(RiTa.singularize("monies"), "money"); + equal(RiTa.singularize("vertebrae"), "vertebra"); + equal(RiTa.singularize("humans"), "human"); + equal(RiTa.singularize("germans"), "german"); + equal(RiTa.singularize("romans"), "roman"); + + equal(RiTa.singularize("memoranda"), "memorandum"); + equal(RiTa.singularize("data"), "datum"); + equal(RiTa.singularize("appendices"), "appendix"); + equal(RiTa.singularize("theses"), "thesis"); + equal(RiTa.singularize("alumni"), "alumnus"); + + equal(RiTa.singularize("solos"), "solo"); + equal(RiTa.singularize("music"), "music"); + + equal(RiTa.singularize("oxen"), "ox"); + equal(RiTa.singularize("solos"), "solo"); + equal(RiTa.singularize("music"), "music"); + + equal(RiTa.singularize("tobacco"), "tobacco"); + equal(RiTa.singularize("cargo"), "cargo"); + equal(RiTa.singularize("golf"), "golf"); + equal(RiTa.singularize("grief"), "grief"); + + equal(RiTa.singularize("cakes"), "cake"); + + equal("dog", RiTa.singularize("dogs")); + equal("foot", RiTa.singularize("feet")); + equal("tooth", RiTa.singularize("teeth")); + equal("kiss", RiTa.singularize("kisses")); + equal("child", RiTa.singularize("child")); + equal("randomword", RiTa.singularize("randomwords")); + equal("deer", RiTa.singularize("deer")); + equal("sheep", RiTa.singularize("sheep")); + equal("shrimp", RiTa.singularize("shrimps")); + + equal(RiTa.singularize("tomatoes"), "tomato"); + equal(RiTa.singularize("photos"), "photo"); + + equal(RiTa.singularize("toes"), "toe"); + + equal("series", RiTa.singularize("series")); + equal("ox", RiTa.singularize("oxen")); + equal("man", RiTa.singularize("men")); + equal("mouse", RiTa.singularize("mice")); + equal("louse", RiTa.singularize("lice")); + equal("child", RiTa.singularize("children")); + + equal(RiTa.singularize("gases"), "gas"); + equal(RiTa.singularize("buses"), "bus"); + equal(RiTa.singularize("happiness"), "happiness"); + + equal(RiTa.singularize("crises"), "crisis"); + equal(RiTa.singularize("theses"), "thesis"); + equal(RiTa.singularize("apotheses"), "apothesis"); + equal(RiTa.singularize("stimuli"), "stimulus"); + equal(RiTa.singularize("alumni"), "alumnus"); + equal(RiTa.singularize("corpora"), "corpus"); + + equal("", RiTa.singularize("")); + }); test("testGetPastParticiple", function() { - equal(RiTa.getPastParticiple("sleep"), "slept"); - equal(RiTa.getPastParticiple("withhold"), "withheld"); - - equal(RiTa.getPastParticiple("cut"), "cut"); - equal(RiTa.getPastParticiple("go"), "gone"); - equal(RiTa.getPastParticiple("swim"), "swum"); - equal(RiTa.getPastParticiple("would"), "would"); - equal(RiTa.getPastParticiple("might"), "might"); - equal(RiTa.getPastParticiple("run"), "run"); - equal(RiTa.getPastParticiple("speak"), "spoken"); - equal(RiTa.getPastParticiple("break"), "broken"); - equal(RiTa.getPastParticiple(""), ""); - - // PROBLEMS - - equal(RiTa.getPastParticiple("awake"), "awoken"); - equal(RiTa.getPastParticiple("become"), "became"); - equal(RiTa.getPastParticiple("drink"), "drunk"); - equal(RiTa.getPastParticiple("plead"), "pled"); - equal(RiTa.getPastParticiple("run"), "run"); - equal(RiTa.getPastParticiple("shine"), "shone"); - // or shined - equal(RiTa.getPastParticiple("shrink"), "shrunk"); - // or shrunken - equal(RiTa.getPastParticiple("stink"), "stunk"); - equal(RiTa.getPastParticiple("study"), "studied"); - }); + equal(RiTa.getPastParticiple("sleep"), "slept"); + equal(RiTa.getPastParticiple("withhold"), "withheld"); + + equal(RiTa.getPastParticiple("cut"), "cut"); + equal(RiTa.getPastParticiple("go"), "gone"); + equal(RiTa.getPastParticiple("swim"), "swum"); + equal(RiTa.getPastParticiple("would"), "would"); + equal(RiTa.getPastParticiple("might"), "might"); + equal(RiTa.getPastParticiple("run"), "run"); + equal(RiTa.getPastParticiple("speak"), "spoken"); + equal(RiTa.getPastParticiple("break"), "broken"); + equal(RiTa.getPastParticiple(""), ""); + + // PROBLEMS + + equal(RiTa.getPastParticiple("awake"), "awoken"); + equal(RiTa.getPastParticiple("become"), "became"); + equal(RiTa.getPastParticiple("drink"), "drunk"); + equal(RiTa.getPastParticiple("plead"), "pled"); + equal(RiTa.getPastParticiple("run"), "run"); + equal(RiTa.getPastParticiple("shine"), "shone"); + // or shined + equal(RiTa.getPastParticiple("shrink"), "shrunk"); + // or shrunken + equal(RiTa.getPastParticiple("stink"), "stunk"); + equal(RiTa.getPastParticiple("study"), "studied"); + }); test("testGetPresentParticiple", function() { - equal(RiTa.getPresentParticiple("sleep"), "sleeping"); - equal(RiTa.getPresentParticiple("withhold"), "withholding"); - - equal(RiTa.getPresentParticiple("cut"), "cutting"); - equal(RiTa.getPresentParticiple("go"), "going"); - equal(RiTa.getPresentParticiple("run"), "running"); - equal(RiTa.getPresentParticiple("speak"), "speaking"); - equal(RiTa.getPresentParticiple("break"), "breaking"); - equal(RiTa.getPresentParticiple("become"), "becoming"); - equal(RiTa.getPresentParticiple("plead"), "pleading"); - equal(RiTa.getPresentParticiple("awake"), "awaking"); - equal(RiTa.getPresentParticiple("study"), "studying"); - - equal(RiTa.getPresentParticiple("lie"), "lying"); - equal(RiTa.getPresentParticiple("swim"), "swimming"); - equal(RiTa.getPresentParticiple("run"), "running"); - equal(RiTa.getPresentParticiple("dig"), "digging"); - equal(RiTa.getPresentParticiple("set"), "setting"); - equal(RiTa.getPresentParticiple("speak"), "speaking"); - equal(RiTa.getPresentParticiple("bring"), "bringing"); - equal(RiTa.getPresentParticiple("speak"), "speaking"); - - equal(RiTa.getPresentParticiple("study "), "studying"); - //space - equal(RiTa.getPresentParticiple(" study"), "studying"); - //space - equal(RiTa.getPresentParticiple("study "), "studying"); - //double space - equal(RiTa.getPresentParticiple(" study"), "studying"); - //double space - equal(RiTa.getPresentParticiple("study "), "studying"); - //tab space - equal(RiTa.getPresentParticiple(" study"), "studying"); - //tab space - equal(RiTa.getPresentParticiple(""), ""); - - }); + equal(RiTa.getPresentParticiple("sleep"), "sleeping"); + equal(RiTa.getPresentParticiple("withhold"), "withholding"); + + equal(RiTa.getPresentParticiple("cut"), "cutting"); + equal(RiTa.getPresentParticiple("go"), "going"); + equal(RiTa.getPresentParticiple("run"), "running"); + equal(RiTa.getPresentParticiple("speak"), "speaking"); + equal(RiTa.getPresentParticiple("break"), "breaking"); + equal(RiTa.getPresentParticiple("become"), "becoming"); + equal(RiTa.getPresentParticiple("plead"), "pleading"); + equal(RiTa.getPresentParticiple("awake"), "awaking"); + equal(RiTa.getPresentParticiple("study"), "studying"); + + equal(RiTa.getPresentParticiple("lie"), "lying"); + equal(RiTa.getPresentParticiple("swim"), "swimming"); + equal(RiTa.getPresentParticiple("run"), "running"); + equal(RiTa.getPresentParticiple("dig"), "digging"); + equal(RiTa.getPresentParticiple("set"), "setting"); + equal(RiTa.getPresentParticiple("speak"), "speaking"); + equal(RiTa.getPresentParticiple("bring"), "bringing"); + equal(RiTa.getPresentParticiple("speak"), "speaking"); + + equal(RiTa.getPresentParticiple("study "), "studying"); + //space + equal(RiTa.getPresentParticiple(" study"), "studying"); + //space + equal(RiTa.getPresentParticiple("study "), "studying"); + //double space + equal(RiTa.getPresentParticiple(" study"), "studying"); + //double space + equal(RiTa.getPresentParticiple("study "), "studying"); + //tab space + equal(RiTa.getPresentParticiple(" study"), "studying"); + //tab space + equal(RiTa.getPresentParticiple(""), ""); + + }); test("testUntokenize", function() { - equal(RiTa.untokenize([""]), ""); + equal(RiTa.untokenize([""]), ""); - var expected = "The boy, dressed in red, ate an apple."; - var input = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "apple", "."]; - var output = RiTa.untokenize(input); - deepEqual(output, expected); + var expected = "The boy, dressed in red, ate an apple."; + var input = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "apple", "."]; + var output = RiTa.untokenize(input); + deepEqual(output, expected); - var expected = "The boy screamed, 'Where is my apple?'"; - var input = ["The", "boy", "screamed", ",", "'Where", "is", "my", "apple", "?", "'"]; - var output = RiTa.untokenize(input); - deepEqual(output, expected); + var expected = "The boy screamed, 'Where is my apple?'"; + var input = ["The", "boy", "screamed", ",", "'Where", "is", "my", "apple", "?", "'"]; + var output = RiTa.untokenize(input); + deepEqual(output, expected); - var outputs = ["A simple sentence.", - "that's why this is our place).", - ]; + var outputs = ["A simple sentence.", + "that's why this is our place).", + ]; - var inputs = [ - ["A", "simple", "sentence", "."], - ["that's", "why", "this", "is", "our", "place", ")", "."], - ]; + var inputs = [ + ["A", "simple", "sentence", "."], + ["that's", "why", "this", "is", "our", "place", ")", "."], + ]; - ok(inputs.length == outputs.length); + ok(inputs.length == outputs.length); - for (var i = 0; i < inputs.length; i++) { - var result = RiTa.untokenize(inputs[i]); - deepEqual(result, outputs[i]); - } + for (var i = 0; i < inputs.length; i++) { + var result = RiTa.untokenize(inputs[i]); + deepEqual(result, outputs[i]); + } - var expected = "Dr. Chan is talking slowly with Mr. Cheng, and they're friends."; // strange but same as RiTa-java - var input = ["Dr", ".", "Chan", "is", "talking", "slowly", "with", "Mr", ".", "Cheng", ",", "and", "they're", "friends", "."]; - var output = RiTa.untokenize(input); - deepEqual(output, expected); + var expected = "Dr. Chan is talking slowly with Mr. Cheng, and they're friends."; // strange but same as RiTa-java + var input = ["Dr", ".", "Chan", "is", "talking", "slowly", "with", "Mr", ".", "Cheng", ",", "and", "they're", "friends", "."]; + var output = RiTa.untokenize(input); + deepEqual(output, expected); - var input = ["why", "?", "Me", "?", "huh", "?", "!"]; - var expected = "why? Me? huh?!"; - var output = RiTa.untokenize(input); - deepEqual(output, expected); + var input = ["why", "?", "Me", "?", "huh", "?", "!"]; + var expected = "why? Me? huh?!"; + var output = RiTa.untokenize(input); + deepEqual(output, expected); - var input = ["123", "123", "1", "2", "3", "1", ",", "1", "1", ".", "1", "23", ".", "45", ".", "67", "22/05/2012", "12th", "May", ",", "2012"]; - var expected = "123 123 1 2 3 1, 1 1. 1 23. 45. 67 22/05/2012 12th May, 2012"; - var output = RiTa.untokenize(input); - deepEqual(output, expected); - }); + var input = ["123", "123", "1", "2", "3", "1", ",", "1", "1", ".", "1", "23", ".", "45", ".", "67", "22/05/2012", "12th", "May", ",", "2012"]; + var expected = "123 123 1 2 3 1, 1 1. 1 23. 45. 67 22/05/2012 12th May, 2012"; + var output = RiTa.untokenize(input); + deepEqual(output, expected); + }); test("testConjugate", function() { - // TODO: Check against RiTa-java (why are these all doubling?) - - var args = { - tense: RiTa.PRESENT_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON - }; - - s = ["swim", "need", "open"]; - a = ["swims", "needs", "opens"]; - - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - tense: RiTa.PRESENT_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON, - passive: true - }; - - a = ["is swum", "is needed", "is opened"]; - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - //return; - } - - ///////////////////////////////////////////////// - - var args = { - number: RiTa.SINGULAR, - person: RiTa.FIRST_PERSON, - tense: RiTa.PAST_TENSE - }; - - var c = RiTa.conjugate("swim", args); - equal(c, "swam"); - - var s = ["swim", "need", "open", ""]; - var a = ["swam", "needed", "opened", ""]; - - ok(a.length === s.length); - - for (var i = 0; i < s.length; i++) { - var c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - equal("swum", RiTa.getPastParticiple("swim")); - - var args = { - number: RiTa.PLURAL, - person: RiTa.SECOND_PERSON, - tense: RiTa.PAST_TENSE - }; - - var a = ["swam", "needed", "opened", ""]; - ok(a.length === s.length); - - - for (var i = 0; i < s.length; i++) { - var c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - number: RiTa.PLURAL, - person: RiTa.SECOND_PERSON, - tense: RiTa.FUTURE_TENSE - }; - a = ["will swim", "will need", "will open", ""]; - ok(a.length === s.length); - - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - tense: RiTa.PAST_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON - }; - a = ["swam", "needed", "opened", ""]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - tense: RiTa.PAST_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON, - form: RiTa.INFINITIVE - }; - a = ["to swim", "to need", "to open", ""]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - tense: RiTa.PAST_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON, - passive: true - }; - - s = ["scorch", "burn", "hit", ""]; - a = ["was scorched", "was burned", "was hit", ""]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - s = ["swim", "need", "open", ""]; - var args = { - tense: RiTa.PRESENT_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON, - form: RiTa.INFINITIVE, - progressive: true - }; - a = ["to be swimming", "to be needing", "to be opening", ""]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - tense: RiTa.PRESENT_TENSE, - number: RiTa.SINGULAR, - person: RiTa.THIRD_PERSON, - form: RiTa.INFINITIVE, - perfect: true - }; - a = ["to have swum", "to have needed", "to have opened", ""]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - - var args = { - number: RiTa.PLURAL, - person: RiTa.SECOND_PERSON, - tense: RiTa.PAST_TENSE - }; - equal(RiTa.conjugate("barter", args), "bartered"); - equal(RiTa.conjugate("run", args), "ran"); - - s = ["compete", "complete", "eject"]; - a = ["competed", "completed", "ejected"]; - ok(a.length === s.length); - for (var i = 0; i < s.length; i++) { - c = RiTa.conjugate(s[i], args); - equal(c, a[i]); - } - }); + // TODO: Check against RiTa-java (why are these all doubling?) + + var args = { + tense: RiTa.PRESENT_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON + }; + + s = ["swim", "need", "open"]; + a = ["swims", "needs", "opens"]; + + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + tense: RiTa.PRESENT_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON, + passive: true + }; + + a = ["is swum", "is needed", "is opened"]; + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + //return; + } + + ///////////////////////////////////////////////// + + var args = { + number: RiTa.SINGULAR, + person: RiTa.FIRST_PERSON, + tense: RiTa.PAST_TENSE + }; + + var c = RiTa.conjugate("swim", args); + equal(c, "swam"); + + var s = ["swim", "need", "open", ""]; + var a = ["swam", "needed", "opened", ""]; + + ok(a.length === s.length); + + for (var i = 0; i < s.length; i++) { + var c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + equal("swum", RiTa.getPastParticiple("swim")); + + var args = { + number: RiTa.PLURAL, + person: RiTa.SECOND_PERSON, + tense: RiTa.PAST_TENSE + }; + + var a = ["swam", "needed", "opened", ""]; + ok(a.length === s.length); + + + for (var i = 0; i < s.length; i++) { + var c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + number: RiTa.PLURAL, + person: RiTa.SECOND_PERSON, + tense: RiTa.FUTURE_TENSE + }; + a = ["will swim", "will need", "will open", ""]; + ok(a.length === s.length); + + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + tense: RiTa.PAST_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON + }; + a = ["swam", "needed", "opened", ""]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + tense: RiTa.PAST_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON, + form: RiTa.INFINITIVE + }; + a = ["to swim", "to need", "to open", ""]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + tense: RiTa.PAST_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON, + passive: true + }; + + s = ["scorch", "burn", "hit", ""]; + a = ["was scorched", "was burned", "was hit", ""]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + s = ["swim", "need", "open", ""]; + var args = { + tense: RiTa.PRESENT_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON, + form: RiTa.INFINITIVE, + progressive: true + }; + a = ["to be swimming", "to be needing", "to be opening", ""]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + tense: RiTa.PRESENT_TENSE, + number: RiTa.SINGULAR, + person: RiTa.THIRD_PERSON, + form: RiTa.INFINITIVE, + perfect: true + }; + a = ["to have swum", "to have needed", "to have opened", ""]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + + var args = { + number: RiTa.PLURAL, + person: RiTa.SECOND_PERSON, + tense: RiTa.PAST_TENSE + }; + equal(RiTa.conjugate("barter", args), "bartered"); + equal(RiTa.conjugate("run", args), "ran"); + + s = ["compete", "complete", "eject"]; + a = ["competed", "completed", "ejected"]; + ok(a.length === s.length); + for (var i = 0; i < s.length; i++) { + c = RiTa.conjugate(s[i], args); + equal(c, a[i]); + } + }); // no need to extract - asyncTest("testTimerAsync", function() { + /*asyncTest("testTimerAsync", function() { var functionToTrigger = function() { functionToTrigger.countInstances++; @@ -1394,9 +1402,9 @@ var runtests = function() { RiTa.stopTimer(id); }, 400); - }); + });*/ -} // end runtests + } // end runtests if (typeof exports != 'undefined') runtests(); diff --git a/test/RiText-tests.js b/test/RiText-tests.js index a429a937..7098c686 100755 --- a/test/RiText-tests.js +++ b/test/RiText-tests.js @@ -3,1284 +3,1276 @@ var runtests = function() { - var tmp; - QUnit.module("RiText", { - - setup: function () { + var tmp; + QUnit.module("RiText", { - tmp = RiTa.SILENT; - RiTa.SILENT = true; - }, - teardown: function () { + setup: function() { - RiTa.SILENT = tmp; - } - }); - - test("testCheckAPI", function() { // Can this move to QUnit-Callbacks? - - if (typeof QUnit.propertiesFromAPI != 'function') { - - ok(typeof exports == 'undefined'); // not in node, ignore for now - return; - } - - var eles = QUnit.propertiesFromAPI('RiText'), name, obj = new RiText(); - - for ( var i = 0; i < eles.length; i++) { - - if (eles[i].isVar) { - - if (/^defaults\./.test(eles[i].name)) { // strange-case for static field (generalize) - - name = eles[i].name.substring('defaults.'.length); - ok(RiText.defaults.hasOwnProperty(name), 'default-var: '+eles[i].name); - } - else { - ok(obj.hasOwnProperty(eles[i].name), 'var: '+eles[i].name); - } - - } - else if (eles[i].isStatic) { - - equal(typeof RiText[eles[i].name], 'function(static): ', RiText[eles[i].name]); - } - else { - - equal(typeof obj[eles[i].name], 'function', 'function: '+eles[i].name+'()'); - } + tmp = RiTa.SILENT; + RiTa.SILENT = true; + }, + teardown: function() { + + RiTa.SILENT = tmp; + } + }); + + test("testCheckAPI", function() { // Can this move to QUnit-Callbacks? + + if (typeof QUnit.propertiesFromAPI != 'function') { + + ok(typeof exports == 'undefined'); // not in node, ignore for now + return; + } + + var eles = QUnit.propertiesFromAPI('RiText'), + name, obj = new RiText(); + + for (var i = 0; i < eles.length; i++) { + + if (eles[i].isVar) { + + if (/^defaults\./.test(eles[i].name)) { // strange-case for static field (generalize) + + name = eles[i].name.substring('defaults.'.length); + ok(RiText.defaults.hasOwnProperty(name), 'default-var: ' + eles[i].name); + } else { + ok(obj.hasOwnProperty(eles[i].name), 'var: ' + eles[i].name); } - }); - test("RiText()", function() { - - ok(new RiText("The dog was white")); - - ok(RiText("The dog was white")); - - ok(RiText("")); - - ok(RiText()); - ok(RiText(123)); - - ok(RiText(" ")); - equal(RiText(" ").length(), 1); - - ok(new RiText(RiString("The dog was white"))); - ok(RiText(RiString("The dog was white"))); - ok(RiText(new RiString("The dog was white"))); - ok(new RiText(new RiString("The dog was white"))); - - ok(RiText(new RiString(""))); - ok(RiText(new RiString(123))); - - var BADS = [ null, undefined ] - for ( var i = 0; i < BADS.length; i++) { - throws(function() { - - try { - new RiText(BADS[i]); - fail("no exception"); - } - catch (e) { - throw e; - } - }); - throws(function() { - - try { - RiText(BADS[i]); - fail("no exception"); - } - catch (e) { - throw e; - } - }); + } else if (eles[i].isStatic) { + + equal(typeof RiText[eles[i].name], 'function(static): ', RiText[eles[i].name]); + } else { + + equal(typeof obj[eles[i].name], 'function', 'function: ' + eles[i].name + '()'); + } + } + }); + + test("RiText()", function() { + + ok(new RiText("The dog was white")); + + ok(RiText("The dog was white")); + + ok(RiText("")); + + ok(RiText()); + ok(RiText(123)); + + ok(RiText(" ")); + equal(RiText(" ").length(), 1); + + ok(new RiText(RiString("The dog was white"))); + ok(RiText(RiString("The dog was white"))); + ok(RiText(new RiString("The dog was white"))); + ok(new RiText(new RiString("The dog was white"))); + + ok(RiText(new RiString(""))); + ok(RiText(new RiString(123))); + + var BADS = [null, undefined] + for (var i = 0; i < BADS.length; i++) { + throws(function() { + + try { + new RiText(BADS[i]); + fail("no exception"); + } catch (e) { + throw e; + } + }); + throws(function() { + + try { + RiText(BADS[i]); + fail("no exception"); + } catch (e) { + throw e; } + }); + } - }); - - test("RiText(this)", function() { - - ok(new RiText(this, "The dog was white")); - - ok(RiText(this, "The dog was white")); - - ok(RiText(this, "")); - - ok(RiText(this)); - ok(RiText(this, 123)); - - ok(RiText(this," ")); - equal(RiText(this," ").length(), 1); - - ok(new RiText(this, RiString("The dog was white"))); - ok(RiText(this, RiString("The dog was white"))); - ok(RiText(this, new RiString("The dog was white"))); - ok(new RiText(this, new RiString("The dog was white"))); - - ok(RiText(this, RiString(""))); - - ok(RiText(this, new RiString(123))); - - var BADS = [ null, undefined ] - for ( var i = 0; i < BADS.length; i++) { - throws(function() { - - try { - new RiText(this,BADS[i]); - fail("no exception"); - } - catch (e) { - throw e; - } - }); - throws(function() { - - try { - RiText(this,BADS[i]); - fail("no exception"); - } - catch (e) { - throw e; - } - }); + }); + + test("RiText(this)", function() { + + ok(new RiText(this, "The dog was white")); + + ok(RiText(this, "The dog was white")); + + ok(RiText(this, "")); + + ok(RiText(this)); + ok(RiText(this, 123)); + + ok(RiText(this, " ")); + equal(RiText(this, " ").length(), 1); + + ok(new RiText(this, RiString("The dog was white"))); + ok(RiText(this, RiString("The dog was white"))); + ok(RiText(this, new RiString("The dog was white"))); + ok(new RiText(this, new RiString("The dog was white"))); + + ok(RiText(this, RiString(""))); + + ok(RiText(this, new RiString(123))); + + var BADS = [null, undefined] + for (var i = 0; i < BADS.length; i++) { + throws(function() { + + try { + new RiText(this, BADS[i]); + fail("no exception"); + } catch (e) { + throw e; } + }); + throws(function() { + + try { + RiText(this, BADS[i]); + fail("no exception"); + } catch (e) { + throw e; + } + }); + } - }); + }); - //--------------------------RiString Functions----------------------------- + //--------------------------RiString Functions----------------------------- - //---------------------------COPY FROM RISTRING TESTS + //---------------------------COPY FROM RISTRING TESTS - test("testAnalyze()", function() { + test("testAnalyze()", function() { - var features = RiText("the laggin dragon").analyze().features(); - ok(features); - equal(features.phonemes, "dh-ax l-ae-g-ih-n d-r-ae-g-aa-n"); - equal(features.syllables, "dh-ax l-ae/g-ih-n d-r-ae-g/aa-n"); - equal(features.stresses, "0 1/1 1/0"); + var features = RiText("the laggin dragon").analyze().features(); + ok(features); + equal(features.phonemes, "dh-ax l-ae-g-ih-n d-r-ae-g-aa-n"); + equal(features.syllables, "dh-ax l-ae/g-ih-n d-r-ae-g/aa-n"); + equal(features.stresses, "0 1/1 1/0"); - var features = RiText("123").analyze().features(); - ok(features); - equal(features.phonemes, "w-ah-n-t-uw-th-r-iy"); - equal(features.syllables, "w-ah-n/t-uw/th-r-iy"); - equal(features.stresses, "0/0/0"); + var features = RiText("123").analyze().features(); + ok(features); + equal(features.phonemes, "w-ah-n-t-uw-th-r-iy"); + equal(features.syllables, "w-ah-n/t-uw/th-r-iy"); + equal(features.stresses, "0/0/0"); - var features = RiText("123").analyze().features(); - ok(features); - equal(features.phonemes, "w-ah-n-t-uw-th-r-iy"); - equal(features.syllables, "w-ah-n/t-uw/th-r-iy"); - equal(features.stresses, "0/0/0"); + var features = RiText("123").analyze().features(); + ok(features); + equal(features.phonemes, "w-ah-n-t-uw-th-r-iy"); + equal(features.syllables, "w-ah-n/t-uw/th-r-iy"); + equal(features.stresses, "0/0/0"); - var features = RiText("1 2 7").analyze().features(); - ok(features); - equal(features.phonemes, "w-ah-n t-uw s-eh-v-ax-n"); - equal(features.syllables, "w-ah-n t-uw s-eh/v-ax-n"); - equal(features.stresses, "0 0 1/0"); - }); + var features = RiText("1 2 7").analyze().features(); + ok(features); + equal(features.phonemes, "w-ah-n t-uw s-eh-v-ax-n"); + equal(features.syllables, "w-ah-n t-uw s-eh/v-ax-n"); + equal(features.stresses, "0 0 1/0"); + }); - test("testFeatures()", function() { - - var rs = [ RiText("Returns the array of words."), RiText(this,"Returns the array of words.")]; - for (var i=0; i < rs.length; i++) { - - var features = rs[i].features(); - //console.log(features); - ok(features); - ok(features.syllables); - ok(features.phonemes); - ok(features.stresses); - - //ok(features.mutable); - ok(features.tokens); - ok(features.text); - ok(features.pos); - } - - }); - - test("testCharAt()", function() { - - var rs = [new RiText("The dog was white"),RiText("The dog was white")]; - - for (var i=0; i < rs.length; i++) { - var r = rs[i]; - var result = r.charAt(0); - equal(result, "T"); - - var result = r.charAt(5); - notEqual(result, "O"); - - var result = r.charAt(5); - notEqual(result, '*'); - - var result = r.charAt(200); //out of range character - equal(result, ""); - } - }); - - test("testConcat()", function() { - - var rs = new RiText("The dog was white"); - var rs2 = new RiText("The dog was not white"); - var result = rs.concat(rs2); - equal(result, "The dog was whiteThe dog was not white"); - - var rs = new RiText(" The dog was white "); - var rs2 = new RiText("The dog was not white "); - var result = rs.concat(rs2); - equal(result, " The dog was white The dog was not white "); - - var rs = new RiText("#$#@#$@#"); - var rs2 = new RiText("The dog was not white "); - var result = rs.concat(rs2); - equal(result, "#$#@#$@#The dog was not white "); - - var BADS = [ "sometext",null, undefined ]; - for ( var i = 0; i < BADS.length; i++) { - var rs = new RiText(" The dog was white "); - throws(function() { - try { - - rs.concat(BADS[i]); - fail("no exception"); - } - catch (e) { - throw e; - } - }); + test("testFeatures()", function() { + + var rs = [RiText("Returns the array of words."), RiText(this, "Returns the array of words.")]; + for (var i = 0; i < rs.length; i++) { + + var features = rs[i].features(); + //console.log(features); + ok(features); + ok(features.syllables); + ok(features.phonemes); + ok(features.stresses); + + //ok(features.mutable); + ok(features.tokens); + ok(features.text); + ok(features.pos); + } + + }); + + test("testCharAt()", function() { + + var rs = [new RiText("The dog was white"), RiText("The dog was white")]; + + for (var i = 0; i < rs.length; i++) { + var r = rs[i]; + var result = r.charAt(0); + equal(result, "T"); + + var result = r.charAt(5); + notEqual(result, "O"); + + var result = r.charAt(5); + notEqual(result, '*'); + + var result = r.charAt(200); //out of range character + equal(result, ""); + } + }); + + test("testConcat()", function() { + + var rs = new RiText("The dog was white"); + var rs2 = new RiText("The dog was not white"); + var result = rs.concat(rs2); + equal(result, "The dog was whiteThe dog was not white"); + + var rs = new RiText(" The dog was white "); + var rs2 = new RiText("The dog was not white "); + var result = rs.concat(rs2); + equal(result, " The dog was white The dog was not white "); + + var rs = new RiText("#$#@#$@#"); + var rs2 = new RiText("The dog was not white "); + var result = rs.concat(rs2); + equal(result, "#$#@#$@#The dog was not white "); + + var BADS = ["sometext", null, undefined]; + for (var i = 0; i < BADS.length; i++) { + var rs = new RiText(" The dog was white "); + throws(function() { + try { + + rs.concat(BADS[i]); + fail("no exception"); + } catch (e) { + throw e; } - - + }); + } - }); - test("testContainsWord", function() { - // check that these are ok --- ------------ - var rs = new RiText("The dog was white"); + }); - ok(rs.containsWord("dog")); - ok(rs.containsWord("")); - ok(!rs.containsWord("*")); - ok(!rs.containsWord(".")); - ok(!rs.containsWord("brown")); - }); + test("testContainsWord", function() { - test("testEndsWith()", function() { + // check that these are ok --- ------------ + var rs = new RiText("The dog was white"); - // check that these are ok -------------- - var rs = new RiText("girls"); - var result = rs.endsWith("s"); - ok(result); + ok(rs.containsWord("dog")); + ok(rs.containsWord("")); + ok(!rs.containsWord("*")); + ok(!rs.containsWord(".")); + ok(!rs.containsWord("brown")); + }); - var rs = new RiText("closed"); - var result = rs.endsWith("ed"); - ok(result); + test("testEndsWith()", function() { - var rs = new RiText("The dog was white"); - var result = rs.endsWith("white"); - ok(result); + // check that these are ok -------------- + var rs = new RiText("girls"); + var result = rs.endsWith("s"); + ok(result); - var rs = new RiText(""); - var result = rs.endsWith(""); - ok(result); + var rs = new RiText("closed"); + var result = rs.endsWith("ed"); + ok(result); - }); + var rs = new RiText("The dog was white"); + var result = rs.endsWith("white"); + ok(result); - test("testEquals()", function() { // compare Object - - // check that these are ok --------------- - var rs = new RiText("closed"); - var rs2 = new RiText("closed"); - var result = rs.equals(rs2); - ok(result); - - var rs = new RiText("closed"); - var rs2 = new RiText("Closed"); - var result = rs.equals(rs2); - ok(!result); - - var rs = new RiText("clOsed"); - var rs2 = new RiText("closed"); - var result = rs.equals(rs2); - ok(!result); - - var rs = new RiText("There is a cat."); - var rs2 = new RiText("There is a cat."); - var result = rs.equals(rs2); - ok(result); - - var rs = new RiText("There is a cat."); - var rs2 = new RiText("There is a cat. "); - var result = rs.equals(rs2); - ok(!result); - - var rs = new RiText("There is a cat."); - var rs2 = new RiText("There is a cat"); - var result = rs.equals(rs2); - ok(!result); - - var rs = new RiText("There is a cat."); - var rs2 = new RiText(""); - var result = rs.equals(rs2); - ok(!result); - - var rs = new RiText(""); - var rs2 = new RiText(""); - var result = rs.equals(rs2); - ok(result); - }); + var rs = new RiText(""); + var result = rs.endsWith(""); + ok(result); + }); - test("testEqualsIgnoreCase()", function() { + test("testEquals()", function() { // compare Object - // check that these are ok --------------- - var rs = new RiText("closed"); - var result = rs.equalsIgnoreCase("Closed"); - ok(result); + // check that these are ok --------------- + var rs = new RiText("closed"); + var rs2 = new RiText("closed"); + var result = rs.equals(rs2); + ok(result); - var rs = new RiText("There is a cat."); - var result = rs.equalsIgnoreCase("TheRe Is a cAt."); - ok(result); + var rs = new RiText("closed"); + var rs2 = new RiText("Closed"); + var result = rs.equals(rs2); + ok(!result); - var rs = new RiText("THere iS a Cat."); - var result = rs.equalsIgnoreCase("TheRe Is a cAt."); - ok(result); + var rs = new RiText("clOsed"); + var rs2 = new RiText("closed"); + var result = rs.equals(rs2); + ok(!result); - var rs = new RiText("THere iS a Cat."); - var rs2 = new RiText("THere iS a Cat."); - var result = rs.equalsIgnoreCase(rs2); - ok(result); + var rs = new RiText("There is a cat."); + var rs2 = new RiText("There is a cat."); + var result = rs.equals(rs2); + ok(result); - var rs = new RiText("THere iS a Cat."); - var rs2 = new RiText("THere iS not a Cat."); - var result = rs.equalsIgnoreCase(rs2); - ok(!result); + var rs = new RiText("There is a cat."); + var rs2 = new RiText("There is a cat. "); + var result = rs.equals(rs2); + ok(!result); - var rs = new RiText(""); - var result = rs.equalsIgnoreCase(""); - ok(result); + var rs = new RiText("There is a cat."); + var rs2 = new RiText("There is a cat"); + var result = rs.equals(rs2); + ok(!result); + var rs = new RiText("There is a cat."); + var rs2 = new RiText(""); + var result = rs.equals(rs2); + ok(!result); - }); + var rs = new RiText(""); + var rs2 = new RiText(""); + var result = rs.equals(rs2); + ok(result); + }); - /* - * test("testGet()", function () { - * - * var rs = RiText("The laggin dragon").analyze(); var ph = rs.get(RiTa.PHONEMES); var sy = - * rs.get(RiTa.SYLLABLES); var st = rs.get(RiTa.STRESSES); equal(ph, "dh-ax l-ae-g-ih-n - * d-r-ae-g-aa-n"); equal(sy, "dh-ax l-ae/g-ih-n d-r-ae-g/aa-n"); equal(st, "0 1/1 1/0"); - * }); - */ + test("testEqualsIgnoreCase()", function() { + // check that these are ok --------------- + var rs = new RiText("closed"); + var result = rs.equalsIgnoreCase("Closed"); + ok(result); - test("testIndexOf()", function() { + var rs = new RiText("There is a cat."); + var result = rs.equalsIgnoreCase("TheRe Is a cAt."); + ok(result); - // check that these are ok --------------- - var rs = new RiText("Returns the array of words."); - var result = rs.indexOf("e"); - equal(result, 1); + var rs = new RiText("THere iS a Cat."); + var result = rs.equalsIgnoreCase("TheRe Is a cAt."); + ok(result); - var rs = new RiText("Returns the array of words ."); - var result = rs.indexOf("a"); - equal(result, 12); + var rs = new RiText("THere iS a Cat."); + var rs2 = new RiText("THere iS a Cat."); + var result = rs.equalsIgnoreCase(rs2); + ok(result); - var rs = new RiText("s ."); //space - var result = rs.indexOf(" "); - equal(result, 1); + var rs = new RiText("THere iS a Cat."); + var rs2 = new RiText("THere iS not a Cat."); + var result = rs.equalsIgnoreCase(rs2); + ok(!result); + + var rs = new RiText(""); + var result = rs.equalsIgnoreCase(""); + ok(result); + + + }); + + /* + * test("testGet()", function () { + * + * var rs = RiText("The laggin dragon").analyze(); var ph = rs.get(RiTa.PHONEMES); var sy = + * rs.get(RiTa.SYLLABLES); var st = rs.get(RiTa.STRESSES); equal(ph, "dh-ax l-ae-g-ih-n + * d-r-ae-g-aa-n"); equal(sy, "dh-ax l-ae/g-ih-n d-r-ae-g/aa-n"); equal(st, "0 1/1 1/0"); + * }); + */ + + + test("testIndexOf()", function() { + + // check that these are ok --------------- + var rs = new RiText("Returns the array of words."); + var result = rs.indexOf("e"); + equal(result, 1); + + var rs = new RiText("Returns the array of words ."); + var result = rs.indexOf("a"); + equal(result, 12); + + var rs = new RiText("s ."); //space + var result = rs.indexOf(" "); + equal(result, 1); + + var rs = new RiText("s ."); //double space + var result = rs.indexOf(" "); + equal(result, 1); + + var rs = new RiText(" abc"); //space + var result = rs.indexOf(" "); + equal(result, 0); + + var rs = new RiText(" abc"); //double space + var result = rs.indexOf(" "); + equal(result, 0); + + var rs = new RiText(" abc"); //tap space + var result = rs.indexOf(" "); + equal(result, 0); + + var rs = new RiText("Returns the array of words ."); + var result = rs.indexOf("array"); + equal(result, 12); + + var rs = new RiText("Returns the array of words."); + var result = rs.indexOf(","); + equal(result, -1); + + var rs = new RiText("Returns the array of words. Returns the array of words."); + var result = rs.indexOf("a", 13); + equal(result, 15); + + var rs = new RiText("Returns the array of words. Returns the array of words?"); + var result = rs.indexOf("array", 13); + equal(result, 40); - var rs = new RiText("s ."); //double space - var result = rs.indexOf(" "); - equal(result, 1); + var rs = new RiText("Returns the array of words. Returns the array of words."); + var result = rs.indexOf(""); + equal(result, 0); - var rs = new RiText(" abc"); //space - var result = rs.indexOf(" "); - equal(result, 0); + }); + + test("testInsertWord()", function() { - var rs = new RiText(" abc"); //double space - var result = rs.indexOf(" "); - equal(result, 0); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(4, "then"); + equal(rs.text(), "Inserts at wordIdx and then shifts each subsequent word accordingly."); - var rs = new RiText(" abc"); //tap space - var result = rs.indexOf(" "); - equal(result, 0); + var rs = new RiText("inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(0, "He"); + equal("He inserts at wordIdx and shifts each subsequent word accordingly.", rs.text()); - var rs = new RiText("Returns the array of words ."); - var result = rs.indexOf("array"); - equal(result, 12); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(1, "newWord"); + var rs2 = new RiText( + "Inserts newWord at wordIdx and shifts each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - var rs = new RiText("Returns the array of words."); - var result = rs.indexOf(","); - equal(result, -1); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(1, "newWord and newWords"); + var rs2 = new RiText( + "Inserts newWord and newWords at wordIdx and shifts each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - var rs = new RiText("Returns the array of words. Returns the array of words."); - var result = rs.indexOf("a", 13); - equal(result, 15); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(5, ""); + var rs2 = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - var rs = new RiText("Returns the array of words. Returns the array of words?"); - var result = rs.indexOf("array", 13); - equal(result, 40); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(5, " "); //space + var rs2 = new RiText( + "Inserts at wordIdx and shifts each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - var rs = new RiText("Returns the array of words. Returns the array of words."); - var result = rs.indexOf(""); - equal(result, 0); + //console.log(rs.text()); return; - }); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(5, " "); //tab space + var rs2 = new RiText( + "Inserts at wordIdx and shifts each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - test( "testInsertWord()", function() { - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(4,"then"); - equal(rs.text(), "Inserts at wordIdx and then shifts each subsequent word accordingly."); - - var rs = new RiText("inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(0,"He"); - equal("He inserts at wordIdx and shifts each subsequent word accordingly.", rs.text()); - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(1,"newWord"); - var rs2 = new RiText( - "Inserts newWord at wordIdx and shifts each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(1,"newWord and newWords"); - var rs2 = new RiText( - "Inserts newWord and newWords at wordIdx and shifts each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(5,""); - var rs2 = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(5," "); //space - var rs2 = new RiText( - "Inserts at wordIdx and shifts each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - -//console.log(rs.text()); return; - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(5," "); //tab space - var rs2 = new RiText( - "Inserts at wordIdx and shifts each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - // not sure what to do about this one, either it OR the next one will fail either way - /* TODO: reconsider */ - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(5,"**"); - var rs2 = new RiText( - "Inserts at wordIdx and shifts ** each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - var rs = new RiText("Inserts at wordIdx shifting each subsequent word accordingly."); - rs.insertWord(3,","); - var rs2 = new RiText("Inserts at wordIdx , shifting each subsequent word accordingly."); - equal(rs.text(), rs2.text()); - - var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); - rs.insertWord(-2, "newWord"); //error -- (no change to original string); - equal("Inserts at wordIdx and shifts each subsequent word newWord accordingly.", rs.text()); - - }); - - test("testLastIndexOf()", function() { //TODO revise - - // check that these are ok --- ------------ - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf("r"); - equal(result, 48); - - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf("Start"); - equal(result, 26); - - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf("start"); - equal(result, -1); - - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf("a", 12); - equal(result, 6); - - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf("at", 12); - equal(result, 6); - - var rs = new RiText("Start at first character. Start at last character."); - var result = rs.lastIndexOf(""); - equal(result, rs.length()); // should be 50 or -1? 50(DCH) - }); + // not sure what to do about this one, either it OR the next one will fail either way + /* TODO: reconsider */ + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(5, "**"); + var rs2 = new RiText( + "Inserts at wordIdx and shifts ** each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - test("testLength()", function() { + var rs = new RiText("Inserts at wordIdx shifting each subsequent word accordingly."); + rs.insertWord(3, ","); + var rs2 = new RiText("Inserts at wordIdx , shifting each subsequent word accordingly."); + equal(rs.text(), rs2.text()); - var rs = new RiText("S"); - var result = rs.length(); - equal(result, 1); + var rs = new RiText("Inserts at wordIdx and shifts each subsequent word accordingly."); + rs.insertWord(-2, "newWord"); //error -- (no change to original string); + equal("Inserts at wordIdx and shifts each subsequent word newWord accordingly.", rs.text()); - var rs = new RiText("s "); //space - var result = rs.length(); - equal(result, 2); + }); - var rs = new RiText("s" + '\t'); //tab space - var result = rs.length(); - equal(result, 2); + test("testLastIndexOf()", function() { //TODO revise - var rs = new RiText(" s "); //2 space - var result = rs.length(); - equal(result, 3); + // check that these are ok --- ------------ + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf("r"); + equal(result, 48); - var rs = new RiText('\t' + "s" + '\t'); // 2 tab space - var result = rs.length(); - equal(result, 3); + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf("Start"); + equal(result, 26); - var rs = new RiText("s b"); - var result = rs.length(); - equal(result, 3); + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf("start"); + equal(result, -1); - var rs = new RiText("s b."); - var result = rs.length(); - equal(result, 4); + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf("a", 12); + equal(result, 6); - var rs = new RiText("s b ."); //space - var result = rs.length(); - equal(result, 5); + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf("at", 12); + equal(result, 6); - var rs = new RiText("><><><#$!$@$@!$"); - var result = rs.length(); - equal(result, 15); + var rs = new RiText("Start at first character. Start at last character."); + var result = rs.lastIndexOf(""); + equal(result, rs.length()); // should be 50 or -1? 50(DCH) + }); - var rs = new RiText(""); - var result = rs.length(); - equal(result, 0); + test("testLength()", function() { - // no error checks needed - }); + var rs = new RiText("S"); + var result = rs.length(); + equal(result, 1); + var rs = new RiText("s "); //space + var result = rs.length(); + equal(result, 2); - test("testMatch()", function() { - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - var result = rs.match(/ain/g); - deepEqual(result, [ "ain", "ain", "ain" ]); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - var result = rs.match(/ain/gi); - deepEqual(result, [ "ain", "AIN", "ain", "ain" ]); - - var rs = new RiText("Watch out for the rock!"); - var result = rs.match(/r?or?/g); - deepEqual(result, [ "o", "or", "ro" ]); - - var rs = new RiText("abc!"); - var result = rs.match(/r?or?/g); - deepEqual(result, []); - - var rs = new RiText("Letter !>D? hello 213331123"); - var result = rs.match(/[A-Za-z]/g); - deepEqual(result, ["L", "e", "t", "t", "e", "r", "D", "h", "e", "l", "l", "o"]); - - var rs = new RiText("Letter !>D? hello 213331123"); - var result = rs.match(/\W/g); - deepEqual(result, [" ", "!", ">", "?", " ", " "]); - - var rs = new RiText("Letter !>D? hello 213331123"); - var result = rs.match(/[^0-9]/g); - deepEqual(result, ["L", "e", "t", "t", "e", "r", " ", "!", ">", "D", "?", " ", "h", "e", "l", "l", "o", " "]); - - var rs = new RiText("!@#$%^&*()__+"); - var result = rs.match(/X|Z/g); - deepEqual(result, []); - - var rs = new RiText("!@#$%^&*()__+"); - var result = rs.match(/!|Z/g); - deepEqual(result, ["!"]); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - var result = rs.match(/ain/g); - deepEqual(result, ["ain", "ain", "ain" ]); - - //case-insensitive tests - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - var result = rs.match(/ain/gi); - deepEqual(result, [ "ain", "AIN", "ain", "ain" ]); - }); + var rs = new RiText("s" + '\t'); //tab space + var result = rs.length(); + equal(result, 2); - test("testPos()", function() { + var rs = new RiText(" s "); //2 space + var result = rs.length(); + equal(result, 3); - // TODO: check that these are ok -------------- + var rs = new RiText('\t' + "s" + '\t'); // 2 tab space + var result = rs.length(); + equal(result, 3); - var rs = new RiText("asdfaasd"); - var result = rs.pos(); - deepEqual(result, [ "nn" ]); + var rs = new RiText("s b"); + var result = rs.length(); + equal(result, 3); - var rs = new RiText("clothes"); - var result = rs.pos(); - deepEqual(result, [ "nns" ]); + var rs = new RiText("s b."); + var result = rs.length(); + equal(result, 4); - var rs = new RiText("There is a cat."); - var result = rs.pos(); - deepEqual([ "ex", "vbz", "dt", "nn", "." ], result); + var rs = new RiText("s b ."); //space + var result = rs.length(); + equal(result, 5); - var rs = new RiText("The boy, dressed in red, ate an apple."); - var result = rs.pos(); - deepEqual([ "dt", "nn", ",", "vbn", "in", "jj", ",", "vbd", "dt", "nn", "." ], result); - }); + var rs = new RiText("><><><#$!$@$@!$"); + var result = rs.length(); + equal(result, 15); - test("testPosAt()", function() { + var rs = new RiText(""); + var result = rs.length(); + equal(result, 0); - // check that these are ok --------------- - var rs = new RiText("The emperor had no clothes on."); - var result = rs.posAt(4); - equal("nns", result); + // no error checks needed + }); - var rs = new RiText("There is a cat."); - var result = rs.posAt(3); - equal("nn", result); - }); - test("testRemoveChar()", function() { + test("testMatch()", function() { - var rs = new RiText("The dog was white"); - var result = rs.removeChar(1); - equal(rs.text(), "Te dog was white"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + var result = rs.match(/ain/g); + deepEqual(result, ["ain", "ain", "ain"]); - var rs = new RiText("The dog was white"); - var result = rs.removeChar(rs.length() - 1); - equal(rs.text(), "The dog was whit"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + var result = rs.match(/ain/gi); + deepEqual(result, ["ain", "AIN", "ain", "ain"]); - var rs = new RiText("The dog was white"); - var result = rs.removeChar(rs.length()); - equal(rs.text(), "The dog was white"); + var rs = new RiText("Watch out for the rock!"); + var result = rs.match(/r?or?/g); + deepEqual(result, ["o", "or", "ro"]); - var rs = new RiText("The dog was white"); - var result = rs.removeChar(0); - equal(rs.text(), "he dog was white"); + var rs = new RiText("abc!"); + var result = rs.match(/r?or?/g); + deepEqual(result, []); - var rs = new RiText("The dog was white"); - var result = rs.removeChar(-1); - equal(rs.text(), "The dog was whit"); + var rs = new RiText("Letter !>D? hello 213331123"); + var result = rs.match(/[A-Za-z]/g); + deepEqual(result, ["L", "e", "t", "t", "e", "r", "D", "h", "e", "l", "l", "o"]); - var rs = new RiText("The dog was white"); - var result = rs.removeChar(1000); - equal(rs.text(), "The dog was white"); + var rs = new RiText("Letter !>D? hello 213331123"); + var result = rs.match(/\W/g); + deepEqual(result, [" ", "!", ">", "?", " ", " "]); - var rs = new RiText("The dog was white."); - var result = rs.removeChar(rs.length() - 1); - equal(rs.text(), "The dog was white"); - }); + var rs = new RiText("Letter !>D? hello 213331123"); + var result = rs.match(/[^0-9]/g); + deepEqual(result, ["L", "e", "t", "t", "e", "r", " ", "!", ">", "D", "?", " ", "h", "e", "l", "l", "o", " "]); - test("testReplaceChar()", function() { + var rs = new RiText("!@#$%^&*()__+"); + var result = rs.match(/X|Z/g); + deepEqual(result, []); - var rs = new RiText("Who are you?"); - rs.replaceChar(2, ""); - equal(rs.text(), "Wh are you?"); + var rs = new RiText("!@#$%^&*()__+"); + var result = rs.match(/!|Z/g); + deepEqual(result, ["!"]); - var rs = new RiText("Who are you?"); - rs.replaceChar(2, "e"); - equal(rs.text(), "Whe are you?"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + var result = rs.match(/ain/g); + deepEqual(result, ["ain", "ain", "ain"]); - var rs = new RiText("Who are you?"); - rs.replaceChar(2, "ere"); - equal(rs.text(), "Where are you?"); + //case-insensitive tests + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + var result = rs.match(/ain/gi); + deepEqual(result, ["ain", "AIN", "ain", "ain"]); + }); - var rs = new RiText("Who are you?"); - rs.replaceChar(11, "!!"); - equal(rs.text(), "Who are you!!"); + test("testPos()", function() { - var rs = new RiText("Who are you?"); - rs.replaceChar(0, "me"); - equal(rs.text(), "meho are you?"); + // TODO: check that these are ok -------------- - var rs = new RiText("Who are you?"); - rs.replaceChar(-1, "me"); - equal(rs.text(), "Who are youme"); + var rs = new RiText("asdfaasd"); + var result = rs.pos(); + deepEqual(result, ["nn"]); - var rs = new RiText("Who are you?"); - rs.replaceChar(10000, "me"); - equal(rs.text(), "Who are you?"); + var rs = new RiText("clothes"); + var result = rs.pos(); + deepEqual(result, ["nns"]); - }); + var rs = new RiText("There is a cat."); + var result = rs.pos(); + deepEqual(["ex", "vbz", "dt", "nn", "."], result); - test("testReplaceFirst()", function() { - - var rs = new RiText("Who are you?"); - rs.replaceFirst("e", "E"); - equal(rs.text(), "Who arE you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("o", "O"); - equal(rs.text(), "WhO are you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("Who", "Where"); - equal(rs.text(), "Where are you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("notExist", "Exist"); - equal(rs.text(), "Who are you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("Who are", "Dare"); - equal(rs.text(), "Dare you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("Who aRe", "Dare"); - equal(rs.text(), "Who are you?"); - - var rs = new RiText("Who are you? Who are you?"); - rs.replaceFirst("Who are", "Dare"); - equal(rs.text(), "Dare you? Who are you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("?", "?!"); - equal(rs.text(), "Who are you?!"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("", ""); - equal(rs.text(), "Who are you?"); - - var rs = new RiText("Who are you?"); - rs.replaceFirst("?", "?!"); - equal(rs.text(), "Who are you?!"); - - //regex - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/ain/, "ane"); - equal(rs.text(), "The rane in SPAIN stays mainly in the plain"); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/ain/i, "oll"); - equal(rs.text(), "The roll in SPAIN stays mainly in the plain"); - - var rs = new RiText("Watch out for the rock!"); - rs.replaceFirst(/r?or?/, "a"); - equal(rs.text(), "Watch aut for the rock!"); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/in/, "d"); - equal(rs.text(), "The rad in SPAIN stays mainly in the plain"); - - // global should have not affect - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/ain/g, "ane"); - equal(rs.text(), "The rane in SPAIN stays mainly in the plain"); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/ain/gi, "oll"); - equal(rs.text(), "The roll in SPAIN stays mainly in the plain"); - - var rs = new RiText("Watch out for the rock!"); - rs.replaceFirst(/r?or?/g, "a"); - equal(rs.text(), "Watch aut for the rock!"); - - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceFirst(/in/g, "d"); - equal(rs.text(), "The rad in SPAIN stays mainly in the plain"); - }); + var rs = new RiText("The boy, dressed in red, ate an apple."); + var result = rs.pos(); + deepEqual(["dt", "nn", ",", "vbn", "in", "jj", ",", "vbd", "dt", "nn", "."], result); + }); + test("testPosAt()", function() { - test("testReplaceAll()", function() { + // check that these are ok --------------- + var rs = new RiText("The emperor had no clothes on."); + var result = rs.posAt(4); + equal("nns", result); - //replaceAll(regex, replacement); - var rs = new RiText("Who are you? Who is he? Who is it?"); - equal(rs.replaceAll("e", "E").text(), "Who arE you? Who is hE? Who is it?"); + var rs = new RiText("There is a cat."); + var result = rs.posAt(3); + equal("nn", result); + }); - var rs = new RiText("Who are you? Who is he? Who is it?"); - equal(rs.replaceAll("Who", "O").text(), "O are you? O is he? O is it?"); + test("testRemoveChar()", function() { - var rs = new RiText("Whom is he? Where is he? What is it?"); - equal(rs.replaceAll("Wh*", "O").text(), "Whom is he? Where is he? What is it?"); + var rs = new RiText("The dog was white"); + var result = rs.removeChar(1); + equal(rs.text(), "Te dog was white"); - var rs = new RiText("Whom is he? Where is he? What is it?"); - equal(rs.replaceAll(/Wh*/, "O").text(), "Oom is he? Oere is he? Oat is it?"); + var rs = new RiText("The dog was white"); + var result = rs.removeChar(rs.length() - 1); + equal(rs.text(), "The dog was whit"); - var rs = new RiText("%^&%&?"); - equal(rs.replaceAll("%^&%&?", "!!!").text(), "!!!"); - + var rs = new RiText("The dog was white"); + var result = rs.removeChar(rs.length()); + equal(rs.text(), "The dog was white"); + var rs = new RiText("The dog was white"); + var result = rs.removeChar(0); + equal(rs.text(), "he dog was white"); - var rs = new RiText("Who are you?"); - equal(rs.replaceAll("notExist", "Exist").text(), "Who are you?"); + var rs = new RiText("The dog was white"); + var result = rs.removeChar(-1); + equal(rs.text(), "The dog was whit"); - var rs = new RiText("Who are you?"); - equal(rs.replaceAll("", "").text(), "Who are you?"); + var rs = new RiText("The dog was white"); + var result = rs.removeChar(1000); + equal(rs.text(), "The dog was white"); - var rs = new RiText(""); - equal(rs.replaceAll("", "").text(), ""); + var rs = new RiText("The dog was white."); + var result = rs.removeChar(rs.length() - 1); + equal(rs.text(), "The dog was white"); + }); - var rs = new RiText("Who wuz you?"); - rs.replaceAll("u?", "?!"); - equal(rs.text(), "Who wuz yo?!"); + test("testReplaceChar()", function() { - var rs = new RiText("Who are you{1,}"); - rs.replaceAll("{1,}", "!"); - equal(rs.text(), "Who are you!"); + var rs = new RiText("Who are you?"); + rs.replaceChar(2, ""); + equal(rs.text(), "Wh are you?"); - var rs = new RiText("Who are you*"); - rs.replaceAll("*", "!"); - equal(rs.text(), "Who are you!"); + var rs = new RiText("Who are you?"); + rs.replaceChar(2, "e"); + equal(rs.text(), "Whe are you?"); - var rs = new RiText("Who are you+"); - rs.replaceAll("+", "!"); - equal(rs.text(), "Who are you!"); + var rs = new RiText("Who are you?"); + rs.replaceChar(2, "ere"); + equal(rs.text(), "Where are you?"); - var rs = new RiText("Who are you?"); - rs.replaceAll("?", "?!"); - equal(rs.text(), "Who are you?!"); - - // regex + var rs = new RiText("Who are you?"); + rs.replaceChar(11, "!!"); + equal(rs.text(), "Who are you!!"); - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/ain/, "ane"); - equal(rs.text(), "The rane in SPAIN stays manely in the plane"); + var rs = new RiText("Who are you?"); + rs.replaceChar(0, "me"); + equal(rs.text(), "meho are you?"); - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/ain/i, "ane"); - equal(rs.text(), "The rane in SPane stays manely in the plane"); + var rs = new RiText("Who are you?"); + rs.replaceChar(-1, "me"); + equal(rs.text(), "Who are youme"); + var rs = new RiText("Who are you?"); + rs.replaceChar(10000, "me"); + equal(rs.text(), "Who are you?"); - var rs = new RiText("Watch out for the rock!"); - rs.replaceAll(/ ?r/, "wood"); - equal(rs.text(), "Watch out fowood thewoodock!"); + }); - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/in/, ""); - equal(rs.text(), "The ra SPAIN stays maly the pla"); - - // global should have not affect + test("testReplaceFirst()", function() { - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/ain/g, "ane"); - equal(rs.text(), "The rane in SPAIN stays manely in the plane"); + var rs = new RiText("Who are you?"); + rs.replaceFirst("e", "E"); + equal(rs.text(), "Who arE you?"); - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/ain/ig, "ane"); - equal(rs.text(), "The rane in SPane stays manely in the plane"); + var rs = new RiText("Who are you?"); + rs.replaceFirst("o", "O"); + equal(rs.text(), "WhO are you?"); - var rs = new RiText("Watch out for the rock!"); - rs.replaceAll(/ ?r/g, "wood"); - equal(rs.text(), "Watch out fowood thewoodock!"); + var rs = new RiText("Who are you?"); + rs.replaceFirst("Who", "Where"); + equal(rs.text(), "Where are you?"); - var rs = new RiText("The rain in SPAIN stays mainly in the plain"); - rs.replaceAll(/in/g, ""); - equal(rs.text(), "The ra SPAIN stays maly the pla"); - - }); + var rs = new RiText("Who are you?"); + rs.replaceFirst("notExist", "Exist"); + equal(rs.text(), "Who are you?"); - test("testReplaceWord()", function() { + var rs = new RiText("Who are you?"); + rs.replaceFirst("Who are", "Dare"); + equal(rs.text(), "Dare you?"); - var rs = new RiText("Who are you?"); - equal("Who are What?", rs.replaceWord(2, "What").text()); + var rs = new RiText("Who are you?"); + rs.replaceFirst("Who aRe", "Dare"); + equal(rs.text(), "Who are you?"); - var rs = new RiText("Who are you?"); - equal(rs.replaceWord(0, "What").text(), "What are you?"); + var rs = new RiText("Who are you? Who are you?"); + rs.replaceFirst("Who are", "Dare"); + equal(rs.text(), "Dare you? Who are you?"); - var rs = new RiText("Who are you?"); - rs.replaceWord(3, "!!"); // - equal(rs.text(), "Who are you!!"); // nice! this is a strange one... - - var rs = new RiText("Who are you?"); - rs.replaceWord(-1, "asfasf"); - equal("Who are you asfasf", rs.text()); + var rs = new RiText("Who are you?"); + rs.replaceFirst("?", "?!"); + equal(rs.text(), "Who are you?!"); - var rs = new RiText("Who are you?"); - rs.replaceWord(20, "asfasf"); - equal(rs.text(), "Who are you?"); + var rs = new RiText("Who are you?"); + rs.replaceFirst("", ""); + equal(rs.text(), "Who are you?"); - }); + var rs = new RiText("Who are you?"); + rs.replaceFirst("?", "?!"); + equal(rs.text(), "Who are you?!"); - test("testSlice()", function() { //very similar to substring + //regex - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(1, 3).text(), "he"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/ain/, "ane"); + equal(rs.text(), "The rane in SPAIN stays mainly in the plain"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(-3, -2).text(), "f"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/ain/i, "oll"); + equal(rs.text(), "The roll in SPAIN stays mainly in the plain"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(15, 500).text(), - "Pavilion at the Venice Biennale is getting a much-needed facelift."); + var rs = new RiText("Watch out for the rock!"); + rs.replaceFirst(/r?or?/, "a"); + equal(rs.text(), "Watch aut for the rock!"); - var rs = new RiText("!@#$%^&**()"); - equal(rs.slice(2, 5).text(), "#$%"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/in/, "d"); + equal(rs.text(), "The rad in SPAIN stays mainly in the plain"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(15, 500).text(), - "Pavilion at the Venice Biennale is getting a much-needed facelift."); + // global should have not affect - var rs = new RiText("The Australian"); - equal(rs.slice(-5, -3).text(), "al"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/ain/g, "ane"); + equal(rs.text(), "The rane in SPAIN stays mainly in the plain"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(500, 501).text(), ""); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/ain/gi, "oll"); + equal(rs.text(), "The roll in SPAIN stays mainly in the plain"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(10, 10).text(), ""); + var rs = new RiText("Watch out for the rock!"); + rs.replaceFirst(/r?or?/g, "a"); + equal(rs.text(), "Watch aut for the rock!"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(3, 1).text(), ""); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceFirst(/in/g, "d"); + equal(rs.text(), "The rad in SPAIN stays mainly in the plain"); + }); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(-2, 3).text(), ""); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.slice(-2, -3).text(), ""); + test("testReplaceAll()", function() { + //replaceAll(regex, replacement); + var rs = new RiText("Who are you? Who is he? Who is it?"); + equal(rs.replaceAll("e", "E").text(), "Who arE you? Who is hE? Who is it?"); - }); -/* - test("testSplit()", function() { - - var rs = new RiText("Who are you?"); - var result = rs.split(); - var answer = [ RiText("Who are you?") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split(" "); - var answer = [ RiText("Who"), RiText("are"), RiText("you?") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("are"); - var answer = [ RiText("Who "), RiText(" you?") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("?"); - var answer = [ RiText("Who are you"), RiText("") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("W"); - var answer = [ RiText(""), RiText("ho are you?") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("abc"); - var answer = [ RiText("Who are you?") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split(""); - var answer = []; - var chars = [ "W", "h", "o", " ", "a", "r", "e", " ", "y", "o", "u", "?" ]; - for ( var i = 0; i < chars.length; i++) { - answer[i] = RiText(chars[i]); - } - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("", 3); - var answer = [ RiText("W"), RiText("h"), RiText("o") ]; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("", 0); - var answer = []; - deepEqual(result, answer); - - var rs = new RiText("Who are you?"); - var result = rs.split("", 100); - var answer = []; - var chars = [ "W", "h", "o", " ", "a", "r", "e", " ", "y", "o", "u", "?" ]; - for ( var i = 0; i < chars.length; i++) { - answer[i] = RiText(chars[i]); - } - deepEqual(result, answer); - - });*/ - - test( - "testStartsWith()", - function() { - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith("T")); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith("The")); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(!rs.startsWith("Aus")); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(!rs.startsWith("*")); - - var rs = new RiText( - "*The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith("*")); - - var rs = new RiText( - " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith(" ")); //single space - var rs = new RiText( - " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith(" ")); //double space - var rs = new RiText( - " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith(" ")); // tab space - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - ok(rs.startsWith("")); // fail here should not be true -- DCH: this is ok -- everything matches "" - }); - - test("testSubstring()", function() { - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(1, 3).text(), "he"); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(3, 1).text(), "he"); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(-2, 3).text(), "The"); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(15, 500).text(), - "Pavilion at the Venice Biennale is getting a much-needed facelift."); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(500, 501).text(), ""); - - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substring(10, 10).text(), ""); - - var rs = new RiText("!@#$%^&**()"); - equal(rs.substring(2, 5).text(), "#$%"); - - var rs = new RiText("Start at first character."); - equal(rs.substring(1, 5).text(), "tart"); - - var rs = new RiText("Start at first character."); - equal(rs.substring(0, 1).text(), "S"); - - var rs = new RiText("Start at first character."); - equal(rs.substring(0, 1).text(), "S"); - - var rs = new RiText("Start at first character."); - equal(rs.substring(3).text(), "rt at first character."); + var rs = new RiText("Who are you? Who is he? Who is it?"); + equal(rs.replaceAll("Who", "O").text(), "O are you? O is he? O is it?"); - }); + var rs = new RiText("Whom is he? Where is he? What is it?"); + equal(rs.replaceAll("Wh*", "O").text(), "Whom is he? Where is he? What is it?"); - test("testSubstr()", function() { // Duplicated with substring() and slice()? + var rs = new RiText("Whom is he? Where is he? What is it?"); + equal(rs.replaceAll(/Wh*/, "O").text(), "Oom is he? Oere is he? Oat is it?"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substr(1, 3).text(), "he "); + var rs = new RiText("%^&%&?"); + equal(rs.replaceAll("%^&%&?", "!!!").text(), "!!!"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substr(-2, 3).text(), "t."); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substr(15, 500).text(), - "Pavilion at the Venice Biennale is getting a much-needed facelift."); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substr(500, 501).text(), ""); + var rs = new RiText("Who are you?"); + equal(rs.replaceAll("notExist", "Exist").text(), "Who are you?"); - var rs = new RiText( - "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); - equal(rs.substr(10, 10).text(), "lian Pavil"); + var rs = new RiText("Who are you?"); + equal(rs.replaceAll("", "").text(), "Who are you?"); - var rs = new RiText("!@#$%^&**()"); - equal(rs.substr(2, 5).text(), "#$%^&"); + var rs = new RiText(""); + equal(rs.replaceAll("", "").text(), ""); - }); + var rs = new RiText("Who wuz you?"); + rs.replaceAll("u?", "?!"); + equal(rs.text(), "Who wuz yo?!"); + var rs = new RiText("Who are you{1,}"); + rs.replaceAll("{1,}", "!"); + equal(rs.text(), "Who are you!"); - test("testText()", function() { + var rs = new RiText("Who are you*"); + rs.replaceAll("*", "!"); + equal(rs.text(), "Who are you!"); - // check that these are ok --------------- - var rs = new RiText("this door is closed"); - var result = rs.text(); - equal(result, "this door is closed"); + var rs = new RiText("Who are you+"); + rs.replaceAll("+", "!"); + equal(rs.text(), "Who are you!"); - var rs = new RiText("this door, is closed.*&)*^"); - var result = rs.text(); - equal(result, "this door, is closed.*&)*^"); + var rs = new RiText("Who are you?"); + rs.replaceAll("?", "?!"); + equal(rs.text(), "Who are you?!"); - var rs = new RiText(" this door , is closed."); - var result = rs.text(); - equal(result, " this door , is closed."); + // regex - var rs = new RiText("this Door is closed"); - var result = rs.text(); - notEqual(result, "this door is closed"); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/ain/, "ane"); + equal(rs.text(), "The rane in SPAIN stays manely in the plane"); - var rs = new RiText(""); - var result = rs.text(); - equal(result, ""); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/ain/i, "ane"); + equal(rs.text(), "The rane in SPane stays manely in the plane"); - // no error checks needed ------------ - }); - test("testToLowerCase()", function() { + var rs = new RiText("Watch out for the rock!"); + rs.replaceAll(/ ?r/, "wood"); + equal(rs.text(), "Watch out fowood thewoodock!"); - var rs = new RiText("The Australian Pavilion."); - rs.toLowerCase(); - equal("the australian pavilion.", rs.text()); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/in/, ""); + equal(rs.text(), "The ra SPAIN stays maly the pla"); - var rs = new RiText("the Australian pavilion."); - rs.toLowerCase(); - equal("the australian pavilion.", rs.text()); + // global should have not affect - var rs = new RiText(")(*(&^%%$!#$$%%^))"); - rs.toLowerCase(); - equal(")(*(&^%%$!#$$%%^))", rs.text()); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/ain/g, "ane"); + equal(rs.text(), "The rane in SPAIN stays manely in the plane"); - // no error checks needed - }); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/ain/ig, "ane"); + equal(rs.text(), "The rane in SPane stays manely in the plane"); - test("testToUpperCase()", function() { + var rs = new RiText("Watch out for the rock!"); + rs.replaceAll(/ ?r/g, "wood"); + equal(rs.text(), "Watch out fowood thewoodock!"); - var rs = new RiText("The Australian Pavilion."); - equal("THE AUSTRALIAN PAVILION.", rs.toUpperCase().text()); + var rs = new RiText("The rain in SPAIN stays mainly in the plain"); + rs.replaceAll(/in/g, ""); + equal(rs.text(), "The ra SPAIN stays maly the pla"); - var rs = new RiText(")(*(&^%%$!#$$%%^))"); - rs.toUpperCase(); - equal(")(*(&^%%$!#$$%%^))", rs.text()); + }); - // no error checks needed - }); + test("testReplaceWord()", function() { - test("testTrim()", function() { + var rs = new RiText("Who are you?"); + equal("Who are What?", rs.replaceWord(2, "What").text()); - // check that these are ok --------------- - var rs = new RiText("Start at first character. "); - equal(rs.trim().text(), "Start at first character."); + var rs = new RiText("Who are you?"); + equal(rs.replaceWord(0, "What").text(), "What are you?"); - var rs = new RiText(" Start at first character."); - equal(rs.trim().text(), "Start at first character."); + var rs = new RiText("Who are you?"); + rs.replaceWord(3, "!!"); // + equal(rs.text(), "Who are you!!"); // nice! this is a strange one... - var rs = new RiText(" Start at first character. "); // tabs - equal(rs.trim().text(), "Start at first character."); + var rs = new RiText("Who are you?"); + rs.replaceWord(-1, "asfasf"); + equal("Who are you asfasf", rs.text()); - var rs = new RiText(" Start at first character. "); // spaces/tabs - equal(rs.trim().text(), "Start at first character."); + var rs = new RiText("Who are you?"); + rs.replaceWord(20, "asfasf"); + equal(rs.text(), "Who are you?"); - var rs = new RiText("Start at first character.\t"); //\t - equal(rs.trim().text(), "Start at first character."); - - var rs = new RiText("\t\t\tStart at first character.\t"); //\t - equal(rs.trim().text(), "Start at first character."); - // no error checks needed - }); + }); + + test("testSlice()", function() { //very similar to substring + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(1, 3).text(), "he"); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(-3, -2).text(), "f"); - test("testWordAt()", function() { + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(15, 500).text(), + "Pavilion at the Venice Biennale is getting a much-needed facelift."); - // check that these are ok --------------- - var rs = new RiText("Returns the word at wordIdx using the default WordTokenizer."); - var result = rs.wordAt(0); - equal(result, "Returns"); + var rs = new RiText("!@#$%^&**()"); + equal(rs.slice(2, 5).text(), "#$%"); - var result = rs.wordAt(1); - equal(result, "the"); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(15, 500).text(), + "Pavilion at the Venice Biennale is getting a much-needed facelift."); - var result = rs.wordAt(9); - equal(result, "."); + var rs = new RiText("The Australian"); + equal(rs.slice(-5, -3).text(), "al"); - var result = rs.wordAt(500); - equal(result, ""); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(500, 501).text(), ""); - var result = rs.wordAt(-5); - equal(result, ""); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(10, 10).text(), ""); - var rs = new RiText(""); - var result = rs.wordAt(0); - equal(result, ""); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(3, 1).text(), ""); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(-2, 3).text(), ""); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.slice(-2, -3).text(), ""); + + + }); + /* + test("testSplit()", function() { + + var rs = new RiText("Who are you?"); + var result = rs.split(); + var answer = [ RiText("Who are you?") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split(" "); + var answer = [ RiText("Who"), RiText("are"), RiText("you?") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("are"); + var answer = [ RiText("Who "), RiText(" you?") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("?"); + var answer = [ RiText("Who are you"), RiText("") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("W"); + var answer = [ RiText(""), RiText("ho are you?") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("abc"); + var answer = [ RiText("Who are you?") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split(""); + var answer = []; + var chars = [ "W", "h", "o", " ", "a", "r", "e", " ", "y", "o", "u", "?" ]; + for ( var i = 0; i < chars.length; i++) { + answer[i] = RiText(chars[i]); + } + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("", 3); + var answer = [ RiText("W"), RiText("h"), RiText("o") ]; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("", 0); + var answer = []; + deepEqual(result, answer); + + var rs = new RiText("Who are you?"); + var result = rs.split("", 100); + var answer = []; + var chars = [ "W", "h", "o", " ", "a", "r", "e", " ", "y", "o", "u", "?" ]; + for ( var i = 0; i < chars.length; i++) { + answer[i] = RiText(chars[i]); + } + deepEqual(result, answer); + + });*/ + + test( + "testStartsWith()", + function() { + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith("T")); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith("The")); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(!rs.startsWith("Aus")); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(!rs.startsWith("*")); + + var rs = new RiText( + "*The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith("*")); + + var rs = new RiText( + " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith(" ")); //single space + var rs = new RiText( + " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith(" ")); //double space + var rs = new RiText( + " The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith(" ")); // tab space + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + ok(rs.startsWith("")); // fail here should not be true -- DCH: this is ok -- everything matches "" }); - test("testWordCount()", function() { + test("testSubstring()", function() { - // check that these are ok --- ------------ - var rs = new RiText("Returns the word at wordIdx using the default WordTokenizer."); - var result = rs.wordCount(); - equal(result, 10); // correct, according to WordTokenizer, need to try with RegexTokenizer - var rs = new RiText("Returns the word.Returns the word. Returns the word ."); - var result = rs.wordCount(); - equal(result, 12); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(1, 3).text(), "he"); - var rs = new RiText(" Returns the word at wordIdx , using the default WordTokenizer."); //space - var result = rs.wordCount(); - equal(result, 11); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(3, 1).text(), "he"); - var rs = new RiText(" Returns the word at wordIdx , using the default WordTokenizer. "); //tab space - var result = rs.wordCount(); - equal(result, 11); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(-2, 3).text(), "The"); - var rs = new RiText(""); - var result = rs.wordCount(); - equal(result, 0); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(15, 500).text(), + "Pavilion at the Venice Biennale is getting a much-needed facelift."); - }); + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(500, 501).text(), ""); - test("testWords()", function() { + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substring(10, 10).text(), ""); - // check that these are ok --------------- - var rs = new RiText("Returns the array of words."); - var result = rs.words(); - var answer = [ "Returns", "the", "array", "of", "words", "." ]; - deepEqual(result, answer); + var rs = new RiText("!@#$%^&**()"); + equal(rs.substring(2, 5).text(), "#$%"); - var rs = new RiText("The boy, dressed in red, ate an array."); - var result = rs.words(); - var answer = [ "The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "array", "." ]; - deepEqual(result, answer); + var rs = new RiText("Start at first character."); + equal(rs.substring(1, 5).text(), "tart"); - var rs = new RiText("Returns the array of words ."); - var result = rs.words(); - var answer = [ "Returns", "the", "array", "of", "words", "." ]; - deepEqual(result, answer); + var rs = new RiText("Start at first character."); + equal(rs.substring(0, 1).text(), "S"); - var rs = new RiText("The boy, dressed in red , ate an array?"); - var result = rs.words(); - var answer = [ "The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "array", "?" ]; - deepEqual(result, answer); + var rs = new RiText("Start at first character."); + equal(rs.substring(0, 1).text(), "S"); - var rs = new RiText(""); - var result = rs.words(); - var answer = [ "" ]; - deepEqual(result, answer); + var rs = new RiText("Start at first character."); + equal(rs.substring(3).text(), "rt at first character."); - // no error checks needed - }); + }); + + test("testSubstr()", function() { // Duplicated with substring() and slice()? + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substr(1, 3).text(), "he "); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substr(-2, 3).text(), "t."); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substr(15, 500).text(), + "Pavilion at the Venice Biennale is getting a much-needed facelift."); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substr(500, 501).text(), ""); + + var rs = new RiText( + "The Australian Pavilion at the Venice Biennale is getting a much-needed facelift."); + equal(rs.substr(10, 10).text(), "lian Pavil"); + + var rs = new RiText("!@#$%^&**()"); + equal(rs.substr(2, 5).text(), "#$%^&"); + + }); + + + test("testText()", function() { + + // check that these are ok --------------- + var rs = new RiText("this door is closed"); + var result = rs.text(); + equal(result, "this door is closed"); + + var rs = new RiText("this door, is closed.*&)*^"); + var result = rs.text(); + equal(result, "this door, is closed.*&)*^"); + + var rs = new RiText(" this door , is closed."); + var result = rs.text(); + equal(result, " this door , is closed."); + + var rs = new RiText("this Door is closed"); + var result = rs.text(); + notEqual(result, "this door is closed"); + + var rs = new RiText(""); + var result = rs.text(); + equal(result, ""); + + // no error checks needed ------------ + }); + + test("testToLowerCase()", function() { + + var rs = new RiText("The Australian Pavilion."); + rs.toLowerCase(); + equal("the australian pavilion.", rs.text()); + + var rs = new RiText("the Australian pavilion."); + rs.toLowerCase(); + equal("the australian pavilion.", rs.text()); + + var rs = new RiText(")(*(&^%%$!#$$%%^))"); + rs.toLowerCase(); + equal(")(*(&^%%$!#$$%%^))", rs.text()); + + // no error checks needed + }); + + test("testToUpperCase()", function() { + + var rs = new RiText("The Australian Pavilion."); + equal("THE AUSTRALIAN PAVILION.", rs.toUpperCase().text()); + + var rs = new RiText(")(*(&^%%$!#$$%%^))"); + rs.toUpperCase(); + equal(")(*(&^%%$!#$$%%^))", rs.text()); + + // no error checks needed + }); + + test("testTrim()", function() { + // check that these are ok --------------- + var rs = new RiText("Start at first character. "); + equal(rs.trim().text(), "Start at first character."); - test("testCopy()", function() { - var rt = new RiText("hello", 100, 270); + var rs = new RiText(" Start at first character."); + equal(rs.trim().text(), "Start at first character."); + + var rs = new RiText(" Start at first character. "); // tabs + equal(rs.trim().text(), "Start at first character."); + + var rs = new RiText(" Start at first character. "); // spaces/tabs + equal(rs.trim().text(), "Start at first character."); + + var rs = new RiText("Start at first character.\t"); //\t + equal(rs.trim().text(), "Start at first character."); + + var rs = new RiText("\t\t\tStart at first character.\t"); //\t + equal(rs.trim().text(), "Start at first character."); + // no error checks needed + }); + + test("testWordAt()", function() { + + // check that these are ok --------------- + var rs = new RiText("Returns the word at wordIdx using the default WordTokenizer."); + var result = rs.wordAt(0); + equal(result, "Returns"); + + var result = rs.wordAt(1); + equal(result, "the"); + + var result = rs.wordAt(9); + equal(result, "."); + + var result = rs.wordAt(500); + equal(result, ""); + + var result = rs.wordAt(-5); + equal(result, ""); + + var rs = new RiText(""); + var result = rs.wordAt(0); + equal(result, ""); + + }); + + test("testWordCount()", function() { + + // check that these are ok --- ------------ + var rs = new RiText("Returns the word at wordIdx using the default WordTokenizer."); + var result = rs.wordCount(); + equal(result, 10); // correct, according to WordTokenizer, need to try with RegexTokenizer + var rs = new RiText("Returns the word.Returns the word. Returns the word ."); + var result = rs.wordCount(); + equal(result, 12); + + var rs = new RiText(" Returns the word at wordIdx , using the default WordTokenizer."); //space + var result = rs.wordCount(); + equal(result, 11); + + var rs = new RiText(" Returns the word at wordIdx , using the default WordTokenizer. "); //tab space + var result = rs.wordCount(); + equal(result, 11); + + var rs = new RiText(""); + var result = rs.wordCount(); + equal(result, 0); + + }); + + test("testWords()", function() { + + // check that these are ok --------------- + var rs = new RiText("Returns the array of words."); + var result = rs.words(); + var answer = ["Returns", "the", "array", "of", "words", "."]; + deepEqual(result, answer); + + var rs = new RiText("The boy, dressed in red, ate an array."); + var result = rs.words(); + var answer = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "array", "."]; + deepEqual(result, answer); + + var rs = new RiText("Returns the array of words ."); + var result = rs.words(); + var answer = ["Returns", "the", "array", "of", "words", "."]; + deepEqual(result, answer); + + var rs = new RiText("The boy, dressed in red , ate an array?"); + var result = rs.words(); + var answer = ["The", "boy", ",", "dressed", "in", "red", ",", "ate", "an", "array", "?"]; + deepEqual(result, answer); + + var rs = new RiText(""); + var result = rs.words(); + var answer = [""]; + deepEqual(result, answer); + + // no error checks needed + }); + + + test("testCopy()", function() { + var rt = new RiText("hello", 100, 270); rt.fill(101, 102, 103, 104); rt.showBounds(true); @@ -1292,16 +1284,16 @@ var runtests = function() { equal(rt.alpha(), rt2.alpha()); equal(rt.text(), rt2.text()); equal(rt.align(), rt2.align()); - + // equal(rt.autodraw(), rt2.autodraw()); // not in API equal(rt.behaviors, rt2.behaviors); equal(rt.charAt(3), rt2.charAt(3)); - deepEqual(rt.boundingBox(),rt2.boundingBox()); + deepEqual(rt.boundingBox(), rt2.boundingBox()); deepEqual(rt.fill(), rt2.fill()); - - + + rt = new RiText(" space tabSpace AbCd 1234 ", 5, 10); rt.fill(101, 102, 103, 104); @@ -1314,20 +1306,20 @@ var runtests = function() { equal(rt.alpha(), rt2.alpha()); equal(rt.text(), rt2.text()); equal(rt.align(), rt2.align()); - + // equal(rt.autodraw(), rt2.autodraw()); // not in API equal(rt.behaviors, rt2.behaviors); equal(rt.charAt(3), rt2.charAt(3)); - deepEqual(rt.boundingBox(),rt2.boundingBox()); + deepEqual(rt.boundingBox(), rt2.boundingBox()); deepEqual(rt.fill(), rt2.fill()); - - - - + + + + var rt3 = new RiText("!@#$%^&*()_ GHFHJJJ hjhjjh", 15, 20); - + rt3.fill(1, 100, 23); rt3.showBounds(false); @@ -1343,14 +1335,14 @@ var runtests = function() { equal(rt4.behaviors, rt3.behaviors); // not in API ?? equal(rt4.charAt(3), rt3.charAt(3)); - deepEqual(rt4.boundingBox(),rt3.boundingBox()); + deepEqual(rt4.boundingBox(), rt3.boundingBox()); deepEqual(rt4.fill(), rt3.fill()); - }); + }); - RiTa.SILENT = tmp; + RiTa.SILENT = tmp; } if (typeof exports != 'undefined') runtests();