Example #1
0
var createStory = function (cluster, cb) {
  var content = [], titles = [],
      story = new self.models.story;

  // iterate through each article to acquire references, titles and content.
  cluster.articles.forEach(function (article) {
    story.refs.push(article.url);
    titles.push(article.title);
    if (content.indexOf(article.story) === -1)
      content.push(article.story);
  });

  // concatenate content
  content = content.join(' ');

  // title generation
  titlegen.feed(titles);
  if (titles.length > 1) story.title = titlegen();
  if (story.title === '' || story.title === undefined) story.title = titles[0];

  // content summarization
  story.content = summaryTool({ corpus: content, nSentences: 5 }).sentences;

  // category acquired via an api then finally save story
  request('http://uclassify.com/browse/mvazquez/News Classifier/ClassifyText?readkey=' + api_keys.classifier.read + '&text=' + encodeURI(story.content.join('  ')) + '&output=json&version=1.01', function (err, res, body) {
    var response, category;
    try {
      response = JSON.parse(body);
      var categories = [];
    
      for (var c in response.cls1)
        categories.push([c, response.cls1[c]]);
      categories.sort(function(a, b) {return b[1] - a[1]});

      story.category = ((categories[0][0] === 'US') ? 'UK & Others' : categories[0][0]);

    } catch (e) {
      console.log(new Error('Could not set category.'));
      story.category = 'Miscellaneous';
    } finally {
      story.save(function (err, story) {
        console.log('new story:\n>>>>', story._id);
        cb(err);
      });
    }
  });
};
Example #2
0
 expect(function () {
     sum(1, '');
 }).to.throw(TypeError, /a and b should be numbers/);
Example #3
0
 it('sums only first two arguments', function () {
     expect(sum(1, 1, 1)).to.eql(2);
 });
Example #4
0
 it('calculates sum of two numbers', function () {
     expect(sum(1, 1)).to.eql(2);
 });
Example #5
0



var Sum = require('sum');
var Write = require('write');

var writer = Write('hello');

console.log(Sum(1)(2));

writer('world 2');
writer('gatto');
Example #6
0
function setHeight(store, el) {
  var height = sum(store, function (o) {
    return o.height;
  })
  el.style.height = height + 'px';
}