From 505925ee110ab8e83a875597466567eb55dac051 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 17 Dec 2013 15:16:13 +0000 Subject: [PATCH] Forgot to commit this file --- lib/summary.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/summary.js b/lib/summary.js index c75ae12..11aa6ed 100644 --- a/lib/summary.js +++ b/lib/summary.js @@ -1,11 +1,11 @@ -var _ = require('underscore'); +var _ = require('lodash-node/underscore'); function splitContentToSentences(content, callback) { if(content.indexOf('.') === -1) { return callback(false); } - content = content.replace("\n", ". "); + content = content.replace("\n", '. '); callback(content.match(/(.+?\.(?:\s|$))/g)); } @@ -14,14 +14,14 @@ function splitContentToParagraphs(content, callback) { } function sentencesIntersection(sent1, sent2, callback) { - var s1 = sent1.split(" "); - var s2 = sent2.split(" "); + var s1 = sent1.split(' '); + var s2 = sent2.split(' '); if((s1.length + s2.length) === 0) { callback(true); } - var intersect = _.intersection(s1, s2); + var intersect = _.intersection(s1, s2); var spliceHere = ((s1.length + s2.length) / 2); callback(false, intersect.splice(0, spliceHere).length); @@ -36,10 +36,10 @@ function formatSentence(sentence, callback) { function getBestSentence(paragraph, sentences_dict, callback) { splitContentToSentences(paragraph, function(sentences) { - if (!sentences) return ""; - if (sentences.length < 2) return ""; + if (!sentences) return ''; + if (sentences.length < 2) return ''; - var best_sentence = "", max_value = 0, strip_s; + var best_sentence = '', max_value = 0, strip_s; _.each(sentences, function(s) { formatSentence(s, function(strip_s) { if(strip_s && sentences_dict[strip_s] > max_value) { @@ -55,8 +55,8 @@ function getBestSentence(paragraph, sentences_dict, callback) { function getSortedSentences(paragraph, sentences_dict, n, callback) { splitContentToSentences(paragraph, function(sentences) { - if (!sentences) return callback(""); - if (sentences.length < 2) return callback(""); + if (!sentences) return callback(''); + if (sentences.length < 2) return callback(''); var sentence_scores = [], strip_s; _.each(sentences, function(s, i) { @@ -130,7 +130,7 @@ function getSentencesRanks(content, callback) { } exports.summarize = function(title, content, callback) { - var summary = [], paragraphs = [], sentence = "", err = false; + var summary = [], paragraphs = [], sentence = '', err = false; getSentencesRanks(content, function(dict) { splitContentToParagraphs(content, function(paragraphs) { summary.push(title); // Store the title. @@ -156,7 +156,7 @@ exports.getSortedSentences = function(content, n, callback) { getSentencesRanks(content, function(dict) { getSortedSentences(content, dict, n, function(sorted_sentences) { - if(sorted_sentences === "") { + if(sorted_sentences === '') { callback(new Error('Too short to summarize.')); } else { callback(null, sorted_sentences);