Example #1
0
    set : function(attrs, options) {

      // Extract attributes and options.
      options || (options = {});
      if (!attrs) return this;
      if (attrs.attributes) attrs = attrs.attributes;
      var now = this.attributes, escaped = this._escapedAttributes;

      // Run validation.
      if (!options.silent && this.validate && !this._performValidation(attrs, options)) return false;

      // Check for changes of `id`.
      if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];

      // Update attributes.
      for (var attr in attrs) {
        var val = attrs[attr];
        if (!_.isEqual(now[attr], val)) {
          now[attr] = val;
          delete escaped[attr];
          this._changed = true;
          if (!options.silent) this.trigger('change:' + attr, this, val, options);
        }
      }

      // Fire the `"change"` event, if the model has been changed.
      if (!options.silent && this._changed) this.change(options);
      return this;
    },
Example #2
0
 function(err, myModel){
   myModel.subcollection.add([savedModel]);
   // TODO: write w/ asyncblock to ensure that callbacks are called
   console.log(myModel.get('subcollection'), [savedModel.id]);
   assert(_.isEqual(myModel.get('subcollection'), [savedModel.id]));
   done();
 }
Example #3
0
    _(expectedClasses.length).times(function(n){
      if (currentStats.length<n+1) 
        { 
        currentStats.push(new PrecisionRecall())
        data_stats.push([])
        }

      var sentence_hash = {}
      data_stats[n].push(sentence_hash);
      expl1 = currentStats[n].addCasesHash(expectedClasses[n], actualClasses1[n], (verbosity>2));
      expl2 = currentStats[n].addCasesHash(expectedClasses[n], actualClasses2[n], (verbosity>2));
      // console.log(expl1)
      // console.log(expl2)

      if (!(_.isEqual(expl1,expl2)))
        {
          console.log(testSetOriginal[i].input)
          console.log(expl1)
          console.log(expl2)
        }
      // currentStats[n].addCasesLabels(expectedClasses[n], actualClasses[n]);
      // sentence_hash['input'] = testSet[i].input;
      // sentence_hash['expected'] = expectedClasses[n];
      // sentence_hash['classified'] = actualClasses[n];
      // sentence_hash['explanation'] = expl;
      // sentence_hash['expected original'] = testSetOriginal[i]['output']
      // sentence_hash['classified original'] = classified
      })  
Example #4
0
 var wasToldToListenOnce = function() {
   for (var i = 0, l = obj.once.callCount; i < l; i ++) {
     var test = obj.once.getCall(i).args[0];
     if (_.isEqual(test, args[0])) {
       return true;
     } 
   }
   return false;
 };
Example #5
0
 setTimeout(function() {
     if (_.isEqual(this.get("hangout-pending"), obj)) {
         this.logAnalytics({action: "unfarmed start timeout"});
         this.onHangoutStopped();
         if (!this.isDeleted()) {
             this.save();
         }
     }
 }.bind(this), this.HANGOUT_CREATION_TIMEOUT - interval);
Example #6
0
        function(err, pkg_, headers, readme) {
            if (err) throw err;
            pkg = pkg_;

            if (!_.isEqual(pkg.name, name)) {
                throw new SyntaxError("Package name \"" + pkg.name + "\" in " +
                                      name + "-pkg.el" + " doesn't match " +
                                      "archive name \"" + name + "\"!");
            } else if (!_.isEqual(pkg.version, version)) {
                throw new SyntaxError("Package version \"" +
                                      pkg.version.join(".") + "\" in " + name +
                                      "-pkg.el doesn't match archive version " +
                                      '"' + version.join(".") + '"!');
            }

            pkg.headers = headers;
            pkg.commentary = readme;
            return pkg;
        },
Example #7
0
 var everWrote = function() {
   for (var i = 0, l = obj.write.callCount; i < l; i ++) {
     var test = obj.write.getCall(i).args[0].args;
     if (_.isEqual(test, args)) {
       return true;
     } 
   }
   return false;
   //_.isEqual(obj.write.getCall(obj.write.callCount-1).args[0].args, args)
 };
			return function(doc) {
				if (doCheckWithHC) {
					// let hcDoc = HierarchicalUserProperties._HierarchyCollection.findOne({_id: doc.nodeId});
					let hcDoc = WBSCollection.findOne({ _id: doc.nodeId });
					const hcUsnList = hcDoc.upstreamNodeIdList.sort();
					const ownUsnList = (doc.upstreamNodeIdList || ['!!!!!!']).sort();
					console.log('-----\n', msg, arguments, _.isEqual(hcUsnList, ownUsnList) ? ['Ok.'] : ['****** NOT OK! ******', doc, hcDoc], '\n-----');
				} else {
					console.log('-----\n', msg, arguments, '\n-----');
				}
			};
Example #9
0
chai.Assertion.addMethod('write', function(){
  var obj = this._obj;
  var args = Array.prototype.slice.call(arguments, 0);
  this.assert(
    _.isEqual(obj.write.getCall(obj.write.callCount-1).args[0].args, args),
    "expected to write #{exp}, but wrote #{act}",
    "expected not to write #{act}",
    args,
    obj.write.getCall(0).args[0].args,
    true
  );
});
Example #10
0
 changedAttributes : function(now) {
   now || (now = this.attributes);
   var old = this._previousAttributes;
   var changed = false;
   for (var attr in now) {
     if (!_.isEqual(old[attr], now[attr])) {
       changed = changed || {};
       changed[attr] = now[attr];
     }
   }
   return changed;
 },
Example #11
0
	      		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()
    			})
