describePost : function ( user, method, path ) { var params = {}, pathComponents = path.split('/'); if ( __.isEmpty( __.intersection( pathComponents, ['data'] ) ) ) { if ( __.isEmpty( __.intersection( pathComponents, ['complaint','nonConformity','task'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'creó un ' + translate( pathComponents[1] ), 'when' : getOperationDate() } }; foward( params ); } else { params = { 'reference' : { 'who' : user.username, 'what' : 'creó una ' + translate( pathComponents[1] ), 'when' : getOperationDate() } }; foward( params ); } } },
createGame(u1, u2, u3, u4, function (game) { var cards = game.round.cards; test.equals(_.intersection(cards.player1, cids1).length, 8); test.equals(_.intersection(cards.player2, cids2).length, 8); test.equals(_.intersection(cards.player3, cids3).length, 8); test.equals(_.intersection(cards.player4, cids4).length, 8); assertTurn1(game, function (game) { assertTurn2(game, function (game) { // assertTurn3(game, function (game) { deck.shuffle = oldShuffle; test.done(); // }) }) }); });
onlycontent(phrase, function(err, response) { // response - content of the seed var content_phrase = (response.length != 0 ? response : phrase.split(" ")); if (_.isEqual(content_phrase, _.intersection(input_list, content_phrase)) == true) { var elem = {} elem[intent] = {} elem[intent]['original seed'] = keyphrases elem[intent]['ppdb phrase'] = phrase elem[intent]['content of ppdb phrase'] = content_phrase output.push(elem) } callback3() })
lists.intersection = function (head, req) { var extraKeys = []; if (req.query.key) { extraKeys.push(req.query.key); } if (req.query.extra_keys) { var split = req.query.extra_keys.split(' '); extraKeys = extraKeys.concat(split); } extraKeys = _.uniq(_.map(extraKeys, function(key) {return key.toLowerCase()})); var realJson = true; if (req.query.streamJson) { realJson = false; } start({'headers' : {'Content-Type' : 'application/json'}}); if (realJson) send('[\n'); var count = 0; var row; while ((row = getRow())) { var doc_intersection = _.intersection(row.doc.tag, extraKeys); if (doc_intersection.length == extraKeys.length) { var res = { id : row.id, name : row.doc.name, size : row.doc.size, s : row.doc.s, l : row.doc.l, m : row.doc.m } var pre = ''; if (count++ > 0 && realJson) pre = ','; send(pre + JSON.stringify(res) + '\n'); } } if (realJson) send(']'); }
describeDelete : function ( user, method, path ) { if ( __.isEmpty( __.intersection( pathComponents, ['complaint','nonConformity','task'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'eliminó un ' + translate( pathComponents[1] ), 'when' : getOperationDate() } }; foward( params ); } else { params = { 'reference' : { 'who' : user.username, 'what' : 'eliminó una ' + translate( pathComponents[1] ), 'when' : getOperationDate() } }; foward( params ); } }
function assertTurn2(game, callback) { test.equals(game.round.turn.firstPid, "player1", "first player in 3rd turn should be correct"); test.equals(game.round.turn.currentPid, "player1", "first player in 3rd turn should be correct"); test.equals(game.round.score.team1, 25, "turn should calculate correct score"); test.equals(game.round.score.team2, 0, "turn should calculate correct score"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(_.intersection(game._getCardsAllowed("player1"), ["s-A", "s-K", "s-8", "h-K", "d-9"]).length, 5, "only non trumps should be available for turn"); // callback(game); // return; //TODO: complete challenge doTurn(game, u1, "h-K", u2, "h-A", u3, "h-10", u4, "h-9", function (error, game, state, step) { if (state === "newTurn") { callback(game); } }); }
setConnectedParticipants: function(users) { if (users.length > 10) { return false; } // Clean incoming users.. users = _.map(users, function(u) { u = (u.toJSON ? u.toJSON() : u); return { id: u.id, displayName: u.displayName, picture: u.picture || (u.image && u.image.url ? u.image.url : "") } }); // Has anything changed? var current = this.get("connectedParticipants"); var intersection = _.intersection(_.pluck(users, "id"), _.pluck(current, "id")); if (users.length != current.length || intersection.length != current.length) { // We've changed. this.set("connectedParticipants", users); return true; } else { // No change. return false; } },
LibSynphony.prototype.checkStory = function( aFocusWordList, aWordCumulativeList, aGPCsKnown, storyHTML, sightWords ) { var letters; var story_vocab; if (aGPCsKnown.length > 0) { letters = this.fullGPC2Regular(aGPCsKnown).join("|"); // break the text into words story_vocab = this.getWordsFromHtmlString(storyHTML, letters); } else { letters = ""; // break the text into words story_vocab = this.getWordsFromHtmlString(storyHTML); } // Just in case users want ? for glottal or similar nonsense with other special // RE characters. See https://issues.bloomlibrary.org/youtrack/issue/BL-7075. if (letters.includes("\\")) letters = letters.replace("\\", "\\\\"); if (letters.includes("?")) letters = letters.replace("?", "\\?"); if (letters.includes("+")) letters = letters.replace("+", "\\+"); if (letters.includes("*")) letters = letters.replace("*", "\\*"); // get unique word list var story_vocab_compacted = _.uniq(story_vocab); // count total words in the story var total_words = _.filter(story_vocab, function(word) { return isNaN(word) === true; }).length; // if aGPCsKnown is empty, return now // BL-2359: Need to allow stages based on word lists rather than known graphemes //if (aGPCsKnown.length === 0) // return new StoryCheckResults([], [], [], [], [], 0, total_words); // first we do diffs on aFocusWordList and aWordCumulativeList with story_vocab words var story_focus_words = _.intersection( aFocusWordList, story_vocab_compacted ); var story_cumulative_words = _.intersection( _.pluck(aWordCumulativeList, "Name"), story_vocab ); this.array_sort_length(story_focus_words); /* TODO: has to handle utf8 */ // FIRST PASS: we handle words which are currently in focus var focus_words = _.intersection(story_focus_words, story_vocab_compacted); var remaining_words = _.difference(story_vocab_compacted, focus_words); this.array_sort_length(focus_words); // SECOND PASS: we handle words which are part of the cumulative word bank // aWordCumulativeList is an object that contains the following fields: // GPCForm,GPCS,GPCcount,Name,Reverse,SyllShape,Syllables var cumulative_words = _.intersection( story_cumulative_words, remaining_words ); remaining_words = _.difference(remaining_words, cumulative_words); this.array_sort_length(cumulative_words); // THIRD PASS: we handle words which have not been matched yet to check if they are // decodable at this point. This can match words which are longer than the syllable // selectors specify but contain all the gpcs. We do this using a regular expression // with the array of knownGPCs. This is not the most accurate method; we should // first segment the word with all gpcs, then test with known gpcs. This also checks // for the possibility that the word is not yet in our database. // This only works for simple gpc notation, not complex. // Why not for full gpc? Once you have covered the regular spelling patterns (in English) // you will match all the other words, so everything gets tagged as 'possible'. Not useful!! var possible_words = []; if ( typeof theOneLanguageDataInstance === "undefined" || theOneLanguageDataInstance["UseFullGPCNotation"] === false ) { // allow punctuation characters in the words // BL-1216 Use negative look-ahead to keep letters from being counted as punctuation // even if Unicode says something is a punctuation character when the user // has specified it as a letter (like single quote). var re = new XRegExp( "^((" + letters + ")+((?![" + letters + "])[\\p{P}]*(" + letters + ")*)*)$", "gi" ); possible_words = _.filter(remaining_words, function(word) { return word.match(re); }); // BL-1217: exclude words with unknown graphemes, specifically 'aa' when only 'a' is known if (typeof theOneLanguageDataInstance !== "undefined") { // get the unknown letters var unknownGPCs = _.difference( _.pluck(theOneLanguageDataInstance["GPCS"], "GPC"), letters.split("|") ); // .join('|'); if (Array.isArray(unknownGPCs) && unknownGPCs.length > 0) { // remove from the list of unknownGPCs characters used to build multi-graphs in the list aGPCsKnown unknownGPCs = _.filter(unknownGPCs, function(gpc) { return letters.indexOf(gpc) === -1; }); if (unknownGPCs.length > 0) { re = new XRegExp("(" + unknownGPCs.join("|") + ")+", "gi"); possible_words = _.filter(possible_words, function(word) { return !word.match(re); }); } } } remaining_words = _.difference(remaining_words, possible_words); this.array_sort_length(possible_words); } // FOURTH PASS: we handle sight words // NOTE: Handle sight words after checking for decodability, because a sight word may become decodable. var sight_words = []; if (sightWords.length > 0) { sight_words = _.intersection(sightWords.split(" "), remaining_words); remaining_words = _.difference(remaining_words, sight_words); this.array_sort_length(sight_words); } // FIFTH PASS: we handle everything else that's left over var readable = focus_words.length + cumulative_words.length + possible_words.length; return new StoryCheckResults( focus_words, cumulative_words, possible_words, sight_words, remaining_words, readable, total_words ); };
bot.addListener("message",function(nick,channel,message){ // Check for swear words var words=S(message).trim().s.toLowerCase().split(/[\'\"\?\><\(\)\|\-\;\.\!\\\,\:\s]/); if(_.intersection(swearWords,words).length !== 0){ bot.say(channel,nick+", please refrain from being profane in the channel."); } });
var found = function(target, source) { if (!_.isArray(source)) { source = _.toArray(arguments).slice(1); } return _.intersection(target, source).length > 0; };
describeGet : function ( user, method, path ) { var params = {}, pathComponents = path.split('/'); if( typeof user !== 'undefined' ) { if ( __.isEmpty( __.intersection( pathComponents, ['menus','404', '_common', '_templates'] ) ) ) { if ( !__.isEmpty( __.intersection( pathComponents, ['html'] ) ) ) { //[0] = '', [1] = 'html' lastItem = pathComponents[ pathComponents.length - 1 ]; lastItem = lastItem.substring( 0, lastItem.length - 5 ); pathComponents.pop(); pathComponents.push( lastItem ); if ( __.isEmpty( __.intersection( pathComponents, ['control_panel','formation','permissions','processes','welcome'] ) ) ) { if ( !__.isEmpty( __.intersection( pathComponents, ['all','assignment','new','own','revision'] ) ) ) { action = pathComponents[ pathComponents.length - 1 ]; if ( !__.isEmpty( __.intersection( pathComponents, ['all','own'] ) ) ) { if ( !__.isEmpty( __.intersection( pathComponents, ['own'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Consultó la lista de ' .concat( translate( pathComponents[2] ), ' propias en la sección: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Consultó la lista general de ' .concat( translate( pathComponents[2] ), ' en la sección: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' de ', translate( pathComponents[2] ), ' en la sección de: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else if ( !__.isEmpty( __.intersection( pathComponents, ['departments','employees','employments'] ) ) ) { if ( !__.isEmpty( __.intersection( pathComponents, ['profile'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la información específica de un talento humano' .concat( ' en la sección de: ', translate( 'organizational_structure' ) ), 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' de ', translate( pathComponents[2] ), ' en la sección de: ', translate( 'organizational_structure' ) ), 'when' : getOperationDate() } }; } } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' de ', translate( pathComponents[2] ), ' en la sección de: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else if ( !__.isEmpty(__.intersection( pathComponents, ['formation'] ) ) ) { if ( !__.isEmpty(__.intersection( pathComponents, ['all','assignment','new'] ) ) ) { if ( !__.isEmpty( __.intersection( pathComponents, ['all'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Consultó la lista general' .concat( ' de ', translate( 'courses' ), ' en la sección de: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' de ', translate( 'courses' ), ' en la sección de: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la información específica de un curso' .concat(' en la sección: ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else if ( !__.isEmpty(__.intersection( pathComponents, ['control_panel', 'permissions'] ) ) ) { if ( !__.isEmpty(__.intersection( pathComponents, ['permissions'] ) ) ) { pathComponents.pop(); pathComponents.pop(); pathComponents.push('control_panel'); pathComponents.push('permissions'); } if ( !__.isEmpty(__.intersection( pathComponents, ['documents'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió al ciclo de aprobación de ' .concat( translate( pathComponents[3] ), ' en el ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' en el ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } } else if ( !__.isEmpty(__.intersection( pathComponents, ['processes'] ) ) ) { if ( !__.isEmpty(__.intersection( pathComponents, ['process_map'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió al ' .concat( translate( pathComponents[3] ), ' en la sección de ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' en la sección de ', translate( pathComponents[2] ) ), 'when' : getOperationDate() } } } } else if ( !__.isEmpty(__.intersection( pathComponents, ['welcome'] ) ) ) { params = { 'reference' : { 'who' : user.username, 'what' : 'Inició sesión', 'when' : getOperationDate() } }; } else { params = { 'reference' : { 'who' : user.username, 'what' : 'Accedió a la ' .concat( translate( pathComponents[3] ), ' de ', translate( pathComponents[2] ), ' en la sección de: ', translate( pathComponents[2] ), '...' ), 'when' : getOperationDate() } }; } foward( params ); } else { //console.log('Es una ruta que no se quiere loggear'); //console.log(pathComponents); } } } else { //console.log('Usuario sin sesión'); } },
function assertCards(cids, firstCid, isShuffled, turn, round, expected, message) { var allowed = getCardsAllowed(cids, firstCid, isShuffled, turn, round); test.equals(_.intersection(allowed, expected).length, expected.length, message); }
_turn : function (test) { var u1 = createUser() , u2 = createUser() , u3 = createUser() , u4 = createUser() , cids1 = ["d-Q", "c-8", "s-A", "s-K", "s-8", "h-K", "d-A", "d-9"] , cids2 = ["d-J", "c-10", "s-10", "h-A", "h-8", "h-7", "d-10", "d-7"] , cids3 = ["c-7", "h-J", "c-9", "s-9", "s-7", "h-10", "c-K", "d-K"] , cids4 = ["c-Q", "s-Q", "h-Q", "c-J", "s-J", "c-A", "h-9", "d-8"]; test.ok(!_.intersection(cids1, cids2, cids3, cids4).length); var oldShuffle = deck.shuffle; deck.shuffle = function () { return [cids1, cids2, cids3, cids4]; }; function allowedCard(game, user) { return game._getCardsAllowed(game._getPidForUser(user))[0]; } // TODO: fix that crap function doTurn(game, u1, cid1, u2, cid2, u3, cid3, u4, cid4, callback4, callback3, callback2, callback1) { game._turn(u1, cid1, function (error, game, state) { callback1 && callback1(error, game, state, 1); game._turn(u2, cid2 || allowedCard(game, u2), function (error, game, state) { callback2 && callback2(error, game, state, 2); game._turn(u3, cid3 || allowedCard(game, u3), function (error, game, state) { callback3 && callback3(error, game, state, 3); game._turn(u4, cid4 || allowedCard(game, u4), function (error, game, state) { test.ok(!error); callback4 && callback4(error, game, state, 4); }); }); }); }) } function assertTurn1(game, callback) { test.equals(game.round.shuffledPlayer, "player4", "shuffled player should be correct"); test.equals(game.round.turn.firstPid, "player1", "first player in game should be correct"); test.equals(game.round.turn.currentPid, "player1", "first turn player in game should be correct"); test.equals(game.round.number, 1, "it should be first round"); test.equals(game.round.turn.number, 1, "it should be first turn"); test.ok(game._getCardsAllowed("player1").length === 1); test.ok(game._getCardsAllowed("player1").indexOf("d-A") >= 0); test.ok(!game._getCardsAllowed("player2").length); test.ok(!game._getCardsAllowed("player3").length); test.ok(!game._getCardsAllowed("player4").length); game._turn(u1, "d-9", function (error) { test.ok(error, "incorrect card turn should raise error"); game._turn(u2, "d-A", function (error) { test.ok(error, "incorrect player turn should raise error"); game._turn(u2, "d-10", function (error) { test.ok(error, "turn with card from other player should raise error"); game._turn(createUser(), "d-A", function (error) { test.ok(error, "turn by not in user game should raise error"); game._turn(u1, "d-A", function (error, game, state) { test.ok(!error, "correct turn should not raise errors"); test.equals(state, "turned", "state should be correct after the turn"); game._turn(u2, game._getCardsAllowed("player2")[0], function (error, game, state) { test.ok(!error, "correct turn should not raise errors"); test.equals(state, "turned", "state should be correct after the turn"); game._turn(u3, game._getCardsAllowed("player3")[0], function (error, game, state) { test.ok(!error, "correct turn should not raise errors"); test.equals(state, "turned", "state should be correct after the turn"); var count = 0; game._turn(u4, game._getCardsAllowed("player4")[0], function (error, game, state) { test.ok(!error, "correct turn should not raise errors"); if (!count) { test.equals(state, "turned", "state should be correct after the turn end"); count++; } else if (count === 1) { test.equals(state, "newTurn", "state should be correct after the turn end"); count++; callback(game); } else { test.ok(false, "forth player turn should not produce extra callbacks"); } }); }); }); }); }); }); }); }); } function assertTurn2(game, callback) { test.equals(game.round.turn.firstPid, "player1", "first player in 3rd turn should be correct"); test.equals(game.round.turn.currentPid, "player1", "first player in 3rd turn should be correct"); test.equals(game.round.score.team1, 25, "turn should calculate correct score"); test.equals(game.round.score.team2, 0, "turn should calculate correct score"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(game.round.cards.player1.length, 7, "cards should be less in new turn"); test.equals(_.intersection(game._getCardsAllowed("player1"), ["s-A", "s-K", "s-8", "h-K", "d-9"]).length, 5, "only non trumps should be available for turn"); // callback(game); // return; //TODO: complete challenge doTurn(game, u1, "h-K", u2, "h-A", u3, "h-10", u4, "h-9", function (error, game, state, step) { if (state === "newTurn") { callback(game); } }); } function assertTurn3(game, callback) { test.equals(game.round.turn.firstPid, "player2", "first player in second turn should be correct"); test.equals(game.round.turn.currentPid, "player2", "first player in second turn should be correct"); test.equals(game.round.score.team1, 0, "turn should calculate correct score"); test.equals(game.round.score.team2, 25, "turn should calculate correct score"); callback(game); return; //TODO: can't finish turn3 var count = 0; doTurn(game, u2, "d-7", u3, null, u4, null, u1, null, function (error, game, state, step) { count++; console.warn(state); if (count == 2) { test.equals(state, "gameEnd"); callback(game); } }); } createGame(u1, u2, u3, u4, function (game) { var cards = game.round.cards; test.equals(_.intersection(cards.player1, cids1).length, 8); test.equals(_.intersection(cards.player2, cids2).length, 8); test.equals(_.intersection(cards.player3, cids3).length, 8); test.equals(_.intersection(cards.player4, cids4).length, 8); assertTurn1(game, function (game) { assertTurn2(game, function (game) { // assertTurn3(game, function (game) { deck.shuffle = oldShuffle; test.done(); // }) }) }); }); },