Example #12
0
	        _.each(item['labels'], function(values, label, list){
	                if (!(label in stats))
	                                stats[label] = {}
	                // _.each(values, function(value, key, list){
	                        if (!(_.isEqual(values,[''])))
	                        // if (values.length > 0)
	                                {
	                                        _.each(values, function(value, key1, list){
	                                                value = value.toLowerCase();
	                                                if (!(value in stats[label]))
	                                                         stats[label][value] = []
	                                                stats[label][value].push(item['sentence'])

	                                        }, this)
	                                }
	                                        // stats[label] = stats[label].concat(values)

	                 // }, this) 
	        }, this)
Example #13
0
 var atLeastEqual = function(act, exp) {
   for (var i = 0, l = act.length; i < l; i ++) {
     var act_v = act[i];
     var exp_v = exp[i];
     if (_.isObject(exp_v)) {
       if (_.isArray(exp_v)) {
         /* the meat of this function is operating on objects
          * it is designed to operate on an array already, so recurse */
         if ( ! atLeastEqual(act_v, exp_v)) { return false; }
       } else {
         // check each property has at least what i am asserting about
         for (var key in exp_v) {
           if ( ! _.isEqual(act_v[key], exp_v[key])) { return false; }
         }
         _.matches(act_v, exp_v);
       }
     } else if (act_v !== exp_v) {
       return false;
     }
   }
   return true;
 };
Example #14
0
/**
 * Compare two langNodes to see if they are at the same state of the same production rule.
 **/
//TODO: Unit test this.
//TODO: Inline categories are not handled.
function compareLangNodes(langNodeA, langNodeB) {
    if(langNodeA.category === langNodeB.category){
        if(langNodeA.parseData.origin === langNodeB.parseData.origin){
            if(langNodeA.parseData.atComponent === langNodeB.parseData.atComponent){
                if(langNodeA.parseData.stringIdx === langNodeB.parseData.stringIdx){
                    //State is the same, now check that the components are the same:
                    //TODO: Not sure if this works with regexs properly.
                    //console.log(langNodeA.components);
                    //console.log(langNodeB.components);
                    return _.isEqual(langNodeA.components, langNodeB.components);
                    //Problem comparing compiled regex?
                    if(langNodeA.components.length === langNodeB.components.length) {
                        return _.all(_.zip(langNodeA.components, langNodeB.components), function(componentPair) {
                            return componentPair[0].category === componentPair[1].category &&
                                componentPair[0].match === componentPair[1].match &&
                                componentPair[0].terminal === componentPair[1].terminal;
                        });
                    }
                }
            }
        }
    }
    return false;
}
Example #15
0
	it('should separate labels correctly', function() {
		_.isEqual(Hierarchy.splitPartEqually([{Offer: {Salary: "20000"}}]), [["Offer"], ["Salary"], ["20000"]]).should.equal(true);
		_.isEqual(Hierarchy.splitPartEqually([{Accept: "previous"}]), [["Accept"], [], ["previous"]]).should.equal(true)
		_.isEqual(Hierarchy.splitPartEqually([{Insist: "Salary"}]), [["Insist"], ["Salary"], []]).should.equal(true)	
		_.isEqual(Hierarchy.splitPartEqually([{Insist: "Salary"}, {Accept: "previous"}]), [["Insist", "Accept"], ["Salary"], ["previous"]]);	
	});
Example #16
0
// extend 复制对象的所有属性到目标对象上,覆盖已有属性
console.log(_.extend({name:'moe'}, {age:8})); //{ name: 'moe', age: 8 }

// default: 复制对象的所有属性到目标对象上,跳过已有属性
console.log(_.defaults({a:'a', b:'b'}, {a:'aa', c:'c'}));//{ a: 'a', b: 'b', c: 'c' }

// pick, omit返回一个对象的副本, 保留指定的属性或去掉指定的属性
console.log(_.pick({name:'tom', age:4}, 'name'));//{ name: 'tom' }
console.log(_.omit({name:'tom', age:4}, 'name'));//{ age: 4 }
// has 判断对象是否包含指定的属性名
console.log(_.has({a:1, b:2, c:3}, 'b')); //true
// isEqual: 判断两个对象是值相等
var moe = {name:'moe', b:[1,2,3]};
var clone = {name:'moe', b:[1,2,3]};
console.log(moe==clone);//false
console.log(_.isEqual(moe, clone));//true
//判断对象类型以下都为空
console.log(_.isEmpty({})); //如果object里没包含任何东西,将返回true
console.log(_.isArray([1,2,3]));
console.log(_.isObject({}));
console.log((function(){ return _.isArguments(arguments); })(1, 2, 3));
console.log(_.isFunction(console.log));
console.log(_.isString("moe"));
console.log(_.isNumber(8.4 * 5));
console.log(_.isFinite(-101));
console.log(_.isBoolean(true));
console.log(_.isDate(new Date()));
console.log(_.isNaN(NaN));
console.log(_.isNull(null));
console.log(_.isUndefined(undefined));
Example #17
0
File: game.js Project: hmac/whist
 _.each(this, function(o) {
   if (_.isEqual(o, obj)) {
     _this.splice(_this.indexOf(o), 1);
     return removed_obj = o;
   }
 });
Example #18
0
   function(err, myModel, model2) {
     myModel.set({subcollection: model2.id});
     // TODO: async-kal ezt is tesztelni
     assert(_.isEqual(myModel.get('subcollection'), myModel.subcollection.toJSON()));
     done();
 });
Example #19
0
 return _.find(this.scents, function (scent) {
     return _.isEqual(scent, input);
 })